From dbbe581276a866491f2cb52078b2161ed669701b Mon Sep 17 00:00:00 2001 From: Philip Reames Date: Sat, 13 Apr 2019 03:55:13 +0000 Subject: [PATCH] [StackMaps] Update llvm-readobj to parse V3 Stackmaps This updates the StackMap parser in the llvm-readobj tool to parse version 3 StackMaps, which were bumped in https://reviews.llvm.org/D32629. Version 3 StackMaps differ in that they have a uint16 sized "location size" field which was added to the Location block in a StackMap record. The record has additional padding for alignment. This was a backwards incompatible change resulting in a StackMap version bump. Patch By: jacob.hughes@kcl.ac.uk (with a rewrite of tests by me) Differential Revision: https://reviews.llvm.org/D59020 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358325 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Object/StackMapParser.h | 25 +++---- test/Object/Inputs/stackmap-test.macho-x86-64 | Bin 3956 -> 4116 bytes test/Object/stackmap-dump.test | 61 +++++++++--------- 3 files changed, 43 insertions(+), 43 deletions(-) diff --git a/include/llvm/Object/StackMapParser.h b/include/llvm/Object/StackMapParser.h index 0aad9148c29..ed44efbf80b 100644 --- a/include/llvm/Object/StackMapParser.h +++ b/include/llvm/Object/StackMapParser.h @@ -117,7 +117,7 @@ public: /// Get the Size for this location. unsigned getSizeInBytes() const { - return read(P + SizeOffset); + return read(P + SizeOffset); } @@ -155,10 +155,10 @@ public: } static const int KindOffset = 0; - static const int SizeOffset = KindOffset + sizeof(uint8_t); - static const int DwarfRegNumOffset = SizeOffset + sizeof(uint8_t); - static const int SmallConstantOffset = DwarfRegNumOffset + sizeof(uint16_t); - static const int LocationAccessorSize = sizeof(uint64_t); + static const int SizeOffset = KindOffset + sizeof(uint16_t); + static const int DwarfRegNumOffset = SizeOffset + sizeof(uint16_t); + static const int SmallConstantOffset = DwarfRegNumOffset + sizeof(uint32_t); + static const int LocationAccessorSize = sizeof(uint64_t) + sizeof(uint32_t); const uint8_t *P; }; @@ -271,8 +271,9 @@ public: RecordAccessor(const uint8_t *P) : P(P) {} unsigned getNumLiveOutsOffset() const { - return LocationListOffset + LocationSize * getNumLocations() + - sizeof(uint16_t); + unsigned LocOffset = + ((LocationListOffset + LocationSize * getNumLocations()) + 7) & ~0x7; + return LocOffset + sizeof(uint16_t); } unsigned getSizeInBytes() const { @@ -292,7 +293,7 @@ public: InstructionOffsetOffset + sizeof(uint32_t) + sizeof(uint16_t); static const unsigned LocationListOffset = NumLocationsOffset + sizeof(uint16_t); - static const unsigned LocationSize = sizeof(uint64_t); + static const unsigned LocationSize = sizeof(uint64_t) + sizeof(uint32_t); static const unsigned LiveOutSize = sizeof(uint32_t); const uint8_t *P; @@ -304,8 +305,8 @@ public: : StackMapSection(StackMapSection) { ConstantsListOffset = FunctionListOffset + getNumFunctions() * FunctionSize; - assert(StackMapSection[0] == 2 && - "StackMapParser can only parse version 2 stackmaps"); + assert(StackMapSection[0] == 3 && + "StackMapParser can only parse version 3 stackmaps"); unsigned CurrentRecordOffset = ConstantsListOffset + getNumConstants() * ConstantSize; @@ -321,8 +322,8 @@ public: using constant_iterator = AccessorIterator; using record_iterator = AccessorIterator; - /// Get the version number of this stackmap. (Always returns 2). - unsigned getVersion() const { return 2; } + /// Get the version number of this stackmap. (Always returns 3). + unsigned getVersion() const { return 3; } /// Get the number of functions in the stack map. uint32_t getNumFunctions() const { diff --git a/test/Object/Inputs/stackmap-test.macho-x86-64 b/test/Object/Inputs/stackmap-test.macho-x86-64 index 438f5e77a4401b5f13739c6c9568a33a99352091..c3fcb0301d3e925ccbfb1250b6f1f80d8589b9a2 100644 GIT binary patch literal 4116 zcmdT{U2IfE6rPp>E0o*fUoaXAMk0wyia`T!+!XXyAvWDoNT6Jn-P?Bcc6YP8U^OAs zlo&Pw?gKBr^~vyJ!h;V@Fu0~95MOK}G5BJLsgXp8O^iS^v3}pooZY+2uHu`X?97}q z=bLlRoI7*w-mibZ{pU)h+LkGFXdGwAtVaVqfwqlu3p&5rC@K~sGHfa~+9UaXF_OmW68l@x0$NzeLooYNArn^z)bsoeSG&~X8wY;JG-j3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DKhW#&U#MC16g zQWApkC^H!8IvV9ZE%P3tT-5RvEsubczCokCn*!)pG|E{i3Gum>D_VZn$iR?3K$G#b z%(F-NCmKOdpiy4c_BdqSr5PV?iB!&y7oOp#)=*+Wcp2YMu^u*`1h6B~(A2o;z~H&qd?8SRp=x5ZP2Z9hGsk;3s5S2r)rdHLaGixw)*LE4+Fj gmny(Gm(Qg#=~PB_<8$c*ikQnxr@##q6()rE8wy3Ji2wiq diff --git a/test/Object/stackmap-dump.test b/test/Object/stackmap-dump.test index 3c632b83678..a121bc3ce22 100644 --- a/test/Object/stackmap-dump.test +++ b/test/Object/stackmap-dump.test @@ -1,10 +1,9 @@ RUN: llvm-readobj -stackmap %p/Inputs/stackmap-test.macho-x86-64 | FileCheck %s ; Note: the macho object file in this test was generated in the following way: -; llc -mtriple=x86_64-apple-darwin %p/test/CodeGen/X86/stackmap.ll -o stackmap.s -; clang -c stackmap.s -o %p/test/Object/Inputs/stackmap-test.macho-x86-64 +; llc -mtriple=x86_64-apple-darwin test/CodeGen/X86/stackmap.ll -o test/Object/Inputs/stackmap-test.macho-x86-64 -filetype=obj -CHECK: LLVM StackMap Version: 2 +CHECK: LLVM StackMap Version: 3 CHECK-NEXT: Num Functions: 16 CHECK-NEXT: Function address: 0, stack size: 8, callsite record count: 1 CHECK-NEXT: Function address: 0, stack size: 24, callsite record count: 1 @@ -13,8 +12,8 @@ CHECK-NEXT: Function address: 0, stack size: 8, callsite record count: 1 CHECK-NEXT: Function address: 0, stack size: 8, callsite record count: 1 CHECK-NEXT: Function address: 0, stack size: 8, callsite record count: 1 CHECK-NEXT: Function address: 0, stack size: 8, callsite record count: 1 -CHECK-NEXT: Function address: 0, stack size: 56, callsite record count: 1 -CHECK-NEXT: Function address: 0, stack size: 56, callsite record count: 1 +CHECK-NEXT: Function address: 0, stack size: 8, callsite record count: 1 +CHECK-NEXT: Function address: 0, stack size: 8, callsite record count: 1 CHECK-NEXT: Function address: 0, stack size: 56, callsite record count: 1 CHECK-NEXT: Function address: 0, stack size: 56, callsite record count: 1 CHECK-NEXT: Function address: 0, stack size: 8, callsite record count: 1 @@ -79,16 +78,16 @@ CHECK-NEXT: #1: Register R#2, size: 8 CHECK-NEXT: #2: Register R#8, size: 8 CHECK-NEXT: 2 live-outs: [ R#0 (8-bytes) R#7 (8-bytes) ] -CHECK: Record ID: 11, instruction offset: 42 +CHECK: Record ID: 11, instruction offset: 4 CHECK-NEXT: 17 locations: CHECK-NEXT: #1: Register R#9, size: 8 -CHECK-NEXT: #2: Register R#14, size: 8 -CHECK-NEXT: #3: Register R#10, size: 8 -CHECK-NEXT: #4: Register R#3, size: 8 -CHECK-NEXT: #5: Register R#0, size: 8 -CHECK-NEXT: #6: Register R#13, size: 8 -CHECK-NEXT: #7: Register R#12, size: 8 -CHECK-NEXT: #8: Register R#15, size: 8 +CHECK-NEXT: #2: Indirect [R#6 + 16], size: 8 +CHECK-NEXT: #3: Indirect [R#6 + 24], size: 8 +CHECK-NEXT: #4: Indirect [R#6 + 32], size: 8 +CHECK-NEXT: #5: Indirect [R#6 + 40], size: 8 +CHECK-NEXT: #6: Indirect [R#6 + 48], size: 8 +CHECK-NEXT: #7: Indirect [R#6 + 56], size: 8 +CHECK-NEXT: #8: Indirect [R#6 + 64], size: 8 CHECK-NEXT: #9: Indirect [R#6 + 72], size: 8 CHECK-NEXT: #10: Indirect [R#6 + 80], size: 8 CHECK-NEXT: #11: Indirect [R#6 + 88], size: 8 @@ -100,21 +99,21 @@ CHECK-NEXT: #16: Indirect [R#6 + 128], size: 8 CHECK-NEXT: #17: Indirect [R#6 + 136], size: 8 CHECK-NEXT: 1 live-outs: [ R#7 (8-bytes) ] -CHECK: Record ID: 12, instruction offset: 62 +CHECK: Record ID: 12, instruction offset: 4 CHECK-NEXT: 17 locations: CHECK-NEXT: #1: Register R#0, size: 8 -CHECK-NEXT: #2: Register R#14, size: 8 -CHECK-NEXT: #3: Register R#10, size: 8 -CHECK-NEXT: #4: Register R#9, size: 8 -CHECK-NEXT: #5: Register R#8, size: 8 -CHECK-NEXT: #6: Register R#4, size: 8 -CHECK-NEXT: #7: Register R#1, size: 8 -CHECK-NEXT: #8: Register R#2, size: 8 -CHECK-NEXT: #9: Register R#5, size: 8 -CHECK-NEXT: #10: Register R#3, size: 8 -CHECK-NEXT: #11: Register R#13, size: 8 -CHECK-NEXT: #12: Register R#12, size: 8 -CHECK-NEXT: #13: Register R#15, size: 8 +CHECK-NEXT: #2: Indirect [R#6 + 16], size: 8 +CHECK-NEXT: #3: Indirect [R#6 + 24], size: 8 +CHECK-NEXT: #4: Indirect [R#6 + 32], size: 8 +CHECK-NEXT: #5: Indirect [R#6 + 40], size: 8 +CHECK-NEXT: #6: Indirect [R#6 + 48], size: 8 +CHECK-NEXT: #7: Indirect [R#6 + 56], size: 8 +CHECK-NEXT: #8: Indirect [R#6 + 64], size: 8 +CHECK-NEXT: #9: Indirect [R#6 + 72], size: 8 +CHECK-NEXT: #10: Indirect [R#6 + 80], size: 8 +CHECK-NEXT: #11: Indirect [R#6 + 88], size: 8 +CHECK-NEXT: #12: Indirect [R#6 + 96], size: 8 +CHECK-NEXT: #13: Indirect [R#6 + 104], size: 8 CHECK-NEXT: #14: Indirect [R#6 + 112], size: 8 CHECK-NEXT: #15: Indirect [R#6 + 120], size: 8 CHECK-NEXT: #16: Indirect [R#6 + 128], size: 8 @@ -137,15 +136,15 @@ CHECK-NEXT: 1 locations: CHECK-NEXT: #1: Constant 33, size: 8 CHECK-NEXT: 0 live-outs: [ ] -CHECK: Record ID: 16, instruction offset: 32 +CHECK: Record ID: 16, instruction offset: 16 CHECK-NEXT: 1 locations: -CHECK-NEXT: #1: Direct R#6 + -32, size: 8 +CHECK-NEXT: #1: Direct R#6 + -40, size: 8 CHECK-NEXT: 0 live-outs: [ ] -CHECK: Record ID: 17, instruction offset: 32 +CHECK: Record ID: 17, instruction offset: 16 CHECK-NEXT: 2 locations: CHECK-NEXT: #1: Direct R#6 + -8, size: 8 -CHECK-NEXT: #2: Direct R#6 + -40, size: 8 +CHECK-NEXT: #2: Direct R#6 + -16, size: 8 CHECK-NEXT: 1 live-outs: [ R#7 (8-bytes) ] CHECK: Record ID: 4294967295, instruction offset: 4 @@ -169,6 +168,6 @@ CHECK-NEXT: 1 locations: CHECK-NEXT: #1: Indirect [R#6 + -44], size: 4 CHECK-NEXT: 0 live-outs: [ ] -CHECK: Record ID: 0, instruction offset: 26 +CHECK: Record ID: 0, instruction offset: 25 CHECK-NEXT: 0 locations: CHECK-NEXT: 0 live-outs: [ ] -- 2.50.1