1 ## Check that we correctly display the contents of the .stack_sizes section
2 ## in a relocatable object file.
4 # RUN: yaml2obj --docnum=1 %s > %t01
5 # RUN: llvm-readelf --stack-sizes %t01 \
6 # RUN: | FileCheck %s --check-prefix=RELOC-GNU --strict-whitespace --match-full-lines
7 # RUN: llvm-readobj --stack-sizes %t01 | FileCheck %s --check-prefix=RELOC-LLVM
9 # RELOC-GNU: Size Function
10 # RELOC-GNU-NEXT: 16 referenced_by_symbol_foo
11 # RELOC-GNU-NEXT: 32 referenced_via_section_bar
12 # RELOC-GNU-NEXT: 8 separate_text_section_baz
15 # RELOC-LLVM: StackSizes [
16 # RELOC-LLVM-NEXT: Entry {
17 # RELOC-LLVM-NEXT: Function: referenced_by_symbol_foo
18 # RELOC-LLVM-NEXT: Size: 0x10
20 # RELOC-LLVM-NEXT: Entry {
21 # RELOC-LLVM-NEXT: Function: referenced_via_section_bar
22 # RELOC-LLVM-NEXT: Size: 0x20
24 # RELOC-LLVM-NEXT: Entry {
25 # RELOC-LLVM-NEXT: Function: separate_text_section_baz
26 # RELOC-LLVM-NEXT: Size: 0x8
51 - Name: '.stack_sizes [1]'
57 - Name: .rela.stack_sizes
61 ## A symbol relative reference.
63 Symbol: referenced_by_symbol_foo
65 ## A section relative reference.
70 - Name: '.rela.stack_sizes [1]'
72 Info: '.stack_sizes [1]'
75 Symbol: separate_text_section_baz
78 - Name: separate_text_section_baz
84 - Name: referenced_by_symbol_foo
88 - Name: referenced_via_section_bar
94 ## Check that we correctly report the stack sizes in an executable (non-relocatable)
97 # RUN: yaml2obj --docnum=2 %s > %t02
98 # RUN: llvm-readelf --stack-sizes %t02 \
99 # RUN: | FileCheck %s --check-prefix=EXEC-GNU --strict-whitespace --match-full-lines
100 # RUN: llvm-readobj --stack-sizes %t02 | FileCheck %s --check-prefix=EXEC-LLVM
102 # EXEC-GNU: Size Function
103 # EXEC-GNU-NEXT: 16 foo
104 # EXEC-GNU-NEXT: 32 bar
107 # EXEC-LLVM: StackSizes [
108 # EXEC-LLVM-NEXT: Entry {
109 # EXEC-LLVM-NEXT: Function: foo
110 # EXEC-LLVM-NEXT: Size: 0x10
112 # EXEC-LLVM-NEXT: Entry {
113 # EXEC-LLVM-NEXT: Function: bar
114 # EXEC-LLVM-NEXT: Size: 0x20
149 ## Check that we report an error when we find relocations whose offsets point outside
150 ## of the .stack_sizes section.
152 # RUN: yaml2obj --docnum=3 %s > %t03
153 # RUN: not llvm-readelf --stack-sizes %t03 2>&1 | FileCheck %s --check-prefix=SHORT -DFILE=%t03
154 # RUN: not llvm-readobj --stack-sizes %t03 2>&1 | FileCheck %s --check-prefix=SHORT -DFILE=%t03
156 # SHORT: error: '[[FILE]]': found invalid relocation offset into section .stack_sizes while trying to extract a stack size entry
173 - Name: .rela.stack_sizes
186 ## Check that we warn about a function symbol that is not in the section
187 ## that is referenced by the stack sizes section's sh_link.
189 # RUN: yaml2obj --docnum=4 %s > %t04
190 # RUN: llvm-readelf --stack-sizes %t04 2> %t04-gnu.err | FileCheck %s --check-prefix=WRONGSECTION-GNU
191 # RUN: FileCheck %s < %t04-gnu.err --check-prefix=WRONGSECTION-ERR -DFILE=%t04
192 # RUN: llvm-readobj --stack-sizes %t04 2> %t04-llvm.err | FileCheck %s --check-prefix=WRONGSECTION-LLVM
193 # RUN: FileCheck %s < %t04-llvm.err --check-prefix=WRONGSECTION-ERR -DFILE=%t04
195 # RUN: llvm-readelf --stack-sizes --demangle %t04 2>&1 | FileCheck %s --check-prefix=WRONGSECTION-DEMANGLE-ERR -DFILE=%t04
196 # RUN: llvm-readobj --stack-sizes --demangle %t04 2>&1 | FileCheck %s --check-prefix=WRONGSECTION-DEMANGLE-ERR -DFILE=%t04
198 # WRONGSECTION-GNU: Size Function
199 # WRONGSECTION-GNU-NEXT: 8 _Z3foof
201 # WRONGSECTION-LLVM: StackSizes [
202 # WRONGSECTION-LLVM-NEXT: Entry {
203 # WRONGSECTION-LLVM-NEXT: Function: _Z3foof
204 # WRONGSECTION-LLVM-NEXT: Size: 0x8
205 # WRONGSECTION-LLVM-NEXT: }
206 # WRONGSECTION-LLVM-NEXT: ]
208 # WRONGSECTION-ERR: warning: '[[FILE]]': relocation symbol '_Z3foof' is not in the expected section
209 # WRONGSECTION-DEMANGLE-ERR: warning: '[[FILE]]': relocation symbol 'foo(float)' is not in the expected section
230 - Name: .rela.stack_sizes
243 ## Check that we report an error when a stack sizes section ends with an incomplete stack size entry.
245 # RUN: yaml2obj --docnum=5 %s > %t05
246 # RUN: not llvm-readelf --stack-sizes %t05 2>&1 | \
247 # RUN: FileCheck %s --check-prefix=SUDDENEND -DFILE=%t05
248 # RUN: not llvm-readobj --stack-sizes %t05 2>&1 | \
249 # RUN: FileCheck %s --check-prefix=SUDDENEND -DFILE=%t05
251 # SUDDENEND: error: '[[FILE]]': section .stack_sizes ended while trying to extract a stack size entry
275 ## Check that we report an invalid stack size, which is represented by a ULEB that
276 ## ends in a byte with the high bit set.
278 # RUN: yaml2obj --docnum=6 %s > %t06
279 # RUN: not llvm-readelf --stack-sizes %t06 2>&1 | FileCheck %s --check-prefix=BADSIZE -DFILE=%t06
280 # RUN: not llvm-readobj --stack-sizes %t06 2>&1 | FileCheck %s --check-prefix=BADSIZE -DFILE=%t06
282 # BADSIZE: error: '[[FILE]]': could not extract a valid stack size in section .stack_sizes
297 Content: "100000000000000080"
306 ## Check that we report a warning when a relocation symbol does not belong to a
307 ## valid section. We expect a stack size entry with an unknown symbol in the
310 # RUN: yaml2obj --docnum=7 %s > %t07
311 # RUN: llvm-readelf --stack-sizes %t07 2> %t07-gnu.err | FileCheck %s --check-prefix=BADSECTION-OUT-GNU
312 # RUN: FileCheck %s < %t07-gnu.err --check-prefix=BADSECTION-ERR -DFILE=%t07
313 # RUN: llvm-readobj --stack-sizes %t07 2> %t07-llvm.err | FileCheck %s --check-prefix=BADSECTION-OUT-LLVM
314 # RUN: FileCheck %s < %t07-llvm.err --check-prefix=BADSECTION-ERR -DFILE=%t07
316 # RUN: llvm-readelf --stack-sizes --demangle %t07 2>&1 | FileCheck %s --check-prefix=BADSECTION-DEMANGLE-ERR -DFILE=%t07
317 # RUN: llvm-readobj --stack-sizes --demangle %t07 2>&1 | FileCheck %s --check-prefix=BADSECTION-DEMANGLE-ERR -DFILE=%t07
319 # BADSECTION-OUT-GNU: Size Function
320 # BADSECTION-OUT-GNU: 8 ?
322 # BADSECTION-OUT-LLVM: StackSizes [
323 # BADSECTION-OUT-LLVM-NEXT: Entry {
324 # BADSECTION-OUT-LLVM-NEXT: Function: ?
325 # BADSECTION-OUT-LLVM-NEXT: Size: 0x8
326 # BADSECTION-OUT-LLVM-NEXT: }
327 # BADSECTION-OUT-LLVM-NEXT: ]
329 # BADSECTION-ERR: warning: '[[FILE]]': cannot identify the section for relocation symbol '_Z3foof'
330 # BADSECTION-DEMANGLE-ERR: warning: '[[FILE]]': cannot identify the section for relocation symbol 'foo(float)'
347 - Name: .rela.stack_sizes
356 ## An invalid section index.
361 ## Check that we report a warning when a stack sizes section does not come with
362 ## a corresponding relocation section.
364 # RUN: yaml2obj --docnum=8 %s > %t08
365 # RUN: llvm-readelf --stack-sizes %t08 2> %t08-gnu.err | FileCheck %s --check-prefix=NORELOCSECTION-OUT-GNU
366 # RUN: FileCheck %s < %t08-gnu.err --check-prefix=NORELOCSECTION-ERR -DFILE=%t08
367 # RUN: llvm-readobj --stack-sizes %t08 2> %t08-llvm.err | FileCheck %s --check-prefix=NORELOCSECTION-OUT-LLVM
368 # RUN: FileCheck %s < %t08-llvm.err --check-prefix=NORELOCSECTION-ERR -DFILE=%t08
370 # NORELOCSECTION-OUT-GNU: Size Function
371 # NORELOCSECTION-OUT-GNU-NOT: {{.}}
373 # NORELOCSECTION-OUT-LLVM: StackSizes [
374 # NORELOCSECTION-OUT-LLVM-NEXT: ]
376 # NORELOCSECTION-ERR: warning: '[[FILE]]': section .stack_sizes does not have a corresponding relocation section
394 ## Check that we handle multiple object files, separately and when they
395 ## are in an archive. This also checks whether we have blank lines between the
398 # RUN: llvm-ar rc %t1.a %t01 %t02
399 # RUN: llvm-readelf --stack-sizes %t01 %t02 \
400 # RUN: | FileCheck %s --check-prefixes=MULTIPLE-GNU,OBJECT -DFILE1=%t01 -DFILE2=%t02
401 # RUN: llvm-readelf --stack-sizes %t1.a \
402 # RUN: | FileCheck %s --check-prefixes=MULTIPLE-GNU,ARCHIVE --strict-whitespace\
403 # RUN: --match-full-lines -DFILE=%t1.a
404 # RUN: llvm-readobj --stack-sizes %t01 %t02 \
405 # RUN: | FileCheck %s --check-prefixes=MULTIPLE-LLVM,OBJECT -DFILE1=%t01 -DFILE2=%t02
406 # RUN: llvm-readobj --stack-sizes %t1.a \
407 # RUN: | FileCheck %s --check-prefixes=MULTIPLE-LLVM,ARCHIVE -DFILE=%t1.a
409 # OBJECT:File: [[FILE1]]
410 # ARCHIVE:File: [[FILE]]({{.*01}})
412 # MULTIPLE-GNU:Stack Sizes:
413 # MULTIPLE-GNU-NEXT: Size Function
414 # MULTIPLE-GNU-NEXT: 16 referenced_by_symbol_foo
415 # MULTIPLE-GNU-NEXT: 32 referenced_via_section_bar
416 # MULTIPLE-GNU-NEXT: 8 separate_text_section_baz
417 # MULTIPLE-GNU-EMPTY:
419 # MULTIPLE-LLVM: StackSizes [
420 # MULTIPLE-LLVM-NEXT: Entry {
421 # MULTIPLE-LLVM-NEXT: Function: referenced_by_symbol_foo
422 # MULTIPLE-LLVM-NEXT: Size: 0x10
423 # MULTIPLE-LLVM-NEXT: }
424 # MULTIPLE-LLVM-NEXT: Entry {
425 # MULTIPLE-LLVM-NEXT: Function: referenced_via_section_bar
426 # MULTIPLE-LLVM-NEXT: Size: 0x20
427 # MULTIPLE-LLVM-NEXT: }
428 # MULTIPLE-LLVM-NEXT: Entry {
429 # MULTIPLE-LLVM-NEXT: Function: separate_text_section_baz
430 # MULTIPLE-LLVM-NEXT: Size: 0x8
431 # MULTIPLE-LLVM-NEXT: }
432 # MULTIPLE-LLVM-NEXT: ]
434 # OBJECT:File: [[FILE2]]
435 # ARCHIVE:File: [[FILE]]({{.*02}})
437 # MULTIPLE-GNU-EMPTY:
438 # MULTIPLE-GNU-NEXT:Stack Sizes:
439 # MULTIPLE-GNU-NEXT: Size Function
440 # MULTIPLE-GNU-NEXT: 16 foo
441 # MULTIPLE-GNU-NEXT: 32 bar
443 # MULTIPLE-LLVM: StackSizes [
444 # MULTIPLE-LLVM-NEXT: Entry {
445 # MULTIPLE-LLVM-NEXT: Function: foo
446 # MULTIPLE-LLVM-NEXT: Size: 0x10
447 # MULTIPLE-LLVM-NEXT: }
448 # MULTIPLE-LLVM-NEXT: Entry {
449 # MULTIPLE-LLVM-NEXT: Function: bar
450 # MULTIPLE-LLVM-NEXT: Size: 0x20
451 # MULTIPLE-LLVM-NEXT: }
452 # MULTIPLE-LLVM-NEXT: ]
454 ## Check that we do not consider symbols that are not function symbols, even though
455 ## a relocation references them.
457 # RUN: yaml2obj --docnum=9 %s > %t14
458 # RUN: llvm-readelf --stack-sizes %t14 2> %t14-gnu.err | FileCheck %s --check-prefix=NONFUNCTIONSYM-GNU
459 # RUN: FileCheck %s < %t14-gnu.err --check-prefix=NONFUNCTIONSYM-ERR -DFILE=%t14
460 # RUN: llvm-readobj --stack-sizes %t14 2> %t14-llvm.err | FileCheck %s --check-prefix=NONFUNCTIONSYM-LLVM
461 # RUN: FileCheck %s < %t14-llvm.err --check-prefix=NONFUNCTIONSYM-ERR -DFILE=%t14
463 # NONFUNCTIONSYM-GNU: Stack Sizes:
464 # NONFUNCTIONSYM-GNU: 0 ?
466 # NONFUNCTIONSYM-LLVM: StackSizes [
467 # NONFUNCTIONSYM-LLVM-NEXT: Entry {
468 # NONFUNCTIONSYM-LLVM-NEXT: Function: ?
469 # NONFUNCTIONSYM-LLVM-NEXT: Size: 0x0
470 # NONFUNCTIONSYM-LLVM-NEXT: }
471 # NONFUNCTIONSYM-LLVM-NEXT: ]
473 # NONFUNCTIONSYM-ERR: warning: '[[FILE]]': could not identify function symbol for stack size entry
490 - Name: .rela.stack_sizes
503 ## Check that we report an error when we find an unsupported relocation
504 ## in the section that contains the stack size entries' relocations.
506 # RUN: yaml2obj --docnum=10 %s > %t15
507 # RUN: not llvm-readelf --stack-sizes %t15 2>&1 | FileCheck %s --check-prefix=UNSUPPRELOC -DFILE=%t15
508 # RUN: not llvm-readobj --stack-sizes %t15 2>&1 | FileCheck %s --check-prefix=UNSUPPRELOC -DFILE=%t15
510 # UNSUPPRELOC: error: '[[FILE]]': unsupported relocation type in section .rela.stack_sizes: R_X86_64_RELATIVE
526 - Name: .rela.stack_sizes
532 Type: R_X86_64_RELATIVE
539 ## Check that warning messages in archives do not impact other members. In the following
540 ## test, the first archive member generates a warning and we make sure all the information
543 # RUN: llvm-ar rc %t2.a %t04 %t01
544 # RUN: llvm-readelf --stack-sizes %t2.a 2>&1 | FileCheck %s --check-prefix=ARCHIVEWARN-GNU \
545 # RUN: -DFILE=%t2.a --strict-whitespace --match-full-lines
546 # RUN: llvm-readobj --stack-sizes %t2.a 2>&1 | FileCheck %s --check-prefix=ARCHIVEWARN-LLVM -DFILE=%t2.a
548 # ARCHIVEWARN-GNU:File: [[FILE]]({{.*04}})
549 # ARCHIVEWARN-GNU:Stack Sizes:
550 # ARCHIVEWARN-GNU-NEXT: Size Function
551 # ARCHIVEWARN-GNU:{{.*}}: warning: '{{.*04}}': relocation symbol '_Z3foof' is not in the expected section
552 # ARCHIVEWARN-GNU: 8 _Z3foof
553 # ARCHIVEWARN-GNU:File: [[FILE]]({{.*01}})
554 # ARCHIVEWARN-GNU:Stack Sizes:
555 # ARCHIVEWARN-GNU-NEXT: Size Function
556 # ARCHIVEWARN-GNU-NEXT: 16 referenced_by_symbol_foo
557 # ARCHIVEWARN-GNU-NEXT: 32 referenced_via_section_bar
558 # ARCHIVEWARN-GNU-NEXT: 8 separate_text_section_baz
559 # ARCHIVEWARN-GNU-NOT:{{.}}
562 # ARCHIVEWARN-LLVM: File: [[FILE]]({{.*04}})
563 # ARCHIVEWARN-LLVM: StackSizes [
564 # ARCHIVEWARN-LLVM: warning: '{{.*04}}': relocation symbol '_Z3foof' is not in the expected section
565 # ARCHIVEWARN-LLVM-NEXT: Entry {
566 # ARCHIVEWARN-LLVM-NEXT: Function: _Z3foof
567 # ARCHIVEWARN-LLVM-NEXT: Size: 0x8
568 # ARCHIVEWARN-LLVM-NEXT: }
569 # ARCHIVEWARN-LLVM-NEXT: ]
570 # ARCHIVEWARN-LLVM: File: [[FILE]]({{.*01}})
571 # ARCHIVEWARN-LLVM: StackSizes [
572 # ARCHIVEWARN-LLVM-NEXT: Entry {
573 # ARCHIVEWARN-LLVM-NEXT: Function: referenced_by_symbol_foo
574 # ARCHIVEWARN-LLVM-NEXT: Size: 0x10
575 # ARCHIVEWARN-LLVM-NEXT: }
576 # ARCHIVEWARN-LLVM-NEXT: Entry {
577 # ARCHIVEWARN-LLVM-NEXT: Function: referenced_via_section_bar
578 # ARCHIVEWARN-LLVM-NEXT: Size: 0x20
579 # ARCHIVEWARN-LLVM-NEXT: }
580 # ARCHIVEWARN-LLVM-NEXT: Entry {
581 # ARCHIVEWARN-LLVM-NEXT: Function: separate_text_section_baz
582 # ARCHIVEWARN-LLVM-NEXT: Size: 0x8
583 # ARCHIVEWARN-LLVM-NEXT: }
584 # ARCHIVEWARN-LLVM-NEXT: ]
586 ## Check that we demangle function names when requested.
588 # RUN: yaml2obj --docnum=11 %s > %t16
589 # RUN: llvm-readelf --stack-sizes --demangle %t16 | FileCheck %s --check-prefix=DEMANGLE-GNU
590 # RUN: llvm-readobj --stack-sizes --demangle %t16 | FileCheck %s --check-prefix=DEMANGLE-LLVM
592 # DEMANGLE-GNU: 16 foo(float)
593 # DEMANGLE-LLVM: Function: foo(float)
619 ## Check that we report an error when we are unable to resolve a relocation for a given ELF architecture.
620 ## Here we have a 64-bit relocation used in a 32-bit object.
622 # RUN: yaml2obj --docnum=12 %s > %t17
623 # RUN: not llvm-readelf --stack-sizes %t17 2>&1 | FileCheck %s -DFILE=%t17 --check-prefix=UNSUPPRELOC2
624 # RUN: not llvm-readobj --stack-sizes %t17 2>&1 | FileCheck %s -DFILE=%t17 --check-prefix=UNSUPPRELOC2
626 # UNSUPPRELOC2: error: '[[FILE]]': unsupported relocation type in section .rela.stack_sizes: R_X86_64_64
638 - Name: .rela.stack_sizes
645 ## Check we report an error when dumping stack sizes if the relocated section
646 ## identified by the sh_info field is invalid. Here sh_info value is larger than
647 ## the number of sections.
649 # RUN: yaml2obj --docnum=13 %s > %t18
650 # RUN: not llvm-readelf --stack-sizes %t18 2>&1 | FileCheck %s -DFILE=%t18 --check-prefix=INVALID-TARGET
651 # RUN: not llvm-readobj --stack-sizes %t18 2>&1 | FileCheck %s -DFILE=%t18 --check-prefix=INVALID-TARGET
653 # INVALID-TARGET: error: '[[FILE]]': .rela.stack_sizes: failed to get a relocated section: invalid section index: 255
662 - Name: .rela.stack_sizes