1## Check that we correctly display the contents of the .stack_sizes section 2## in a relocatable object file. 3 4# RUN: yaml2obj --docnum=1 %s -o %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 8 9# RELOC-GNU: Size Functions 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 13# 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: 0x10 19# RELOC-LLVM-NEXT: } 20# RELOC-LLVM-NEXT: Entry { 21# RELOC-LLVM-NEXT: Functions: [referenced_via_section_bar] 22# RELOC-LLVM-NEXT: Size: 0x20 23# RELOC-LLVM-NEXT: } 24# RELOC-LLVM-NEXT: Entry { 25# RELOC-LLVM-NEXT: Functions: [separate_text_section_baz] 26# RELOC-LLVM-NEXT: Size: 0x8 27# RELOC-LLVM-NEXT: } 28# RELOC-LLVM-NEXT: ] 29 30--- !ELF 31FileHeader: 32 Class: ELFCLASS64 33 Data: ELFDATA2LSB 34 Type: ET_REL 35 Machine: EM_X86_64 36Sections: 37 - Name: .text 38 Type: SHT_PROGBITS 39 Flags: [SHF_ALLOC] 40 Size: 16 41 - Name: .text.baz 42 Type: SHT_PROGBITS 43 Flags: [SHF_ALLOC] 44 Size: 16 45 - Name: .stack_sizes 46 Type: SHT_PROGBITS 47 Entries: 48 - Size: 0x10 49 - Size: 0x20 50 Link: .text 51 - Name: '.stack_sizes (1)' 52 Type: SHT_PROGBITS 53 Entries: 54 - Address: 0x20 55 Size: 0x8 56 Link: .text.baz 57 - Name: .rela.stack_sizes 58 Type: SHT_RELA 59 Info: .stack_sizes 60 Relocations: 61## A symbol relative reference. 62 - Offset: 0 63 Symbol: referenced_by_symbol_foo 64 Type: R_X86_64_64 65## A section relative reference. 66 - Offset: 9 67 Addend: 16 68 Symbol: .text 69 Type: R_X86_64_64 70 - Name: '.rela.stack_sizes (1)' 71 Type: SHT_RELA 72 Info: '.stack_sizes (1)' 73 Relocations: 74 - Offset: 0 75 Symbol: separate_text_section_baz 76 Type: R_X86_64_64 77 - Name: .symtab 78 Type: SHT_SYMTAB 79 ShOffset: [[SYMTABOFFSET=<none>]] 80Symbols: 81 - Name: separate_text_section_baz 82 Section: [[SEC1=.text.baz]] 83 Type: STT_FUNC 84 Index: [[SEC1INDEX=<none>]] 85 - Name: .text 86 Section: .text 87 Type: STT_SECTION 88 - Name: referenced_by_symbol_foo 89 Section: .text 90 Type: STT_FUNC 91 Binding: STB_GLOBAL 92 - Name: referenced_via_section_bar 93 Section: .text 94 Value: 0x10 95 Type: STT_FUNC 96 Binding: STB_GLOBAL 97 98## Check that we report a warning when we are unable to read 99## the symbol table when dumping stack sizes. 100 101# RUN: yaml2obj --docnum=1 %s -DSYMTABOFFSET=0xffffeeee -o %t01.broken.symtab 102# 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 Functions 109# 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 3 112# 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 4 117# 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 3 123# SYMTAB-LLVM-NEXT: Entry { 124# SYMTAB-LLVM-NEXT: Functions: [?] 125# SYMTAB-LLVM-NEXT: Size: 0x10 126# 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: 0x20 131# 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 4 134# SYMTAB-LLVM-NEXT: Entry { 135# SYMTAB-LLVM-NEXT: Functions: [?] 136# SYMTAB-LLVM-NEXT: Size: 0x8 137# 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.sym 144# 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 Functions 151# SYM-GNU-NEXT: warning: '[[FILE]]': unable to get address of symbol 'separate_text_section_baz': invalid section index: 255 152# SYM-GNU-NEXT: warning: '[[FILE]]': could not identify function symbol for stack size entry in SHT_PROGBITS section with index 3 153# 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: 255 156# SYM-GNU-NEXT: warning: '[[FILE]]': could not identify function symbol for stack size entry in SHT_PROGBITS section with index 4 157# 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: 255 161# SYM-LLVM-NEXT: warning: '[[FILE]]': could not identify function symbol for stack size entry in SHT_PROGBITS section with index 3 162# SYM-LLVM-NEXT: Entry { 163# SYM-LLVM-NEXT: Functions: [?] 164# SYM-LLVM-NEXT: Size: 0x10 165# SYM-LLVM-NEXT: } 166# SYM-LLVM-NEXT: Entry { 167# SYM-LLVM-NEXT: Functions: [?] 168# SYM-LLVM-NEXT: Size: 0x20 169# SYM-LLVM-NEXT: } 170# SYM-LLVM-NEXT: warning: '[[FILE]]': cannot identify the section for relocation symbol 'separate_text_section_baz': invalid section index: 255 171# SYM-LLVM-NEXT: warning: '[[FILE]]': could not identify function symbol for stack size entry in SHT_PROGBITS section with index 4 172# SYM-LLVM-NEXT: Entry { 173# SYM-LLVM-NEXT: Functions: [?] 174# SYM-LLVM-NEXT: Size: 0x8 175# 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 situation 180## without warning. 181 182# RUN: yaml2obj --docnum=2 %s -o %t02 183# 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 Functions 190# EXEC-GNU-NEXT: 16 other 191# EXEC-GNU-NEXT: 32 other_end 192# EXEC-GNU-NEXT: 48 bar 193# EXEC-GNU-NOT:{{.}} 194 195# EXEC-LLVM: StackSizes [ 196# EXEC-LLVM-NEXT: Entry { 197# EXEC-LLVM-NEXT: Functions: [other] 198# EXEC-LLVM-NEXT: Size: 0x10 199# EXEC-LLVM-NEXT: } 200# EXEC-LLVM-NEXT: Entry { 201# EXEC-LLVM-NEXT: Functions: [other_end] 202# EXEC-LLVM-NEXT: Size: 0x20 203# EXEC-LLVM-NEXT: } 204# EXEC-LLVM-NEXT: Entry { 205# EXEC-LLVM-NEXT: Functions: [bar] 206# EXEC-LLVM-NEXT: Size: 0x30 207# EXEC-LLVM-NEXT: } 208# EXEC-LLVM-NEXT: ] 209 210--- !ELF 211FileHeader: 212 Class: ELFCLASS64 213 Data: ELFDATA2LSB 214 Type: ET_EXEC 215Sections: 216 - Name: .text 217 Type: SHT_PROGBITS 218 Flags: [SHF_ALLOC] 219 Size: 16 220 - Name: .text2 221 Type: SHT_PROGBITS 222 Flags: [SHF_ALLOC] 223 Size: 16 224 - Name: .stack_sizes 225 Type: SHT_PROGBITS 226 Entries: 227 - Address: 0x0 228 Size: 0x10 229 - Address: 0x10 230 Size: 0x20 231 - Address: 0x20 232 Size: 0x30 233 Link: .text2 234Symbols: 235 ## Undefined symbols are ignored. 236 - Name: undefined 237 Type: STT_FUNC 238 Binding: STB_GLOBAL 239 ## sh_link of .stack_sizes is ignored for non-reloctable objects. 240 - Name: other 241 Section: .text 242 Value: 0 243 Type: STT_FUNC 244 Binding: STB_GLOBAL 245 - Name: other_end 246 Section: .text 247 Value: 0x10 248 Type: STT_FUNC 249 Binding: STB_GLOBAL 250 - Name: bar 251 Section: .text2 252 Value: 0x20 253 Type: STT_FUNC 254 Binding: STB_GLOBAL 255 256## Check that we report a warning when we find relocations whose offsets point outside 257## of the .stack_sizes section. 258 259# RUN: yaml2obj --docnum=3 %s -o %t03 260# RUN: llvm-readelf --stack-sizes %t03 2>&1 | FileCheck %s --check-prefix=SHORT-GNU -DFILE=%t03 261# RUN: llvm-readobj --stack-sizes %t03 2>&1 | FileCheck %s --check-prefix=SHORT-LLVM -DFILE=%t03 262 263# SHORT-GNU: Stack Sizes: 264# SHORT-GNU-NEXT: Size Functions 265# SHORT-GNU-NEXT: 8 foo 266# SHORT-GNU-NEXT: warning: '[[FILE]]': found invalid relocation offset (0x1) into SHT_PROGBITS section with index 2 while trying to extract a stack size entry 267# SHORT-GNU-NEXT: 8 foo 268 269# SHORT-LLVM: StackSizes [ 270# SHORT-LLVM-NEXT: Entry { 271# SHORT-LLVM-NEXT: Functions: [foo] 272# SHORT-LLVM-NEXT: Size: 0x8 273# 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 entry 275# SHORT-LLVM-NEXT: Entry { 276# SHORT-LLVM-NEXT: Functions: [foo] 277# SHORT-LLVM-NEXT: Size: 0x8 278# SHORT-LLVM-NEXT: } 279# SHORT-LLVM-NEXT: ] 280 281--- !ELF 282FileHeader: 283 Class: ELFCLASS64 284 Data: ELFDATA2LSB 285 Type: ET_REL 286 Machine: EM_X86_64 287Sections: 288 - Name: .text 289 Type: SHT_PROGBITS 290 Flags: [SHF_ALLOC] 291 Size: 16 292 - Name: .stack_sizes 293 Type: SHT_PROGBITS 294 Link: .text 295 Entries: 296 - Size: 0x8 297 - Name: .rela.stack_sizes 298 Type: SHT_RELA 299 Info: .stack_sizes 300 Relocations: 301 - Offset: 0x0 302 Symbol: foo 303 Type: R_X86_64_64 304 - Offset: 0x1 305 Symbol: foo 306 Type: R_X86_64_64 307 - Offset: 0x1 308 Symbol: foo 309 Type: R_X86_64_64 310 - Offset: 0x0 311 Symbol: foo 312 Type: R_X86_64_64 313Symbols: 314 - Name: foo 315 Section: .text 316 Type: STT_FUNC 317 Binding: STB_GLOBAL 318 319## Check that we warn about a function symbol that is not in the section 320## that is referenced by the stack sizes section's sh_link, for relocatable 321## output. 322 323# RUN: yaml2obj --docnum=4 %s -o %t04 324# RUN: llvm-readelf --stack-sizes %t04 2> %t04-gnu.err | FileCheck %s --check-prefix=WRONGSECTION-GNU 325# RUN: FileCheck %s < %t04-gnu.err --check-prefix=WRONGSECTION-ERR -DFILE=%t04 326# RUN: llvm-readobj --stack-sizes %t04 2> %t04-llvm.err | FileCheck %s --check-prefix=WRONGSECTION-LLVM 327# RUN: FileCheck %s < %t04-llvm.err --check-prefix=WRONGSECTION-ERR -DFILE=%t04 328 329# RUN: llvm-readelf --stack-sizes --demangle %t04 2>&1 | FileCheck %s --check-prefix=WRONGSECTION-DEMANGLE-ERR -DFILE=%t04 330# RUN: llvm-readobj --stack-sizes --demangle %t04 2>&1 | FileCheck %s --check-prefix=WRONGSECTION-DEMANGLE-ERR -DFILE=%t04 331 332# WRONGSECTION-GNU: Size Functions 333# WRONGSECTION-GNU-NEXT: 8 _Z3foof 334 335# WRONGSECTION-LLVM: StackSizes [ 336# WRONGSECTION-LLVM-NEXT: Entry { 337# WRONGSECTION-LLVM-NEXT: Functions: [_Z3foof] 338# WRONGSECTION-LLVM-NEXT: Size: 0x8 339# WRONGSECTION-LLVM-NEXT: } 340# WRONGSECTION-LLVM-NEXT: ] 341 342# WRONGSECTION-ERR: warning: '[[FILE]]': relocation symbol '_Z3foof' is not in the expected section 343# WRONGSECTION-DEMANGLE-ERR: warning: '[[FILE]]': relocation symbol 'foo(float)' is not in the expected section 344 345--- !ELF 346FileHeader: 347 Class: ELFCLASS64 348 Data: ELFDATA2LSB 349 Type: ET_REL 350 Machine: EM_X86_64 351Sections: 352 - Name: .text 353 Type: SHT_PROGBITS 354 Size: 8 355 - Name: .text2 356 Type: SHT_PROGBITS 357 Size: 8 358 Flags: [SHF_ALLOC] 359 - Name: .stack_sizes 360 Type: SHT_PROGBITS 361 Entries: 362 - Size: 0x8 363 Link: .text2 364 - Name: .rela.stack_sizes 365 Type: SHT_RELA 366 Info: .stack_sizes 367 Relocations: 368 - Offset: 0 369 Symbol: _Z3foof 370 Type: R_X86_64_64 371Symbols: 372 - Name: _Z3foof 373 Section: .text 374 Type: STT_FUNC 375 Binding: STB_GLOBAL 376 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 %t05 380# RUN: llvm-readelf --stack-sizes %t05 2>&1 | \ 381# RUN: FileCheck %s --check-prefix=SUDDENEND-GNU -DFILE=%t05 382# RUN: llvm-readobj --stack-sizes %t05 2>&1 | \ 383# RUN: FileCheck %s --check-prefix=SUDDENEND-LLVM -DFILE=%t05 384 385# SUDDENEND-GNU: Stack Sizes: 386# SUDDENEND-GNU-NEXT: Size Functions 387# SUDDENEND-GNU-NEXT: 8 foo 388# SUDDENEND-GNU-NEXT: warning: '[[FILE]]': SHT_PROGBITS section with index 2 ended while trying to extract a stack size entry 389# SUDDENEND-GNU-NEXT: 8 foo 390# SUDDENEND-GNU-NEXT: warning: '[[FILE]]': SHT_PROGBITS section with index 3 ended while trying to extract a stack size entry 391 392# SUDDENEND-LLVM: StackSizes [ 393# SUDDENEND-LLVM-NEXT: Entry { 394# SUDDENEND-LLVM-NEXT: Functions: [foo] 395# SUDDENEND-LLVM-NEXT: Size: 0x8 396# SUDDENEND-LLVM-NEXT: } 397# SUDDENEND-LLVM-NEXT: warning: '[[FILE]]': SHT_PROGBITS section with index 2 ended while trying to extract a stack size entry 398# SUDDENEND-LLVM-NEXT: Entry { 399# SUDDENEND-LLVM-NEXT: Functions: [foo] 400# SUDDENEND-LLVM-NEXT: Size: 0x8 401# SUDDENEND-LLVM-NEXT: } 402# SUDDENEND-LLVM-NEXT: warning: '[[FILE]]': SHT_PROGBITS section with index 3 ended while trying to extract a stack size entry 403# SUDDENEND-LLVM-NEXT: ] 404 405--- !ELF 406FileHeader: 407 Class: ELFCLASS64 408 Data: ELFDATA2LSB 409 Type: ET_EXEC 410 Machine: EM_X86_64 411Sections: 412 - Name: .text 413 Type: SHT_PROGBITS 414 - Name: .stack_sizes 415 Type: SHT_PROGBITS 416 Link: .text 417 Entries: 418 - Size: 0x8 419 - Size: 0x10 420## 0x11 == the normal size minus 1. 421 ShSize: 0x11 422 - Name: .stack_sizes (1) 423 Type: SHT_PROGBITS 424 Link: .text 425 Entries: 426 - Size: 0x8 427 - Size: 0x10 428 ShSize: 0x11 429Symbols: 430 - Name: foo 431 Section: .text 432 Type: STT_FUNC 433 434## Check that we report an invalid stack size, which is represented by a ULEB that 435## ends in a byte with the high bit set. 436 437# RUN: yaml2obj --docnum=6 %s -o %t06 438# 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 end 444# 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 end 445 446--- !ELF 447FileHeader: 448 Class: ELFCLASS64 449 Data: ELFDATA2LSB 450 Type: ET_EXEC 451Sections: 452 - Name: .text 453 Type: SHT_PROGBITS 454 Flags: [SHF_ALLOC] 455 Size: 16 456 - Name: .stack_sizes 457 Type: SHT_PROGBITS 458 Content: "100000000000000080" 459 Link: .text 460 - Name: .stack_sizes (1) 461 Type: SHT_PROGBITS 462 Content: "100000000000000080" 463 Link: .text 464Symbols: 465 - Name: foo 466 Section: .text 467 Value: 0x10 468 Type: STT_FUNC 469 Binding: STB_GLOBAL 470 471## Check that we report a warning when a relocation symbol does not belong to a 472## valid section or when it has an invalid index. We expect a stack size entry 473## with an unknown symbol in the output. 474 475# RUN: yaml2obj --docnum=7 %s -o %t07 476# 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 Functions 483# BADSECTION-OUT-GNU-NEXT: warning: '[[FILE]]': cannot identify the section for relocation symbol '_Z3foof': invalid section index: 10 484# BADSECTION-OUT-GNU-NEXT: warning: '[[FILE]]': unable to get address of symbol '_Z3foof': invalid section index: 10 485# BADSECTION-OUT-GNU-NEXT: warning: '[[FILE]]': could not identify function symbol for stack size entry in SHT_PROGBITS section with index 2 486# 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: 10 494# BADSECTION-OUT-LLVM-NEXT: warning: '[[FILE]]': unable to get address of symbol '_Z3foof': invalid section index: 10 495# BADSECTION-OUT-LLVM-NEXT: warning: '[[FILE]]': could not identify function symbol for stack size entry in SHT_PROGBITS section with index 2 496# BADSECTION-OUT-LLVM-NEXT: Entry { 497# BADSECTION-OUT-LLVM-NEXT: Functions: [?] 498# BADSECTION-OUT-LLVM-NEXT: Size: 0x8 499# 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: 0x16 504# 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: 0x24 509# 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=%t07 513# RUN: llvm-readobj --stack-sizes --demangle %t07 2>&1 | FileCheck %s --check-prefix=BADSECTION-DEMANGLE-ERR -DFILE=%t07 514 515# BADSECTION-DEMANGLE-ERR: warning: '[[FILE]]': cannot identify the section for relocation symbol 'foo(float)' 516 517--- !ELF 518FileHeader: 519 Class: ELFCLASS64 520 Data: ELFDATA2LSB 521 Type: ET_REL 522 Machine: EM_X86_64 523Sections: 524 - Name: .text 525 Type: SHT_PROGBITS 526 Size: 16 527 - Name: .stack_sizes 528 Type: SHT_PROGBITS 529 Link: .text 530 Entries: 531 - Size: 0x8 532 - Size: 0x16 533 - Size: 0x24 534 - Name: .rela.stack_sizes 535 Type: SHT_RELA 536 Info: .stack_sizes 537 Relocations: 538 - Offset: 0 539 Symbol: _Z3foof 540 Type: R_X86_64_64 541 - Offset: 9 542## An invalid symbol index. 543 Symbol: 0xff 544 Type: R_X86_64_64 545## One more invalid symbol index with the same symbol value (0xff). 546 - Offset: 0x12 547 Symbol: 0xff 548 Type: R_X86_64_64 549Symbols: 550 - Name: _Z3foof 551## An invalid section index. 552 Index: 10 553 Type: STT_FUNC 554 Binding: STB_GLOBAL 555 556## Check that we report a warning when a stack sizes section does not come with 557## a corresponding relocation section. 558 559# RUN: yaml2obj --docnum=8 %s -o %t08 560# RUN: llvm-readelf --stack-sizes %t08 2> %t08-gnu.err | FileCheck %s --check-prefix=NORELOCSECTION-OUT-GNU 561# RUN: FileCheck %s < %t08-gnu.err --check-prefix=NORELOCSECTION-ERR -DFILE=%t08 562# RUN: llvm-readobj --stack-sizes %t08 2> %t08-llvm.err | FileCheck %s --check-prefix=NORELOCSECTION-OUT-LLVM 563# RUN: FileCheck %s < %t08-llvm.err --check-prefix=NORELOCSECTION-ERR -DFILE=%t08 564 565# NORELOCSECTION-OUT-GNU: Size Functions 566# 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 section 572 573--- !ELF 574FileHeader: 575 Class: ELFCLASS64 576 Data: ELFDATA2LSB 577 Type: ET_REL 578Sections: 579 - Name: .text 580 Type: SHT_PROGBITS 581 Size: 8 582 - Name: .stack_sizes 583 Type: SHT_PROGBITS 584 Link: .text 585 Entries: 586 - Size: 0x1 587 588## Check that we handle multiple object files, separately and when they 589## are in an archive. This also checks whether we have blank lines between the 590## tables. 591 592# RUN: llvm-ar rc %t1.a %t01 %t02 593# RUN: llvm-readelf --stack-sizes %t01 %t02 \ 594# RUN: | FileCheck %s --check-prefixes=MULTIPLE-GNU,OBJECT -DFILE1=%t01 -DFILE2=%t02 595# 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.a 598# RUN: llvm-readobj --stack-sizes %t01 %t02 \ 599# RUN: | FileCheck %s --check-prefixes=MULTIPLE-LLVM,OBJECT -DFILE1=%t01 -DFILE2=%t02 600# RUN: llvm-readobj --stack-sizes %t1.a \ 601# RUN: | FileCheck %s --check-prefixes=MULTIPLE-LLVM,ARCHIVE -DFILE=%t1.a 602 603# OBJECT:File: [[FILE1]] 604# ARCHIVE:File: [[FILE]]({{.*01}}) 605 606# MULTIPLE-GNU:Stack Sizes: 607# MULTIPLE-GNU-NEXT: Size Functions 608# MULTIPLE-GNU-NEXT: 16 referenced_by_symbol_foo 609# MULTIPLE-GNU-NEXT: 32 referenced_via_section_bar 610# MULTIPLE-GNU-NEXT: 8 separate_text_section_baz 611# 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: 0x10 617# MULTIPLE-LLVM-NEXT: } 618# MULTIPLE-LLVM-NEXT: Entry { 619# MULTIPLE-LLVM-NEXT: Functions: [referenced_via_section_bar] 620# MULTIPLE-LLVM-NEXT: Size: 0x20 621# MULTIPLE-LLVM-NEXT: } 622# MULTIPLE-LLVM-NEXT: Entry { 623# MULTIPLE-LLVM-NEXT: Functions: [separate_text_section_baz] 624# MULTIPLE-LLVM-NEXT: Size: 0x8 625# 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 Functions 634# MULTIPLE-GNU-NEXT: 16 other 635# MULTIPLE-GNU-NEXT: 32 other_end 636# MULTIPLE-GNU-NEXT: 48 bar 637 638# MULTIPLE-LLVM: StackSizes [ 639# MULTIPLE-LLVM-NEXT: Entry { 640# MULTIPLE-LLVM-NEXT: Functions: [other] 641# MULTIPLE-LLVM-NEXT: Size: 0x10 642# MULTIPLE-LLVM-NEXT: } 643# MULTIPLE-LLVM-NEXT: Entry { 644# MULTIPLE-LLVM-NEXT: Functions: [other_end] 645# MULTIPLE-LLVM-NEXT: Size: 0x20 646# MULTIPLE-LLVM-NEXT: } 647# MULTIPLE-LLVM-NEXT: Entry { 648# MULTIPLE-LLVM-NEXT: Functions: [bar] 649# MULTIPLE-LLVM-NEXT: Size: 0x30 650# MULTIPLE-LLVM-NEXT: } 651# MULTIPLE-LLVM-NEXT: ] 652 653## Check that we do not consider symbols that are not function symbols, even though 654## a relocation references them. 655 656# RUN: yaml2obj --docnum=9 %s -o %t14 657# RUN: llvm-readelf --stack-sizes %t14 2> %t14-gnu.err | FileCheck %s --check-prefix=NONFUNCTIONSYM-GNU 658# RUN: FileCheck %s < %t14-gnu.err --check-prefix=NONFUNCTIONSYM-ERR -DFILE=%t14 659# RUN: llvm-readobj --stack-sizes %t14 2> %t14-llvm.err | FileCheck %s --check-prefix=NONFUNCTIONSYM-LLVM 660# RUN: FileCheck %s < %t14-llvm.err --check-prefix=NONFUNCTIONSYM-ERR -DFILE=%t14 661 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: 0x0 669# 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 2 673 674--- !ELF 675FileHeader: 676 Class: ELFCLASS64 677 Data: ELFDATA2LSB 678 Type: ET_REL 679 Machine: EM_X86_64 680Sections: 681 - Name: .text 682 Type: SHT_PROGBITS 683 Size: 16 684 - Name: .stack_sizes 685 Type: SHT_PROGBITS 686 Entries: 687 - Size: 0 688 Link: .text 689 - Name: .rela.stack_sizes 690 Type: SHT_RELA 691 Info: .stack_sizes 692 Relocations: 693 - Offset: 0 694 Symbol: foo 695 Type: R_X86_64_64 696Symbols: 697 - Name: foo 698 Section: .text 699 Type: STT_OBJECT 700 Binding: STB_GLOBAL 701 702## Check that we report a warning when we find an unsupported relocation 703## in the section that contains the stack size entries' relocations. 704 705# RUN: yaml2obj --docnum=10 %s -o %t15 706# RUN: llvm-readelf --stack-sizes %t15 2>&1 | FileCheck %s --check-prefix=UNSUPPRELOC-GNU -DFILE=%t15 707# RUN: llvm-readobj --stack-sizes %t15 2>&1 | FileCheck %s --check-prefix=UNSUPPRELOC-LLVM -DFILE=%t15 708 709# UNSUPPRELOC-GNU: Stack Sizes: 710# UNSUPPRELOC-GNU-NEXT: Size Functions 711# UNSUPPRELOC-GNU-NEXT: warning: '[[FILE]]': SHT_RELA section with index 3 contains an unsupported relocation with index 0: R_X86_64_RELATIVE 712# UNSUPPRELOC-GNU-NEXT: 0 foo 713# UNSUPPRELOC-GNU-NEXT: warning: '[[FILE]]': SHT_RELA section with index 3 contains an unsupported relocation with index 2: R_X86_64_RELATIVE 714 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_RELATIVE 717# UNSUPPRELOC-LLVM-NEXT: Entry { 718# UNSUPPRELOC-LLVM-NEXT: Functions: [foo] 719# UNSUPPRELOC-LLVM-NEXT: Size: 0x0 720# 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_RELATIVE 722# UNSUPPRELOC-LLVM-NEXT: ] 723 724--- !ELF 725FileHeader: 726 Class: ELFCLASS64 727 Data: ELFDATA2LSB 728 Type: ET_REL 729 Machine: EM_X86_64 730Sections: 731 - Name: .text 732 Type: SHT_PROGBITS 733 Size: 8 734 - Name: .stack_sizes 735 Type: SHT_PROGBITS 736 Link: .text 737 Entries: 738 - Size: 0 739 - Name: .rela.stack_sizes 740 Type: SHT_RELA 741 Info: .stack_sizes 742 Relocations: 743 - Offset: 0 744 Symbol: foo 745 Type: R_X86_64_RELATIVE 746 - Offset: 0 747 Symbol: foo 748 Type: R_X86_64_64 749 - Offset: 0 750 Symbol: foo 751 Type: R_X86_64_RELATIVE 752Symbols: 753 - Name: foo 754 Section: .text 755 Type: STT_FUNC 756 Binding: STB_GLOBAL 757 758## Check that warning messages in archives do not impact other members. In the following 759## test, the first archive member generates a warning and we make sure all the information 760## is still dumped. 761 762# RUN: llvm-ar rc %t2.a %t04 %t01 763# RUN: llvm-readelf --stack-sizes %t2.a 2>&1 | FileCheck %s --check-prefix=ARCHIVEWARN-GNU \ 764# RUN: -DFILE=%t2.a --strict-whitespace --match-full-lines 765# RUN: llvm-readobj --stack-sizes %t2.a 2>&1 | FileCheck %s --check-prefix=ARCHIVEWARN-LLVM -DFILE=%t2.a 766 767# ARCHIVEWARN-GNU:File: [[FILE]]({{.*04}}) 768# ARCHIVEWARN-GNU:Stack Sizes: 769# ARCHIVEWARN-GNU-NEXT: Size Functions 770# ARCHIVEWARN-GNU:{{.*}}: warning: '{{.*04}}': relocation symbol '_Z3foof' is not in the expected section 771# ARCHIVEWARN-GNU: 8 _Z3foof 772# ARCHIVEWARN-GNU:File: [[FILE]]({{.*01}}) 773# ARCHIVEWARN-GNU:Stack Sizes: 774# ARCHIVEWARN-GNU-NEXT: Size Functions 775# ARCHIVEWARN-GNU-NEXT: 16 referenced_by_symbol_foo 776# ARCHIVEWARN-GNU-NEXT: 32 referenced_via_section_bar 777# ARCHIVEWARN-GNU-NEXT: 8 separate_text_section_baz 778# 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 section 784# ARCHIVEWARN-LLVM-NEXT: Entry { 785# ARCHIVEWARN-LLVM-NEXT: Functions: [_Z3foof] 786# ARCHIVEWARN-LLVM-NEXT: Size: 0x8 787# 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: 0x10 794# ARCHIVEWARN-LLVM-NEXT: } 795# ARCHIVEWARN-LLVM-NEXT: Entry { 796# ARCHIVEWARN-LLVM-NEXT: Functions: [referenced_via_section_bar] 797# ARCHIVEWARN-LLVM-NEXT: Size: 0x20 798# ARCHIVEWARN-LLVM-NEXT: } 799# ARCHIVEWARN-LLVM-NEXT: Entry { 800# ARCHIVEWARN-LLVM-NEXT: Functions: [separate_text_section_baz] 801# ARCHIVEWARN-LLVM-NEXT: Size: 0x8 802# 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 %t16 808# RUN: llvm-readelf --stack-sizes --demangle %t16 | FileCheck %s --check-prefix=DEMANGLE-GNU 809# RUN: llvm-readobj --stack-sizes --demangle %t16 | FileCheck %s --check-prefix=DEMANGLE-LLVM 810 811# DEMANGLE-GNU: 16 foo(float) 812# DEMANGLE-LLVM: Functions: [foo(float)] 813 814--- !ELF 815FileHeader: 816 Class: ELFCLASS64 817 Data: ELFDATA2LSB 818 Type: ET_EXEC 819Sections: 820 - Name: .text 821 Type: SHT_PROGBITS 822 Flags: [SHF_ALLOC] 823 Size: 16 824 - Name: .stack_sizes 825 Type: SHT_PROGBITS 826 Entries: 827 - Address: 0x10 828 Size: 0x10 829 Link: .text 830Symbols: 831 - Name: _Z3foof 832 Section: .text 833 Value: 0x10 834 Type: STT_FUNC 835 Binding: STB_GLOBAL 836 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 %t17 841# RUN: llvm-readelf --stack-sizes %t17 2>&1 | FileCheck %s -DFILE=%t17 --check-prefix=UNSUPPRELOC2 842# RUN: llvm-readobj --stack-sizes %t17 2>&1 | FileCheck %s -DFILE=%t17 --check-prefix=UNSUPPRELOC2 843 844# UNSUPPRELOC2: warning: '[[FILE]]': SHT_RELA section with index 2 contains an unsupported relocation with index 0: R_X86_64_64 845 846--- !ELF 847FileHeader: 848 Class: ELFCLASS32 849 Data: ELFDATA2MSB 850 Type: ET_REL 851 Machine: EM_X86_64 852Sections: 853 - Name: .stack_sizes 854 Type: SHT_PROGBITS 855 Content: "00" 856 - Name: .rela.stack_sizes 857 Type: SHT_RELA 858 Info: .stack_sizes 859 Relocations: 860 - Offset: 0 861 Type: R_X86_64_64 862 863## Check we report a warning when dumping stack sizes if the relocated section 864## identified by the sh_info field is invalid. Here the sh_info value is larger than 865## the number of sections. 866 867# RUN: yaml2obj --docnum=13 %s -o %t18 868# RUN: llvm-readelf --stack-sizes %t18 2>&1 | \ 869# RUN: FileCheck %s --implicit-check-not="warning:" -DFILE=%t18 --check-prefix=INVALID-TARGET 870# RUN: llvm-readobj --stack-sizes %t18 2>&1 | \ 871# RUN: FileCheck %s --implicit-check-not="warning:" -DFILE=%t18 --check-prefix=INVALID-TARGET 872 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: 255 874# INVALID-TARGET: SHT_RELA section with index 2: failed to get a relocated section: invalid section index: 255 875 876--- !ELF 877FileHeader: 878 Class: ELFCLASS32 879 Data: ELFDATA2MSB 880 Type: ET_REL 881Sections: 882 - Name: .rela.stack_sizes 883 Type: SHT_RELA 884 Link: 0 885 Info: 0xFF 886 Relocations: [] 887 - Name: .rela.stack_sizes (1) 888 Type: SHT_RELA 889 Link: 0 890 Info: 0xFF 891 Relocations: [] 892 893## Check that that we see multiple symbols output in cases when multiple symbols 894## share the same stack size entry, for example when use of ICF means two functions 895## are represented by the same code. 896 897# RUN: yaml2obj --docnum=14 %s -o %t19 898# RUN: llvm-readelf --stack-sizes %t19 2>&1 \ 899# RUN: | FileCheck %s --check-prefix=MULTIPLE-SYMBOLS-GNU 900# RUN: llvm-readobj --stack-sizes %t19 2>&1 \ 901# RUN: | FileCheck %s --check-prefix=MULTIPLE-SYMBOLS-LLVM 902 903# MULTIPLE-SYMBOLS-GNU: Size Functions 904# MULTIPLE-SYMBOLS-GNU: 16 foo, bar 905# 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: 0x10 911# MULTIPLE-SYMBOLS-LLVM-NEXT: } 912# MULTIPLE-SYMBOLS-LLVM-NEXT: ] 913# MULTIPLE-SYMBOLS-LLVM-NOT:{{.}} 914 915--- !ELF 916FileHeader: 917 Class: ELFCLASS64 918 Data: ELFDATA2LSB 919 Type: ET_EXEC 920Sections: 921 - Name: .text 922 Type: SHT_PROGBITS 923 Flags: [SHF_ALLOC] 924 Size: 16 925 - Name: .stack_sizes 926 Type: SHT_PROGBITS 927 Entries: 928 - Address: 0x0 929 Size: 0x10 930 Link: .text 931Symbols: 932 - Name: foo 933 Section: .text 934 Value: 0x0 935 Type: STT_FUNC 936 Binding: STB_GLOBAL 937 - Name: bar 938 Section: .text 939 Value: 0x0 940 Type: STT_FUNC 941 Binding: STB_GLOBAL 942