blob: ecfba00dd712e6df6bce6f9b0613f597dd57e78d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
|
## Check that we correctly display the contents of the .stack_sizes section
## in a relocatable object file.
# RUN: yaml2obj --docnum=1 %s > %t01
# RUN: llvm-readelf --stack-sizes %t01 \
# RUN: | FileCheck %s --check-prefix=RELOC --strict-whitespace --match-full-lines
# RELOC: Size Function
# RELOC-NEXT: 16 referenced_by_symbol_foo
# RELOC-NEXT: 32 referenced_via_section_bar
# RELOC-NEXT: 8 separate_text_section_baz
# RELOC-NOT:{{.}}
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_REL
Machine: EM_X86_64
Sections:
- Name: .text
Type: SHT_PROGBITS
Flags: [SHF_ALLOC]
Size: 16
- Name: .text.baz
Type: SHT_PROGBITS
Flags: [SHF_ALLOC]
Size: 16
- Name: .stack_sizes
Type: SHT_PROGBITS
## 2 stack size entries. Each consists of an address (subject to relocation)
## followed by a ULEB for the size.
Content: "000000000000000010000000000000000020"
Link: .text
- Name: .stack_sizes.baz
Type: SHT_PROGBITS
## One stack size entry.
Content: "200000000000000008"
Link: .text.baz
- Name: .rela.stack_sizes
Type: SHT_RELA
Info: .stack_sizes
Relocations:
## A symbol relative reference.
- Offset: 0
Symbol: referenced_by_symbol_foo
Type: R_X86_64_64
## A section relative reference.
- Offset: 9
Addend: 16
Symbol: .text
Type: R_X86_64_64
- Name: .rela.stack_sizes.baz
Type: SHT_RELA
Info: .stack_sizes.baz
Relocations:
- Offset: 0
Symbol: separate_text_section_baz
Type: R_X86_64_64
Symbols:
- Name: separate_text_section_baz
Section: .text.baz
Type: STT_FUNC
- Name: .text
Section: .text
Type: STT_SECTION
- Name: referenced_by_symbol_foo
Section: .text
Type: STT_FUNC
Binding: STB_GLOBAL
- Name: referenced_via_section_bar
Section: .text
Value: 0x10
Type: STT_FUNC
Binding: STB_GLOBAL
## Check that we correctly report the stack sizes in an executable (non-relocatable)
## object file.
# RUN: yaml2obj --docnum=2 %s > %t02
# RUN: llvm-readelf --stack-sizes %t02 \
# RUN: | FileCheck %s --check-prefix=EXEC --strict-whitespace --match-full-lines
# EXEC: Size Function
# EXEC-NEXT: 16 foo
# EXEC-NEXT: 32 bar
# EXEC-NOT:{{.}}
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_EXEC
Machine: EM_X86_64
Sections:
- Name: .text
Type: SHT_PROGBITS
Flags: [SHF_ALLOC]
Size: 16
- Name: .stack_sizes
Type: SHT_PROGBITS
Content: "100000000000000010200000000000000020"
Link: .text
Symbols:
- Name: foo
Section: .text
Value: 0x10
Type: STT_FUNC
Binding: STB_GLOBAL
- Name: bar
Section: .text
Value: 0x20
Type: STT_FUNC
Binding: STB_GLOBAL
## Check that we report an error when we find relocations whose offsets point outside
## of the .stack_sizes section.
# RUN: yaml2obj --docnum=3 %s > %t03
# RUN: not llvm-readelf --stack-sizes %t03 2>&1 | FileCheck %s --check-prefix=SHORT -DFILE=%t03
# SHORT: error: '[[FILE]]': found invalid relocation offset into section .stack_sizes while trying to extract a stack size entry
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_REL
Machine: EM_X86_64
Sections:
- Name: .text
Type: SHT_PROGBITS
Flags: [SHF_ALLOC]
Size: 16
- Name: .stack_sizes
Type: SHT_PROGBITS
Size: 1
Link: .text
- Name: .rela.stack_sizes
Type: SHT_RELA
Info: .stack_sizes
Relocations:
- Offset: 1
Symbol: foo
Type: R_X86_64_64
Symbols:
- Name: foo
Section: .text
Type: STT_FUNC
Binding: STB_GLOBAL
## Check that we warn about a function symbol that is not in the section
## that is referenced by the stack sizes section's sh_link.
# RUN: yaml2obj --docnum=4 %s > %t04
# RUN: llvm-readelf --stack-sizes %t04 2> %t04.err | FileCheck %s --check-prefix=WRONGSECTION
# RUN: FileCheck %s < %t04.err --check-prefix=WRONGSECTION-ERR -DFILE=%t04
# WRONGSECTION: Size Function
# WRONGSECTION-NEXT: 8 foo
# WRONGSECTION-ERR: warning: '[[FILE]]': relocation symbol foo is not in the expected section
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_REL
Machine: EM_X86_64
Sections:
- Name: .text
Type: SHT_PROGBITS
Size: 8
- Name: .text2
Type: SHT_PROGBITS
Size: 8
Flags: [SHF_ALLOC]
- Name: .stack_sizes
Type: SHT_PROGBITS
Content: "000000000000000008"
Link: .text2
- Name: .rela.stack_sizes
Type: SHT_RELA
Info: .stack_sizes
Relocations:
- Offset: 0
Symbol: foo
Type: R_X86_64_64
Symbols:
- Name: foo
Section: .text
Type: STT_FUNC
Binding: STB_GLOBAL
## Check that we report an error when a stack sizes section ends with an incomplete stack size entry.
# RUN: yaml2obj --docnum=5 %s > %t05
# RUN: not llvm-readelf --stack-sizes %t05 2>&1 %t05.err | \
# RUN: FileCheck %s --check-prefix=SUDDENEND -DFILE=%t05
# SUDDENEND: error: '[[FILE]]': section .stack_sizes ended while trying to extract a stack size entry
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_EXEC
Machine: EM_X86_64
Sections:
- Name: .text
Type: SHT_PROGBITS
Flags: [SHF_ALLOC]
Size: 16
- Name: .stack_sizes
Type: SHT_PROGBITS
Content: "10000000"
Link: .text
Symbols:
- Name: foo
Section: .text
Value: 0x10
Type: STT_FUNC
Binding: STB_GLOBAL
## Check that we report an invalid stack size, which is represented by a ULEB that
## ends in a byte with the high bit set.
# RUN: yaml2obj --docnum=6 %s > %t06
# RUN: not llvm-readelf --stack-sizes %t06 2>&1 | FileCheck %s --check-prefix=BADSIZE -DFILE=%t06
# BADSIZE: error: '[[FILE]]': could not extract a valid stack size in section .stack_sizes
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_EXEC
Machine: EM_X86_64
Sections:
- Name: .text
Type: SHT_PROGBITS
Flags: [SHF_ALLOC]
Size: 16
- Name: .stack_sizes
Type: SHT_PROGBITS
Content: "100000000000000080"
Link: .text
Symbols:
- Name: foo
Section: .text
Value: 0x10
Type: STT_FUNC
Binding: STB_GLOBAL
## Check that we report a warning when a relocation symbol does not belong to a
## valid section. We expect a stack size entry with an unknown symbol in the
## output.
# RUN: yaml2obj --docnum=7 %s > %t07
# RUN: llvm-readelf --stack-sizes %t07 2> %t07.err | FileCheck %s --check-prefix=BADSECTION-OUT
# RUN: FileCheck %s < %t07.err --check-prefix=BADSECTION-ERR -DFILE=%t07
# BADSECTION-OUT: Size Function
# BADSECTION-OUT: 8 ?
# BADSECTION-ERR: warning: '[[FILE]]': cannot identify the section for relocation symbol foo
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_REL
Machine: EM_X86_64
Sections:
- Name: .text
Type: SHT_PROGBITS
Size: 8
- Name: .stack_sizes
Type: SHT_PROGBITS
Link: .text
Content: "000000000000000008"
- Name: .rela.stack_sizes
Type: SHT_RELA
Info: .stack_sizes
Relocations:
- Offset: 0
Symbol: foo
Type: R_X86_64_64
Symbols:
- Name: foo
## An invalid section index.
Index: 10
Type: STT_FUNC
Binding: STB_GLOBAL
## Check that we report a warning when a stack sizes section does not come with
## a corresponding relocation section.
# RUN: yaml2obj --docnum=8 %s > %t08
# RUN: llvm-readelf --stack-sizes %t08 2> %t08.err | FileCheck %s --check-prefix=NORELOCSECTION-OUT
# RUN: FileCheck %s < %t08.err --check-prefix=NORELOCSECTION-ERR -DFILE=%t08
# NORELOCSECTION-OUT: Size Function
# NORELOCSECTION-OUT-NOT: {{.}}
# NORELOCSECTION-ERR: warning: '[[FILE]]': section .stack_sizes does not have a corresponding relocation section
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_REL
Machine: EM_X86_64
Sections:
- Name: .text
Type: SHT_PROGBITS
Size: 8
- Name: .stack_sizes
Type: SHT_PROGBITS
Link: .text
Content: "000000000000000008"
## Check that we handle multiple object files, separately and when they
## are in an archive. This also checks whether we have blank lines between the
## tables.
# RUN: llvm-ar rc %t1.a %t01 %t02
# RUN: llvm-readelf --stack-sizes %t01 %t02 | FileCheck %s --check-prefix=MULTIPLE
# RUN: llvm-readelf --stack-sizes %t1.a \
# RUN: | FileCheck %s --check-prefix=MULTIPLE --check-prefix=ARCHIVE --strict-whitespace\
# RUN: --match-full-lines -DFILE=%t1.a
# ARCHIVE:File: [[FILE]]({{.*01}})
# MULTIPLE:Stack Sizes:
# MULTIPLE-NEXT: Size Function
# MULTIPLE-NEXT: 16 referenced_by_symbol_foo
# MULTIPLE-NEXT: 32 referenced_via_section_bar
# MULTIPLE-NEXT: 8 separate_text_section_baz
# MULTIPLE-EMPTY:
# ARCHIVE:File: [[FILE]]({{.*02}})
# MULTIPLE-EMPTY:
# MULTIPLE-NEXT:Stack Sizes:
# MULTIPLE-NEXT: Size Function
# MULTIPLE-NEXT: 16 foo
# MULTIPLE-NEXT: 32 bar
## Check that we do not consider symbols that are not function symbols, even though
## a relocation references them.
# RUN: yaml2obj --docnum=9 %s > %t14
# RUN: llvm-readelf --stack-sizes %t14 2> %t14.err | FileCheck %s --check-prefix=NONFUNCTIONSYM
# RUN: FileCheck %s < %t14.err --check-prefix=NONFUNCTIONSYM-ERR -DFILE=%t14
# NONFUNCTIONSYM: Stack Sizes:
# NONFUNCTIONSYM: 0 ?
# NONFUNCTIONSYM-ERR: warning: '[[FILE]]': could not identify function symbol for stack size entry
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_REL
Machine: EM_X86_64
Sections:
- Name: .text
Type: SHT_PROGBITS
Size: 16
- Name: .stack_sizes
Type: SHT_PROGBITS
Size: 9
Link: .text
- Name: .rela.stack_sizes
Type: SHT_RELA
Info: .stack_sizes
Relocations:
- Offset: 0
Symbol: foo
Type: R_X86_64_64
Symbols:
- Name: foo
Section: .text
Type: STT_OBJECT
Binding: STB_GLOBAL
## Check that we report an error when we find an unsupported relocation
## in the section that contains the stack size entries' relocations.
# RUN: yaml2obj --docnum=10 %s > %t15
# RUN: not llvm-readelf --stack-sizes %t15 2>&1 | FileCheck %s --check-prefix=UNSUPPRELOC -DFILE=%t15
# UNSUPPRELOC: error: '[[FILE]]': unsupported relocation type in section .rela.stack_sizes: R_X86_64_RELATIVE
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_REL
Machine: EM_X86_64
Sections:
- Name: .text
Type: SHT_PROGBITS
Size: 8
- Name: .stack_sizes
Type: SHT_PROGBITS
Size: 16
Link: .text
- Name: .rela.stack_sizes
Type: SHT_RELA
Info: .stack_sizes
Relocations:
- Offset: 0
Symbol: foo
Type: R_X86_64_RELATIVE
Symbols:
- Name: foo
Section: .text
Type: STT_FUNC
Binding: STB_GLOBAL
## Check that warning messages in archives do not impact other members. In the following
## test, the first archive member generates a warning and we make sure all the information
## is still dumped.
# RUN: llvm-ar rc %t2.a %t04 %t01
# RUN: llvm-readelf --stack-sizes %t2.a 2>&1 | FileCheck %s --check-prefix=ARCHIVEWARN \
# RUN: -DFILE=%t2.a --strict-whitespace --match-full-lines
# ARCHIVEWARN:File: [[FILE]]({{.*04}})
# ARCHIVEWARN:Stack Sizes:
# ARCHIVEWARN-NEXT: Size Function
# ARCHIVEWARN: 8 foo
# ARCHIVEWARN:File: [[FILE]]({{.*01}})
# ARCHIVEWARN:Stack Sizes:
# ARCHIVEWARN-NEXT: Size Function
# ARCHIVEWARN-NEXT: 16 referenced_by_symbol_foo
# ARCHIVEWARN-NEXT: 32 referenced_via_section_bar
# ARCHIVEWARN-NEXT: 8 separate_text_section_baz
# ARCHIVEWARN-NOT:{{.}}
# ARCHIVEWARN-ERR:warning: '[[FILE]]': relocation symbol foo is not in the expected section
## Check that we demangle function names when requested.
# RUN: yaml2obj --docnum=11 %s > %t16
# RUN: llvm-readelf --stack-sizes --demangle %t16 | FileCheck %s --check-prefix=DEMANGLE
# DEMANGLE: 16 foo(float)
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_EXEC
Machine: EM_X86_64
Sections:
- Name: .text
Type: SHT_PROGBITS
Flags: [SHF_ALLOC]
Size: 16
- Name: .stack_sizes
Type: SHT_PROGBITS
Content: "100000000000000010"
Link: .text
Symbols:
- Name: _Z3foof
Section: .text
Value: 0x10
Type: STT_FUNC
Binding: STB_GLOBAL
## Check that we emit a 'not implemented' message for an attempt to dump stack-sizes
## sections LLVM-style, i.e. when invoking llvm-readobj.
## FIXME: Replace this test with something functional when the feature is implemented.
# RUN: llvm-readobj --stack-sizes %t01 | FileCheck %s --check-prefix=NOTIMPLEMENTED
# NOTIMPLEMENTED: Dumping of stack sizes in LLVM style is not implemented yet
|