942 lines · plain
1## Check that we correctly display the contents of the .stack_sizes section2## in a relocatable object file.3 4# RUN: yaml2obj --docnum=1 %s -o %t015# RUN: llvm-readelf --stack-sizes %t01 \6# RUN: | FileCheck %s --check-prefix=RELOC-GNU --strict-whitespace --match-full-lines7# RUN: llvm-readobj --stack-sizes %t01 | FileCheck %s --check-prefix=RELOC-LLVM8 9# RELOC-GNU: Size Functions10# RELOC-GNU-NEXT: 16 referenced_by_symbol_foo11# RELOC-GNU-NEXT: 32 referenced_via_section_bar12# RELOC-GNU-NEXT: 8 separate_text_section_baz13# RELOC-GNU-NOT:{{.}}14 15# RELOC-LLVM: StackSizes [16# RELOC-LLVM-NEXT: Entry {17# RELOC-LLVM-NEXT: Functions: [referenced_by_symbol_foo]18# RELOC-LLVM-NEXT: Size: 0x1019# RELOC-LLVM-NEXT: }20# RELOC-LLVM-NEXT: Entry {21# RELOC-LLVM-NEXT: Functions: [referenced_via_section_bar]22# RELOC-LLVM-NEXT: Size: 0x2023# RELOC-LLVM-NEXT: }24# RELOC-LLVM-NEXT: Entry {25# RELOC-LLVM-NEXT: Functions: [separate_text_section_baz]26# RELOC-LLVM-NEXT: Size: 0x827# RELOC-LLVM-NEXT: }28# RELOC-LLVM-NEXT: ]29 30--- !ELF31FileHeader:32 Class: ELFCLASS6433 Data: ELFDATA2LSB34 Type: ET_REL35 Machine: EM_X86_6436Sections:37 - Name: .text38 Type: SHT_PROGBITS39 Flags: [SHF_ALLOC]40 Size: 1641 - Name: .text.baz42 Type: SHT_PROGBITS43 Flags: [SHF_ALLOC]44 Size: 1645 - Name: .stack_sizes46 Type: SHT_PROGBITS47 Entries:48 - Size: 0x1049 - Size: 0x2050 Link: .text51 - Name: '.stack_sizes (1)'52 Type: SHT_PROGBITS53 Entries:54 - Address: 0x2055 Size: 0x856 Link: .text.baz57 - Name: .rela.stack_sizes58 Type: SHT_RELA59 Info: .stack_sizes60 Relocations:61## A symbol relative reference. 62 - Offset: 063 Symbol: referenced_by_symbol_foo 64 Type: R_X86_64_6465## A section relative reference. 66 - Offset: 967 Addend: 1668 Symbol: .text69 Type: R_X86_64_6470 - Name: '.rela.stack_sizes (1)'71 Type: SHT_RELA72 Info: '.stack_sizes (1)'73 Relocations:74 - Offset: 075 Symbol: separate_text_section_baz76 Type: R_X86_64_6477 - Name: .symtab78 Type: SHT_SYMTAB79 ShOffset: [[SYMTABOFFSET=<none>]]80Symbols:81 - Name: separate_text_section_baz82 Section: [[SEC1=.text.baz]]83 Type: STT_FUNC84 Index: [[SEC1INDEX=<none>]]85 - Name: .text86 Section: .text87 Type: STT_SECTION88 - Name: referenced_by_symbol_foo89 Section: .text90 Type: STT_FUNC91 Binding: STB_GLOBAL92 - Name: referenced_via_section_bar93 Section: .text94 Value: 0x1095 Type: STT_FUNC96 Binding: STB_GLOBAL97 98## Check that we report a warning when we are unable to read99## the symbol table when dumping stack sizes.100 101# RUN: yaml2obj --docnum=1 %s -DSYMTABOFFSET=0xffffeeee -o %t01.broken.symtab102# RUN: llvm-readelf --stack-sizes %t01.broken.symtab 2>&1 | \103# RUN: FileCheck %s -DFILE=%t01.broken.symtab --check-prefix=SYMTAB-GNU --implicit-check-not=warning:104# RUN: llvm-readobj --stack-sizes %t01.broken.symtab 2>&1 | \105# RUN: FileCheck %s -DFILE=%t01.broken.symtab --check-prefix=SYMTAB-LLVM --implicit-check-not=warning:106 107# SYMTAB-GNU: Stack Sizes:108# SYMTAB-GNU-NEXT: Size Functions109# SYMTAB-GNU-NEXT: warning: '[[FILE]]': unable to get the target of relocation with index 0 in SHT_RELA section with index 5: unable to read an entry with index 3 from SHT_SYMTAB section with index 7: section [index 7] has a sh_offset (0xffffeeee) + sh_size (0x78) that is greater than the file size (0x450)110# SYMTAB-GNU-NEXT: warning: '[[FILE]]': unable to read the symbol table: section [index 7] has a sh_offset (0xffffeeee) + sh_size (0x78) that is greater than the file size (0x450)111# SYMTAB-GNU-NEXT: warning: '[[FILE]]': could not identify function symbol for stack size entry in SHT_PROGBITS section with index 3112# SYMTAB-GNU-NEXT: 16 ?113# SYMTAB-GNU-NEXT: warning: '[[FILE]]': unable to get the target of relocation with index 1 in SHT_RELA section with index 5: unable to read an entry with index 2 from SHT_SYMTAB section with index 7: section [index 7] has a sh_offset (0xffffeeee) + sh_size (0x78) that is greater than the file size (0x450)114# SYMTAB-GNU-NEXT: 32 ?115# SYMTAB-GNU-NEXT: warning: '[[FILE]]': unable to get the target of relocation with index 0 in SHT_RELA section with index 6: unable to read an entry with index 1 from SHT_SYMTAB section with index 7: section [index 7] has a sh_offset (0xffffeeee) + sh_size (0x78) that is greater than the file size (0x450)116# SYMTAB-GNU-NEXT: warning: '[[FILE]]': could not identify function symbol for stack size entry in SHT_PROGBITS section with index 4117# SYMTAB-GNU-NEXT: 8 ?118 119# SYMTAB-LLVM: StackSizes [120# SYMTAB-LLVM-NEXT: warning: '[[FILE]]': unable to get the target of relocation with index 0 in SHT_RELA section with index 5: unable to read an entry with index 3 from SHT_SYMTAB section with index 7: section [index 7] has a sh_offset (0xffffeeee) + sh_size (0x78) that is greater than the file size (0x450)121# SYMTAB-LLVM-NEXT: warning: '[[FILE]]': unable to read the symbol table: section [index 7] has a sh_offset (0xffffeeee) + sh_size (0x78) that is greater than the file size (0x450)122# SYMTAB-LLVM-NEXT: warning: '[[FILE]]': could not identify function symbol for stack size entry in SHT_PROGBITS section with index 3123# SYMTAB-LLVM-NEXT: Entry {124# SYMTAB-LLVM-NEXT: Functions: [?]125# SYMTAB-LLVM-NEXT: Size: 0x10126# SYMTAB-LLVM-NEXT: }127# SYMTAB-LLVM-NEXT: warning: '[[FILE]]': unable to get the target of relocation with index 1 in SHT_RELA section with index 5: unable to read an entry with index 2 from SHT_SYMTAB section with index 7: section [index 7] has a sh_offset (0xffffeeee) + sh_size (0x78) that is greater than the file size (0x450)128# SYMTAB-LLVM-NEXT: Entry {129# SYMTAB-LLVM-NEXT: Functions: [?]130# SYMTAB-LLVM-NEXT: Size: 0x20131# SYMTAB-LLVM-NEXT: }132# SYMTAB-LLVM-NEXT: warning: '[[FILE]]': unable to get the target of relocation with index 0 in SHT_RELA section with index 6: unable to read an entry with index 1 from SHT_SYMTAB section with index 7: section [index 7] has a sh_offset (0xffffeeee) + sh_size (0x78) that is greater than the file size (0x450)133# SYMTAB-LLVM-NEXT: warning: '[[FILE]]': could not identify function symbol for stack size entry in SHT_PROGBITS section with index 4134# SYMTAB-LLVM-NEXT: Entry {135# SYMTAB-LLVM-NEXT: Functions: [?]136# SYMTAB-LLVM-NEXT: Size: 0x8137# SYMTAB-LLVM-NEXT: }138# SYMTAB-LLVM-NEXT: ]139 140## In this case we have a function symbol with an invalid section index.141## Document what we dump.142 143# RUN: yaml2obj --docnum=1 %s -DSEC1="<none>" -DSEC1INDEX=0xFF -o %t01.broken.sym144# RUN: llvm-readelf --stack-sizes %t01.broken.sym 2>&1 | \145# RUN: FileCheck %s -DFILE=%t01.broken.sym --check-prefix=SYM-GNU --implicit-check-not=warning:146# RUN: llvm-readobj --stack-sizes %t01.broken.sym 2>&1 | \147# RUN: FileCheck %s -DFILE=%t01.broken.sym --check-prefix=SYM-LLVM --implicit-check-not=warning:148 149# SYM-GNU: Stack Sizes:150# SYM-GNU-NEXT: Size Functions151# SYM-GNU-NEXT: warning: '[[FILE]]': unable to get address of symbol 'separate_text_section_baz': invalid section index: 255152# SYM-GNU-NEXT: warning: '[[FILE]]': could not identify function symbol for stack size entry in SHT_PROGBITS section with index 3153# SYM-GNU-NEXT: 16 ?154# SYM-GNU-NEXT: 32 ?155# SYM-GNU-NEXT: warning: '[[FILE]]': cannot identify the section for relocation symbol 'separate_text_section_baz': invalid section index: 255156# SYM-GNU-NEXT: warning: '[[FILE]]': could not identify function symbol for stack size entry in SHT_PROGBITS section with index 4157# SYM-GNU-NEXT: 8 ?158 159# SYM-LLVM: StackSizes [160# SYM-LLVM-NEXT: warning: '[[FILE]]': unable to get address of symbol 'separate_text_section_baz': invalid section index: 255161# SYM-LLVM-NEXT: warning: '[[FILE]]': could not identify function symbol for stack size entry in SHT_PROGBITS section with index 3162# SYM-LLVM-NEXT: Entry {163# SYM-LLVM-NEXT: Functions: [?]164# SYM-LLVM-NEXT: Size: 0x10165# SYM-LLVM-NEXT: }166# SYM-LLVM-NEXT: Entry {167# SYM-LLVM-NEXT: Functions: [?]168# SYM-LLVM-NEXT: Size: 0x20169# SYM-LLVM-NEXT: }170# SYM-LLVM-NEXT: warning: '[[FILE]]': cannot identify the section for relocation symbol 'separate_text_section_baz': invalid section index: 255171# SYM-LLVM-NEXT: warning: '[[FILE]]': could not identify function symbol for stack size entry in SHT_PROGBITS section with index 4172# SYM-LLVM-NEXT: Entry {173# SYM-LLVM-NEXT: Functions: [?]174# SYM-LLVM-NEXT: Size: 0x8175# SYM-LLVM-NEXT: }176# SYM-LLVM-NEXT: ]177 178## Check that we correctly report the stack sizes in an executable (non-relocatable)179## object file. This also shows that the sh_link field is ignored in this situation180## without warning.181 182# RUN: yaml2obj --docnum=2 %s -o %t02183# RUN: llvm-readelf --stack-sizes %t02 2>&1 \184# RUN: | FileCheck %s --check-prefix=EXEC-GNU --strict-whitespace \185# RUN: --match-full-lines --implicit-check-not=warning:186# RUN: llvm-readobj --stack-sizes %t02 2>&1 \187# RUN: | FileCheck %s --check-prefix=EXEC-LLVM --implicit-check-not=warning:188 189# EXEC-GNU: Size Functions190# EXEC-GNU-NEXT: 16 other191# EXEC-GNU-NEXT: 32 other_end192# EXEC-GNU-NEXT: 48 bar193# EXEC-GNU-NOT:{{.}}194 195# EXEC-LLVM: StackSizes [196# EXEC-LLVM-NEXT: Entry {197# EXEC-LLVM-NEXT: Functions: [other]198# EXEC-LLVM-NEXT: Size: 0x10199# EXEC-LLVM-NEXT: }200# EXEC-LLVM-NEXT: Entry {201# EXEC-LLVM-NEXT: Functions: [other_end]202# EXEC-LLVM-NEXT: Size: 0x20203# EXEC-LLVM-NEXT: }204# EXEC-LLVM-NEXT: Entry {205# EXEC-LLVM-NEXT: Functions: [bar]206# EXEC-LLVM-NEXT: Size: 0x30207# EXEC-LLVM-NEXT: }208# EXEC-LLVM-NEXT: ]209 210--- !ELF211FileHeader:212 Class: ELFCLASS64213 Data: ELFDATA2LSB214 Type: ET_EXEC215Sections:216 - Name: .text217 Type: SHT_PROGBITS218 Flags: [SHF_ALLOC]219 Size: 16220 - Name: .text2221 Type: SHT_PROGBITS222 Flags: [SHF_ALLOC]223 Size: 16224 - Name: .stack_sizes225 Type: SHT_PROGBITS226 Entries:227 - Address: 0x0228 Size: 0x10229 - Address: 0x10230 Size: 0x20231 - Address: 0x20232 Size: 0x30233 Link: .text2234Symbols:235 ## Undefined symbols are ignored.236 - Name: undefined237 Type: STT_FUNC238 Binding: STB_GLOBAL239 ## sh_link of .stack_sizes is ignored for non-reloctable objects.240 - Name: other241 Section: .text242 Value: 0243 Type: STT_FUNC244 Binding: STB_GLOBAL245 - Name: other_end246 Section: .text247 Value: 0x10248 Type: STT_FUNC249 Binding: STB_GLOBAL250 - Name: bar251 Section: .text2252 Value: 0x20253 Type: STT_FUNC254 Binding: STB_GLOBAL255 256## Check that we report a warning when we find relocations whose offsets point outside257## of the .stack_sizes section.258 259# RUN: yaml2obj --docnum=3 %s -o %t03260# RUN: llvm-readelf --stack-sizes %t03 2>&1 | FileCheck %s --check-prefix=SHORT-GNU -DFILE=%t03261# RUN: llvm-readobj --stack-sizes %t03 2>&1 | FileCheck %s --check-prefix=SHORT-LLVM -DFILE=%t03262 263# SHORT-GNU: Stack Sizes:264# SHORT-GNU-NEXT: Size Functions265# SHORT-GNU-NEXT: 8 foo266# SHORT-GNU-NEXT: warning: '[[FILE]]': found invalid relocation offset (0x1) into SHT_PROGBITS section with index 2 while trying to extract a stack size entry267# SHORT-GNU-NEXT: 8 foo268 269# SHORT-LLVM: StackSizes [270# SHORT-LLVM-NEXT: Entry {271# SHORT-LLVM-NEXT: Functions: [foo]272# SHORT-LLVM-NEXT: Size: 0x8273# SHORT-LLVM-NEXT: }274# SHORT-LLVM-NEXT: warning: '[[FILE]]': found invalid relocation offset (0x1) into SHT_PROGBITS section with index 2 while trying to extract a stack size entry275# SHORT-LLVM-NEXT: Entry {276# SHORT-LLVM-NEXT: Functions: [foo]277# SHORT-LLVM-NEXT: Size: 0x8278# SHORT-LLVM-NEXT: }279# SHORT-LLVM-NEXT: ]280 281--- !ELF282FileHeader:283 Class: ELFCLASS64284 Data: ELFDATA2LSB285 Type: ET_REL286 Machine: EM_X86_64287Sections:288 - Name: .text289 Type: SHT_PROGBITS290 Flags: [SHF_ALLOC]291 Size: 16292 - Name: .stack_sizes293 Type: SHT_PROGBITS294 Link: .text295 Entries:296 - Size: 0x8297 - Name: .rela.stack_sizes298 Type: SHT_RELA299 Info: .stack_sizes300 Relocations:301 - Offset: 0x0302 Symbol: foo303 Type: R_X86_64_64304 - Offset: 0x1305 Symbol: foo306 Type: R_X86_64_64307 - Offset: 0x1308 Symbol: foo309 Type: R_X86_64_64310 - Offset: 0x0311 Symbol: foo312 Type: R_X86_64_64313Symbols:314 - Name: foo315 Section: .text316 Type: STT_FUNC317 Binding: STB_GLOBAL318 319## Check that we warn about a function symbol that is not in the section320## that is referenced by the stack sizes section's sh_link, for relocatable321## output.322 323# RUN: yaml2obj --docnum=4 %s -o %t04324# RUN: llvm-readelf --stack-sizes %t04 2> %t04-gnu.err | FileCheck %s --check-prefix=WRONGSECTION-GNU325# RUN: FileCheck %s < %t04-gnu.err --check-prefix=WRONGSECTION-ERR -DFILE=%t04326# RUN: llvm-readobj --stack-sizes %t04 2> %t04-llvm.err | FileCheck %s --check-prefix=WRONGSECTION-LLVM327# RUN: FileCheck %s < %t04-llvm.err --check-prefix=WRONGSECTION-ERR -DFILE=%t04328 329# RUN: llvm-readelf --stack-sizes --demangle %t04 2>&1 | FileCheck %s --check-prefix=WRONGSECTION-DEMANGLE-ERR -DFILE=%t04330# RUN: llvm-readobj --stack-sizes --demangle %t04 2>&1 | FileCheck %s --check-prefix=WRONGSECTION-DEMANGLE-ERR -DFILE=%t04331 332# WRONGSECTION-GNU: Size Functions333# WRONGSECTION-GNU-NEXT: 8 _Z3foof334 335# WRONGSECTION-LLVM: StackSizes [336# WRONGSECTION-LLVM-NEXT: Entry {337# WRONGSECTION-LLVM-NEXT: Functions: [_Z3foof]338# WRONGSECTION-LLVM-NEXT: Size: 0x8339# WRONGSECTION-LLVM-NEXT: }340# WRONGSECTION-LLVM-NEXT: ]341 342# WRONGSECTION-ERR: warning: '[[FILE]]': relocation symbol '_Z3foof' is not in the expected section343# WRONGSECTION-DEMANGLE-ERR: warning: '[[FILE]]': relocation symbol 'foo(float)' is not in the expected section344 345--- !ELF346FileHeader:347 Class: ELFCLASS64348 Data: ELFDATA2LSB349 Type: ET_REL350 Machine: EM_X86_64351Sections:352 - Name: .text353 Type: SHT_PROGBITS354 Size: 8355 - Name: .text2356 Type: SHT_PROGBITS357 Size: 8358 Flags: [SHF_ALLOC]359 - Name: .stack_sizes360 Type: SHT_PROGBITS361 Entries:362 - Size: 0x8363 Link: .text2364 - Name: .rela.stack_sizes365 Type: SHT_RELA366 Info: .stack_sizes367 Relocations:368 - Offset: 0369 Symbol: _Z3foof370 Type: R_X86_64_64371Symbols:372 - Name: _Z3foof373 Section: .text374 Type: STT_FUNC375 Binding: STB_GLOBAL376 377## Check that we report a warning when a stack sizes section ends with an incomplete stack size entry.378 379# RUN: yaml2obj --docnum=5 %s -o %t05380# RUN: llvm-readelf --stack-sizes %t05 2>&1 | \381# RUN: FileCheck %s --check-prefix=SUDDENEND-GNU -DFILE=%t05382# RUN: llvm-readobj --stack-sizes %t05 2>&1 | \383# RUN: FileCheck %s --check-prefix=SUDDENEND-LLVM -DFILE=%t05384 385# SUDDENEND-GNU: Stack Sizes:386# SUDDENEND-GNU-NEXT: Size Functions387# SUDDENEND-GNU-NEXT: 8 foo388# SUDDENEND-GNU-NEXT: warning: '[[FILE]]': SHT_PROGBITS section with index 2 ended while trying to extract a stack size entry389# SUDDENEND-GNU-NEXT: 8 foo390# SUDDENEND-GNU-NEXT: warning: '[[FILE]]': SHT_PROGBITS section with index 3 ended while trying to extract a stack size entry391 392# SUDDENEND-LLVM: StackSizes [393# SUDDENEND-LLVM-NEXT: Entry {394# SUDDENEND-LLVM-NEXT: Functions: [foo]395# SUDDENEND-LLVM-NEXT: Size: 0x8396# SUDDENEND-LLVM-NEXT: }397# SUDDENEND-LLVM-NEXT: warning: '[[FILE]]': SHT_PROGBITS section with index 2 ended while trying to extract a stack size entry398# SUDDENEND-LLVM-NEXT: Entry {399# SUDDENEND-LLVM-NEXT: Functions: [foo]400# SUDDENEND-LLVM-NEXT: Size: 0x8401# SUDDENEND-LLVM-NEXT: }402# SUDDENEND-LLVM-NEXT: warning: '[[FILE]]': SHT_PROGBITS section with index 3 ended while trying to extract a stack size entry403# SUDDENEND-LLVM-NEXT: ]404 405--- !ELF406FileHeader:407 Class: ELFCLASS64408 Data: ELFDATA2LSB409 Type: ET_EXEC410 Machine: EM_X86_64411Sections:412 - Name: .text413 Type: SHT_PROGBITS414 - Name: .stack_sizes415 Type: SHT_PROGBITS416 Link: .text417 Entries:418 - Size: 0x8419 - Size: 0x10420## 0x11 == the normal size minus 1.421 ShSize: 0x11422 - Name: .stack_sizes (1)423 Type: SHT_PROGBITS424 Link: .text425 Entries:426 - Size: 0x8427 - Size: 0x10428 ShSize: 0x11429Symbols:430 - Name: foo431 Section: .text432 Type: STT_FUNC433 434## Check that we report an invalid stack size, which is represented by a ULEB that435## ends in a byte with the high bit set.436 437# RUN: yaml2obj --docnum=6 %s -o %t06438# RUN: llvm-readelf --stack-sizes %t06 2>&1 | \439# RUN: FileCheck %s --check-prefix=BADSIZE -DFILE=%t06 --implicit-check-not=warning:440# RUN: llvm-readobj --stack-sizes %t06 2>&1 | \441# RUN: FileCheck %s --check-prefix=BADSIZE -DFILE=%t06 --implicit-check-not=warning:442 443# BADSIZE: warning: '[[FILE]]': could not extract a valid stack size from SHT_PROGBITS section with index 2: unable to decode LEB128 at offset 0x00000008: malformed uleb128, extends past end444# BADSIZE: warning: '[[FILE]]': could not extract a valid stack size from SHT_PROGBITS section with index 3: unable to decode LEB128 at offset 0x00000008: malformed uleb128, extends past end445 446--- !ELF447FileHeader:448 Class: ELFCLASS64449 Data: ELFDATA2LSB450 Type: ET_EXEC451Sections:452 - Name: .text453 Type: SHT_PROGBITS454 Flags: [SHF_ALLOC]455 Size: 16456 - Name: .stack_sizes457 Type: SHT_PROGBITS458 Content: "100000000000000080"459 Link: .text460 - Name: .stack_sizes (1)461 Type: SHT_PROGBITS462 Content: "100000000000000080"463 Link: .text464Symbols:465 - Name: foo466 Section: .text467 Value: 0x10468 Type: STT_FUNC469 Binding: STB_GLOBAL470 471## Check that we report a warning when a relocation symbol does not belong to a472## valid section or when it has an invalid index. We expect a stack size entry473## with an unknown symbol in the output.474 475# RUN: yaml2obj --docnum=7 %s -o %t07476# RUN: llvm-readelf --stack-sizes %t07 2>&1 | \477# RUN: FileCheck %s -DFILE=%t07 --check-prefix=BADSECTION-OUT-GNU --implicit-check-not=warning:478# RUN: llvm-readobj --stack-sizes %t07 2>&1 | \479# RUN: FileCheck %s -DFILE=%t07 --check-prefix=BADSECTION-OUT-LLVM --implicit-check-not=warning:480 481# BADSECTION-OUT-GNU: Stack Sizes:482# BADSECTION-OUT-GNU-NEXT: Size Functions483# BADSECTION-OUT-GNU-NEXT: warning: '[[FILE]]': cannot identify the section for relocation symbol '_Z3foof': invalid section index: 10484# BADSECTION-OUT-GNU-NEXT: warning: '[[FILE]]': unable to get address of symbol '_Z3foof': invalid section index: 10485# BADSECTION-OUT-GNU-NEXT: warning: '[[FILE]]': could not identify function symbol for stack size entry in SHT_PROGBITS section with index 2486# BADSECTION-OUT-GNU-NEXT: 8 ?487# BADSECTION-OUT-GNU-NEXT: warning: '[[FILE]]': unable to get the target of relocation with index 1 in SHT_RELA section with index 3: unable to read an entry with index 255 from SHT_SYMTAB section with index 4: can't read an entry at 0x17e8: it goes past the end of the section (0x30)488# BADSECTION-OUT-GNU-NEXT: 22 ?489# BADSECTION-OUT-GNU-NEXT: warning: '[[FILE]]': unable to get the target of relocation with index 2 in SHT_RELA section with index 3: unable to read an entry with index 255 from SHT_SYMTAB section with index 4: can't read an entry at 0x17e8: it goes past the end of the section (0x30)490# BADSECTION-OUT-GNU-NEXT: 36 ?491 492# BADSECTION-OUT-LLVM: StackSizes [493# BADSECTION-OUT-LLVM-NEXT: warning: '[[FILE]]': cannot identify the section for relocation symbol '_Z3foof': invalid section index: 10494# BADSECTION-OUT-LLVM-NEXT: warning: '[[FILE]]': unable to get address of symbol '_Z3foof': invalid section index: 10495# BADSECTION-OUT-LLVM-NEXT: warning: '[[FILE]]': could not identify function symbol for stack size entry in SHT_PROGBITS section with index 2496# BADSECTION-OUT-LLVM-NEXT: Entry {497# BADSECTION-OUT-LLVM-NEXT: Functions: [?]498# BADSECTION-OUT-LLVM-NEXT: Size: 0x8499# BADSECTION-OUT-LLVM-NEXT: }500# BADSECTION-OUT-LLVM-NEXT: warning: '[[FILE]]': unable to get the target of relocation with index 1 in SHT_RELA section with index 3: unable to read an entry with index 255 from SHT_SYMTAB section with index 4: can't read an entry at 0x17e8: it goes past the end of the section (0x30)501# BADSECTION-OUT-LLVM-NEXT: Entry {502# BADSECTION-OUT-LLVM-NEXT: Functions: [?]503# BADSECTION-OUT-LLVM-NEXT: Size: 0x16504# BADSECTION-OUT-LLVM-NEXT: }505# BADSECTION-OUT-LLVM-NEXT: warning: '[[FILE]]': unable to get the target of relocation with index 2 in SHT_RELA section with index 3: unable to read an entry with index 255 from SHT_SYMTAB section with index 4: can't read an entry at 0x17e8: it goes past the end of the section (0x30)506# BADSECTION-OUT-LLVM-NEXT: Entry {507# BADSECTION-OUT-LLVM-NEXT: Functions: [?]508# BADSECTION-OUT-LLVM-NEXT: Size: 0x24509# BADSECTION-OUT-LLVM-NEXT: }510# BADSECTION-OUT-LLVM-NEXT: ]511 512# RUN: llvm-readelf --stack-sizes --demangle %t07 2>&1 | FileCheck %s --check-prefix=BADSECTION-DEMANGLE-ERR -DFILE=%t07513# RUN: llvm-readobj --stack-sizes --demangle %t07 2>&1 | FileCheck %s --check-prefix=BADSECTION-DEMANGLE-ERR -DFILE=%t07514 515# BADSECTION-DEMANGLE-ERR: warning: '[[FILE]]': cannot identify the section for relocation symbol 'foo(float)'516 517--- !ELF518FileHeader:519 Class: ELFCLASS64520 Data: ELFDATA2LSB521 Type: ET_REL522 Machine: EM_X86_64523Sections:524 - Name: .text525 Type: SHT_PROGBITS526 Size: 16527 - Name: .stack_sizes528 Type: SHT_PROGBITS529 Link: .text530 Entries:531 - Size: 0x8532 - Size: 0x16533 - Size: 0x24534 - Name: .rela.stack_sizes535 Type: SHT_RELA536 Info: .stack_sizes537 Relocations:538 - Offset: 0539 Symbol: _Z3foof540 Type: R_X86_64_64541 - Offset: 9542## An invalid symbol index.543 Symbol: 0xff544 Type: R_X86_64_64545## One more invalid symbol index with the same symbol value (0xff).546 - Offset: 0x12547 Symbol: 0xff548 Type: R_X86_64_64549Symbols:550 - Name: _Z3foof551## An invalid section index.552 Index: 10553 Type: STT_FUNC554 Binding: STB_GLOBAL555 556## Check that we report a warning when a stack sizes section does not come with557## a corresponding relocation section.558 559# RUN: yaml2obj --docnum=8 %s -o %t08560# RUN: llvm-readelf --stack-sizes %t08 2> %t08-gnu.err | FileCheck %s --check-prefix=NORELOCSECTION-OUT-GNU561# RUN: FileCheck %s < %t08-gnu.err --check-prefix=NORELOCSECTION-ERR -DFILE=%t08562# RUN: llvm-readobj --stack-sizes %t08 2> %t08-llvm.err | FileCheck %s --check-prefix=NORELOCSECTION-OUT-LLVM563# RUN: FileCheck %s < %t08-llvm.err --check-prefix=NORELOCSECTION-ERR -DFILE=%t08564 565# NORELOCSECTION-OUT-GNU: Size Functions566# NORELOCSECTION-OUT-GNU-NOT: {{.}}567 568# NORELOCSECTION-OUT-LLVM: StackSizes [569# NORELOCSECTION-OUT-LLVM-NEXT: ]570 571# NORELOCSECTION-ERR: warning: '[[FILE]]': .stack_sizes (SHT_PROGBITS section with index 2) does not have a corresponding relocation section572 573--- !ELF574FileHeader:575 Class: ELFCLASS64576 Data: ELFDATA2LSB577 Type: ET_REL578Sections:579 - Name: .text580 Type: SHT_PROGBITS581 Size: 8582 - Name: .stack_sizes583 Type: SHT_PROGBITS584 Link: .text585 Entries:586 - Size: 0x1587 588## Check that we handle multiple object files, separately and when they589## are in an archive. This also checks whether we have blank lines between the590## tables.591 592# RUN: llvm-ar rc %t1.a %t01 %t02593# RUN: llvm-readelf --stack-sizes %t01 %t02 \594# RUN: | FileCheck %s --check-prefixes=MULTIPLE-GNU,OBJECT -DFILE1=%t01 -DFILE2=%t02595# RUN: llvm-readelf --stack-sizes %t1.a \596# RUN: | FileCheck %s --check-prefixes=MULTIPLE-GNU,ARCHIVE --strict-whitespace\597# RUN: --match-full-lines -DFILE=%t1.a598# RUN: llvm-readobj --stack-sizes %t01 %t02 \599# RUN: | FileCheck %s --check-prefixes=MULTIPLE-LLVM,OBJECT -DFILE1=%t01 -DFILE2=%t02600# RUN: llvm-readobj --stack-sizes %t1.a \601# RUN: | FileCheck %s --check-prefixes=MULTIPLE-LLVM,ARCHIVE -DFILE=%t1.a602 603# OBJECT:File: [[FILE1]]604# ARCHIVE:File: [[FILE]]({{.*01}})605 606# MULTIPLE-GNU:Stack Sizes:607# MULTIPLE-GNU-NEXT: Size Functions608# MULTIPLE-GNU-NEXT: 16 referenced_by_symbol_foo609# MULTIPLE-GNU-NEXT: 32 referenced_via_section_bar610# MULTIPLE-GNU-NEXT: 8 separate_text_section_baz611# MULTIPLE-GNU-EMPTY:612 613# MULTIPLE-LLVM: StackSizes [614# MULTIPLE-LLVM-NEXT: Entry {615# MULTIPLE-LLVM-NEXT: Functions: [referenced_by_symbol_foo]616# MULTIPLE-LLVM-NEXT: Size: 0x10617# MULTIPLE-LLVM-NEXT: }618# MULTIPLE-LLVM-NEXT: Entry {619# MULTIPLE-LLVM-NEXT: Functions: [referenced_via_section_bar]620# MULTIPLE-LLVM-NEXT: Size: 0x20621# MULTIPLE-LLVM-NEXT: }622# MULTIPLE-LLVM-NEXT: Entry {623# MULTIPLE-LLVM-NEXT: Functions: [separate_text_section_baz]624# MULTIPLE-LLVM-NEXT: Size: 0x8625# MULTIPLE-LLVM-NEXT: }626# MULTIPLE-LLVM-NEXT: ]627 628# OBJECT:File: [[FILE2]]629# ARCHIVE:File: [[FILE]]({{.*02}})630 631# MULTIPLE-GNU-EMPTY:632# MULTIPLE-GNU-NEXT:Stack Sizes:633# MULTIPLE-GNU-NEXT: Size Functions634# MULTIPLE-GNU-NEXT: 16 other635# MULTIPLE-GNU-NEXT: 32 other_end636# MULTIPLE-GNU-NEXT: 48 bar637 638# MULTIPLE-LLVM: StackSizes [639# MULTIPLE-LLVM-NEXT: Entry {640# MULTIPLE-LLVM-NEXT: Functions: [other]641# MULTIPLE-LLVM-NEXT: Size: 0x10642# MULTIPLE-LLVM-NEXT: }643# MULTIPLE-LLVM-NEXT: Entry {644# MULTIPLE-LLVM-NEXT: Functions: [other_end]645# MULTIPLE-LLVM-NEXT: Size: 0x20646# MULTIPLE-LLVM-NEXT: }647# MULTIPLE-LLVM-NEXT: Entry {648# MULTIPLE-LLVM-NEXT: Functions: [bar]649# MULTIPLE-LLVM-NEXT: Size: 0x30650# MULTIPLE-LLVM-NEXT: }651# MULTIPLE-LLVM-NEXT: ]652 653## Check that we do not consider symbols that are not function symbols, even though654## a relocation references them. 655 656# RUN: yaml2obj --docnum=9 %s -o %t14657# RUN: llvm-readelf --stack-sizes %t14 2> %t14-gnu.err | FileCheck %s --check-prefix=NONFUNCTIONSYM-GNU658# RUN: FileCheck %s < %t14-gnu.err --check-prefix=NONFUNCTIONSYM-ERR -DFILE=%t14659# RUN: llvm-readobj --stack-sizes %t14 2> %t14-llvm.err | FileCheck %s --check-prefix=NONFUNCTIONSYM-LLVM660# RUN: FileCheck %s < %t14-llvm.err --check-prefix=NONFUNCTIONSYM-ERR -DFILE=%t14661 662# NONFUNCTIONSYM-GNU: Stack Sizes:663# NONFUNCTIONSYM-GNU: 0 ?664 665# NONFUNCTIONSYM-LLVM: StackSizes [666# NONFUNCTIONSYM-LLVM-NEXT: Entry {667# NONFUNCTIONSYM-LLVM-NEXT: Functions: [?]668# NONFUNCTIONSYM-LLVM-NEXT: Size: 0x0669# NONFUNCTIONSYM-LLVM-NEXT: }670# NONFUNCTIONSYM-LLVM-NEXT: ]671 672# NONFUNCTIONSYM-ERR: warning: '[[FILE]]': could not identify function symbol for stack size entry in SHT_PROGBITS section with index 2673 674--- !ELF675FileHeader:676 Class: ELFCLASS64677 Data: ELFDATA2LSB678 Type: ET_REL679 Machine: EM_X86_64680Sections:681 - Name: .text682 Type: SHT_PROGBITS683 Size: 16684 - Name: .stack_sizes685 Type: SHT_PROGBITS686 Entries:687 - Size: 0688 Link: .text689 - Name: .rela.stack_sizes690 Type: SHT_RELA691 Info: .stack_sizes692 Relocations:693 - Offset: 0694 Symbol: foo695 Type: R_X86_64_64696Symbols:697 - Name: foo698 Section: .text699 Type: STT_OBJECT700 Binding: STB_GLOBAL701 702## Check that we report a warning when we find an unsupported relocation703## in the section that contains the stack size entries' relocations.704 705# RUN: yaml2obj --docnum=10 %s -o %t15706# RUN: llvm-readelf --stack-sizes %t15 2>&1 | FileCheck %s --check-prefix=UNSUPPRELOC-GNU -DFILE=%t15707# RUN: llvm-readobj --stack-sizes %t15 2>&1 | FileCheck %s --check-prefix=UNSUPPRELOC-LLVM -DFILE=%t15708 709# UNSUPPRELOC-GNU: Stack Sizes:710# UNSUPPRELOC-GNU-NEXT: Size Functions711# UNSUPPRELOC-GNU-NEXT: warning: '[[FILE]]': SHT_RELA section with index 3 contains an unsupported relocation with index 0: R_X86_64_RELATIVE712# UNSUPPRELOC-GNU-NEXT: 0 foo713# UNSUPPRELOC-GNU-NEXT: warning: '[[FILE]]': SHT_RELA section with index 3 contains an unsupported relocation with index 2: R_X86_64_RELATIVE714 715# UNSUPPRELOC-LLVM: StackSizes [716# UNSUPPRELOC-LLVM-NEXT: warning: '[[FILE]]': SHT_RELA section with index 3 contains an unsupported relocation with index 0: R_X86_64_RELATIVE717# UNSUPPRELOC-LLVM-NEXT: Entry {718# UNSUPPRELOC-LLVM-NEXT: Functions: [foo]719# UNSUPPRELOC-LLVM-NEXT: Size: 0x0720# UNSUPPRELOC-LLVM-NEXT: }721# UNSUPPRELOC-LLVM-NEXT: warning: '[[FILE]]': SHT_RELA section with index 3 contains an unsupported relocation with index 2: R_X86_64_RELATIVE722# UNSUPPRELOC-LLVM-NEXT: ]723 724--- !ELF725FileHeader:726 Class: ELFCLASS64727 Data: ELFDATA2LSB728 Type: ET_REL729 Machine: EM_X86_64730Sections:731 - Name: .text732 Type: SHT_PROGBITS733 Size: 8734 - Name: .stack_sizes735 Type: SHT_PROGBITS736 Link: .text737 Entries:738 - Size: 0739 - Name: .rela.stack_sizes740 Type: SHT_RELA741 Info: .stack_sizes742 Relocations:743 - Offset: 0744 Symbol: foo745 Type: R_X86_64_RELATIVE746 - Offset: 0747 Symbol: foo748 Type: R_X86_64_64749 - Offset: 0750 Symbol: foo751 Type: R_X86_64_RELATIVE752Symbols:753 - Name: foo754 Section: .text755 Type: STT_FUNC756 Binding: STB_GLOBAL757 758## Check that warning messages in archives do not impact other members. In the following759## test, the first archive member generates a warning and we make sure all the information760## is still dumped.761 762# RUN: llvm-ar rc %t2.a %t04 %t01763# RUN: llvm-readelf --stack-sizes %t2.a 2>&1 | FileCheck %s --check-prefix=ARCHIVEWARN-GNU \764# RUN: -DFILE=%t2.a --strict-whitespace --match-full-lines765# RUN: llvm-readobj --stack-sizes %t2.a 2>&1 | FileCheck %s --check-prefix=ARCHIVEWARN-LLVM -DFILE=%t2.a766 767# ARCHIVEWARN-GNU:File: [[FILE]]({{.*04}})768# ARCHIVEWARN-GNU:Stack Sizes:769# ARCHIVEWARN-GNU-NEXT: Size Functions770# ARCHIVEWARN-GNU:{{.*}}: warning: '{{.*04}}': relocation symbol '_Z3foof' is not in the expected section771# ARCHIVEWARN-GNU: 8 _Z3foof772# ARCHIVEWARN-GNU:File: [[FILE]]({{.*01}})773# ARCHIVEWARN-GNU:Stack Sizes:774# ARCHIVEWARN-GNU-NEXT: Size Functions775# ARCHIVEWARN-GNU-NEXT: 16 referenced_by_symbol_foo776# ARCHIVEWARN-GNU-NEXT: 32 referenced_via_section_bar777# ARCHIVEWARN-GNU-NEXT: 8 separate_text_section_baz778# ARCHIVEWARN-GNU-NOT:{{.}}779 780 781# ARCHIVEWARN-LLVM: File: [[FILE]]({{.*04}})782# ARCHIVEWARN-LLVM: StackSizes [783# ARCHIVEWARN-LLVM: warning: '{{.*04}}': relocation symbol '_Z3foof' is not in the expected section784# ARCHIVEWARN-LLVM-NEXT: Entry {785# ARCHIVEWARN-LLVM-NEXT: Functions: [_Z3foof]786# ARCHIVEWARN-LLVM-NEXT: Size: 0x8787# ARCHIVEWARN-LLVM-NEXT: }788# ARCHIVEWARN-LLVM-NEXT: ]789# ARCHIVEWARN-LLVM: File: [[FILE]]({{.*01}})790# ARCHIVEWARN-LLVM: StackSizes [791# ARCHIVEWARN-LLVM-NEXT: Entry {792# ARCHIVEWARN-LLVM-NEXT: Functions: [referenced_by_symbol_foo]793# ARCHIVEWARN-LLVM-NEXT: Size: 0x10794# ARCHIVEWARN-LLVM-NEXT: }795# ARCHIVEWARN-LLVM-NEXT: Entry {796# ARCHIVEWARN-LLVM-NEXT: Functions: [referenced_via_section_bar]797# ARCHIVEWARN-LLVM-NEXT: Size: 0x20798# ARCHIVEWARN-LLVM-NEXT: }799# ARCHIVEWARN-LLVM-NEXT: Entry {800# ARCHIVEWARN-LLVM-NEXT: Functions: [separate_text_section_baz]801# ARCHIVEWARN-LLVM-NEXT: Size: 0x8802# ARCHIVEWARN-LLVM-NEXT: }803# ARCHIVEWARN-LLVM-NEXT: ]804 805## Check that we demangle function names when requested.806 807# RUN: yaml2obj --docnum=11 %s -o %t16808# RUN: llvm-readelf --stack-sizes --demangle %t16 | FileCheck %s --check-prefix=DEMANGLE-GNU809# RUN: llvm-readobj --stack-sizes --demangle %t16 | FileCheck %s --check-prefix=DEMANGLE-LLVM810 811# DEMANGLE-GNU: 16 foo(float)812# DEMANGLE-LLVM: Functions: [foo(float)]813 814--- !ELF815FileHeader:816 Class: ELFCLASS64817 Data: ELFDATA2LSB818 Type: ET_EXEC819Sections:820 - Name: .text821 Type: SHT_PROGBITS822 Flags: [SHF_ALLOC]823 Size: 16824 - Name: .stack_sizes825 Type: SHT_PROGBITS826 Entries:827 - Address: 0x10828 Size: 0x10829 Link: .text830Symbols:831 - Name: _Z3foof832 Section: .text833 Value: 0x10834 Type: STT_FUNC835 Binding: STB_GLOBAL836 837## Check that we report a warning when we are unable to resolve a relocation for a given ELF architecture.838## Here we have a 64-bit relocation used in a 32-bit object.839 840# RUN: yaml2obj --docnum=12 %s -o %t17841# RUN: llvm-readelf --stack-sizes %t17 2>&1 | FileCheck %s -DFILE=%t17 --check-prefix=UNSUPPRELOC2842# RUN: llvm-readobj --stack-sizes %t17 2>&1 | FileCheck %s -DFILE=%t17 --check-prefix=UNSUPPRELOC2843 844# UNSUPPRELOC2: warning: '[[FILE]]': SHT_RELA section with index 2 contains an unsupported relocation with index 0: R_X86_64_64845 846--- !ELF847FileHeader:848 Class: ELFCLASS32849 Data: ELFDATA2MSB850 Type: ET_REL851 Machine: EM_X86_64852Sections:853 - Name: .stack_sizes854 Type: SHT_PROGBITS855 Content: "00"856 - Name: .rela.stack_sizes857 Type: SHT_RELA858 Info: .stack_sizes859 Relocations:860 - Offset: 0861 Type: R_X86_64_64862 863## Check we report a warning when dumping stack sizes if the relocated section864## identified by the sh_info field is invalid. Here the sh_info value is larger than865## the number of sections.866 867# RUN: yaml2obj --docnum=13 %s -o %t18868# RUN: llvm-readelf --stack-sizes %t18 2>&1 | \869# RUN: FileCheck %s --implicit-check-not="warning:" -DFILE=%t18 --check-prefix=INVALID-TARGET870# RUN: llvm-readobj --stack-sizes %t18 2>&1 | \871# RUN: FileCheck %s --implicit-check-not="warning:" -DFILE=%t18 --check-prefix=INVALID-TARGET872 873# INVALID-TARGET: warning: '[[FILE]]': unable to get stack size map section(s): SHT_RELA section with index 1: failed to get a relocated section: invalid section index: 255874# INVALID-TARGET: SHT_RELA section with index 2: failed to get a relocated section: invalid section index: 255875 876--- !ELF877FileHeader:878 Class: ELFCLASS32879 Data: ELFDATA2MSB880 Type: ET_REL881Sections:882 - Name: .rela.stack_sizes883 Type: SHT_RELA884 Link: 0885 Info: 0xFF886 Relocations: []887 - Name: .rela.stack_sizes (1)888 Type: SHT_RELA889 Link: 0890 Info: 0xFF891 Relocations: []892 893## Check that that we see multiple symbols output in cases when multiple symbols894## share the same stack size entry, for example when use of ICF means two functions895## are represented by the same code.896 897# RUN: yaml2obj --docnum=14 %s -o %t19898# RUN: llvm-readelf --stack-sizes %t19 2>&1 \899# RUN: | FileCheck %s --check-prefix=MULTIPLE-SYMBOLS-GNU900# RUN: llvm-readobj --stack-sizes %t19 2>&1 \901# RUN: | FileCheck %s --check-prefix=MULTIPLE-SYMBOLS-LLVM902 903# MULTIPLE-SYMBOLS-GNU: Size Functions904# MULTIPLE-SYMBOLS-GNU: 16 foo, bar905# MULTIPLE-SYMBOLS-GNU-NOT:{{.}}906 907# MULTIPLE-SYMBOLS-LLVM: StackSizes [908# MULTIPLE-SYMBOLS-LLVM-NEXT: Entry {909# MULTIPLE-SYMBOLS-LLVM-NEXT: Functions: [foo, bar]910# MULTIPLE-SYMBOLS-LLVM-NEXT: Size: 0x10911# MULTIPLE-SYMBOLS-LLVM-NEXT: }912# MULTIPLE-SYMBOLS-LLVM-NEXT: ]913# MULTIPLE-SYMBOLS-LLVM-NOT:{{.}}914 915--- !ELF916FileHeader:917 Class: ELFCLASS64918 Data: ELFDATA2LSB919 Type: ET_EXEC920Sections:921 - Name: .text922 Type: SHT_PROGBITS923 Flags: [SHF_ALLOC]924 Size: 16925 - Name: .stack_sizes926 Type: SHT_PROGBITS927 Entries:928 - Address: 0x0929 Size: 0x10930 Link: .text931Symbols:932 - Name: foo933 Section: .text934 Value: 0x0935 Type: STT_FUNC936 Binding: STB_GLOBAL937 - Name: bar938 Section: .text939 Value: 0x0940 Type: STT_FUNC941 Binding: STB_GLOBAL942