Skip to content

Commit e03301a

Browse files
committed
[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: [email protected] (with a rewrite of tests by me) Differential Revision: https://reviews.llvm.org/D59020 llvm-svn: 358325
1 parent eea989a commit e03301a

File tree

3 files changed

+43
-43
lines changed

3 files changed

+43
-43
lines changed

llvm/include/llvm/Object/StackMapParser.h

+13-12
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ class StackMapParser {
117117

118118
/// Get the Size for this location.
119119
unsigned getSizeInBytes() const {
120-
return read<uint8_t>(P + SizeOffset);
120+
return read<uint16_t>(P + SizeOffset);
121121

122122
}
123123

@@ -155,10 +155,10 @@ class StackMapParser {
155155
}
156156

157157
static const int KindOffset = 0;
158-
static const int SizeOffset = KindOffset + sizeof(uint8_t);
159-
static const int DwarfRegNumOffset = SizeOffset + sizeof(uint8_t);
160-
static const int SmallConstantOffset = DwarfRegNumOffset + sizeof(uint16_t);
161-
static const int LocationAccessorSize = sizeof(uint64_t);
158+
static const int SizeOffset = KindOffset + sizeof(uint16_t);
159+
static const int DwarfRegNumOffset = SizeOffset + sizeof(uint16_t);
160+
static const int SmallConstantOffset = DwarfRegNumOffset + sizeof(uint32_t);
161+
static const int LocationAccessorSize = sizeof(uint64_t) + sizeof(uint32_t);
162162

163163
const uint8_t *P;
164164
};
@@ -271,8 +271,9 @@ class StackMapParser {
271271
RecordAccessor(const uint8_t *P) : P(P) {}
272272

273273
unsigned getNumLiveOutsOffset() const {
274-
return LocationListOffset + LocationSize * getNumLocations() +
275-
sizeof(uint16_t);
274+
unsigned LocOffset =
275+
((LocationListOffset + LocationSize * getNumLocations()) + 7) & ~0x7;
276+
return LocOffset + sizeof(uint16_t);
276277
}
277278

278279
unsigned getSizeInBytes() const {
@@ -292,7 +293,7 @@ class StackMapParser {
292293
InstructionOffsetOffset + sizeof(uint32_t) + sizeof(uint16_t);
293294
static const unsigned LocationListOffset =
294295
NumLocationsOffset + sizeof(uint16_t);
295-
static const unsigned LocationSize = sizeof(uint64_t);
296+
static const unsigned LocationSize = sizeof(uint64_t) + sizeof(uint32_t);
296297
static const unsigned LiveOutSize = sizeof(uint32_t);
297298

298299
const uint8_t *P;
@@ -304,8 +305,8 @@ class StackMapParser {
304305
: StackMapSection(StackMapSection) {
305306
ConstantsListOffset = FunctionListOffset + getNumFunctions() * FunctionSize;
306307

307-
assert(StackMapSection[0] == 2 &&
308-
"StackMapParser can only parse version 2 stackmaps");
308+
assert(StackMapSection[0] == 3 &&
309+
"StackMapParser can only parse version 3 stackmaps");
309310

310311
unsigned CurrentRecordOffset =
311312
ConstantsListOffset + getNumConstants() * ConstantSize;
@@ -321,8 +322,8 @@ class StackMapParser {
321322
using constant_iterator = AccessorIterator<ConstantAccessor>;
322323
using record_iterator = AccessorIterator<RecordAccessor>;
323324

324-
/// Get the version number of this stackmap. (Always returns 2).
325-
unsigned getVersion() const { return 2; }
325+
/// Get the version number of this stackmap. (Always returns 3).
326+
unsigned getVersion() const { return 3; }
326327

327328
/// Get the number of functions in the stack map.
328329
uint32_t getNumFunctions() const {
160 Bytes
Binary file not shown.

llvm/test/Object/stackmap-dump.test

+30-31
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
RUN: llvm-readobj -stackmap %p/Inputs/stackmap-test.macho-x86-64 | FileCheck %s
22

33
; Note: the macho object file in this test was generated in the following way:
4-
; llc -mtriple=x86_64-apple-darwin %p/test/CodeGen/X86/stackmap.ll -o stackmap.s
5-
; clang -c stackmap.s -o %p/test/Object/Inputs/stackmap-test.macho-x86-64
4+
; llc -mtriple=x86_64-apple-darwin test/CodeGen/X86/stackmap.ll -o test/Object/Inputs/stackmap-test.macho-x86-64 -filetype=obj
65

7-
CHECK: LLVM StackMap Version: 2
6+
CHECK: LLVM StackMap Version: 3
87
CHECK-NEXT: Num Functions: 16
98
CHECK-NEXT: Function address: 0, stack size: 8, callsite record count: 1
109
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
1312
CHECK-NEXT: Function address: 0, stack size: 8, callsite record count: 1
1413
CHECK-NEXT: Function address: 0, stack size: 8, callsite record count: 1
1514
CHECK-NEXT: Function address: 0, stack size: 8, callsite record count: 1
16-
CHECK-NEXT: Function address: 0, stack size: 56, callsite record count: 1
17-
CHECK-NEXT: Function address: 0, stack size: 56, callsite record count: 1
15+
CHECK-NEXT: Function address: 0, stack size: 8, callsite record count: 1
16+
CHECK-NEXT: Function address: 0, stack size: 8, callsite record count: 1
1817
CHECK-NEXT: Function address: 0, stack size: 56, callsite record count: 1
1918
CHECK-NEXT: Function address: 0, stack size: 56, callsite record count: 1
2019
CHECK-NEXT: Function address: 0, stack size: 8, callsite record count: 1
@@ -79,16 +78,16 @@ CHECK-NEXT: #1: Register R#2, size: 8
7978
CHECK-NEXT: #2: Register R#8, size: 8
8079
CHECK-NEXT: 2 live-outs: [ R#0 (8-bytes) R#7 (8-bytes) ]
8180

82-
CHECK: Record ID: 11, instruction offset: 42
81+
CHECK: Record ID: 11, instruction offset: 4
8382
CHECK-NEXT: 17 locations:
8483
CHECK-NEXT: #1: Register R#9, size: 8
85-
CHECK-NEXT: #2: Register R#14, size: 8
86-
CHECK-NEXT: #3: Register R#10, size: 8
87-
CHECK-NEXT: #4: Register R#3, size: 8
88-
CHECK-NEXT: #5: Register R#0, size: 8
89-
CHECK-NEXT: #6: Register R#13, size: 8
90-
CHECK-NEXT: #7: Register R#12, size: 8
91-
CHECK-NEXT: #8: Register R#15, size: 8
84+
CHECK-NEXT: #2: Indirect [R#6 + 16], size: 8
85+
CHECK-NEXT: #3: Indirect [R#6 + 24], size: 8
86+
CHECK-NEXT: #4: Indirect [R#6 + 32], size: 8
87+
CHECK-NEXT: #5: Indirect [R#6 + 40], size: 8
88+
CHECK-NEXT: #6: Indirect [R#6 + 48], size: 8
89+
CHECK-NEXT: #7: Indirect [R#6 + 56], size: 8
90+
CHECK-NEXT: #8: Indirect [R#6 + 64], size: 8
9291
CHECK-NEXT: #9: Indirect [R#6 + 72], size: 8
9392
CHECK-NEXT: #10: Indirect [R#6 + 80], size: 8
9493
CHECK-NEXT: #11: Indirect [R#6 + 88], size: 8
@@ -100,21 +99,21 @@ CHECK-NEXT: #16: Indirect [R#6 + 128], size: 8
10099
CHECK-NEXT: #17: Indirect [R#6 + 136], size: 8
101100
CHECK-NEXT: 1 live-outs: [ R#7 (8-bytes) ]
102101

103-
CHECK: Record ID: 12, instruction offset: 62
102+
CHECK: Record ID: 12, instruction offset: 4
104103
CHECK-NEXT: 17 locations:
105104
CHECK-NEXT: #1: Register R#0, size: 8
106-
CHECK-NEXT: #2: Register R#14, size: 8
107-
CHECK-NEXT: #3: Register R#10, size: 8
108-
CHECK-NEXT: #4: Register R#9, size: 8
109-
CHECK-NEXT: #5: Register R#8, size: 8
110-
CHECK-NEXT: #6: Register R#4, size: 8
111-
CHECK-NEXT: #7: Register R#1, size: 8
112-
CHECK-NEXT: #8: Register R#2, size: 8
113-
CHECK-NEXT: #9: Register R#5, size: 8
114-
CHECK-NEXT: #10: Register R#3, size: 8
115-
CHECK-NEXT: #11: Register R#13, size: 8
116-
CHECK-NEXT: #12: Register R#12, size: 8
117-
CHECK-NEXT: #13: Register R#15, size: 8
105+
CHECK-NEXT: #2: Indirect [R#6 + 16], size: 8
106+
CHECK-NEXT: #3: Indirect [R#6 + 24], size: 8
107+
CHECK-NEXT: #4: Indirect [R#6 + 32], size: 8
108+
CHECK-NEXT: #5: Indirect [R#6 + 40], size: 8
109+
CHECK-NEXT: #6: Indirect [R#6 + 48], size: 8
110+
CHECK-NEXT: #7: Indirect [R#6 + 56], size: 8
111+
CHECK-NEXT: #8: Indirect [R#6 + 64], size: 8
112+
CHECK-NEXT: #9: Indirect [R#6 + 72], size: 8
113+
CHECK-NEXT: #10: Indirect [R#6 + 80], size: 8
114+
CHECK-NEXT: #11: Indirect [R#6 + 88], size: 8
115+
CHECK-NEXT: #12: Indirect [R#6 + 96], size: 8
116+
CHECK-NEXT: #13: Indirect [R#6 + 104], size: 8
118117
CHECK-NEXT: #14: Indirect [R#6 + 112], size: 8
119118
CHECK-NEXT: #15: Indirect [R#6 + 120], size: 8
120119
CHECK-NEXT: #16: Indirect [R#6 + 128], size: 8
@@ -137,15 +136,15 @@ CHECK-NEXT: 1 locations:
137136
CHECK-NEXT: #1: Constant 33, size: 8
138137
CHECK-NEXT: 0 live-outs: [ ]
139138

140-
CHECK: Record ID: 16, instruction offset: 32
139+
CHECK: Record ID: 16, instruction offset: 16
141140
CHECK-NEXT: 1 locations:
142-
CHECK-NEXT: #1: Direct R#6 + -32, size: 8
141+
CHECK-NEXT: #1: Direct R#6 + -40, size: 8
143142
CHECK-NEXT: 0 live-outs: [ ]
144143

145-
CHECK: Record ID: 17, instruction offset: 32
144+
CHECK: Record ID: 17, instruction offset: 16
146145
CHECK-NEXT: 2 locations:
147146
CHECK-NEXT: #1: Direct R#6 + -8, size: 8
148-
CHECK-NEXT: #2: Direct R#6 + -40, size: 8
147+
CHECK-NEXT: #2: Direct R#6 + -16, size: 8
149148
CHECK-NEXT: 1 live-outs: [ R#7 (8-bytes) ]
150149

151150
CHECK: Record ID: 4294967295, instruction offset: 4
@@ -169,6 +168,6 @@ CHECK-NEXT: 1 locations:
169168
CHECK-NEXT: #1: Indirect [R#6 + -44], size: 4
170169
CHECK-NEXT: 0 live-outs: [ ]
171170

172-
CHECK: Record ID: 0, instruction offset: 26
171+
CHECK: Record ID: 0, instruction offset: 25
173172
CHECK-NEXT: 0 locations:
174173
CHECK-NEXT: 0 live-outs: [ ]

0 commit comments

Comments
 (0)