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 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 13# RELOC-GNU-NOT:{{.}} 14 15# RELOC-LLVM: StackSizes [ 16# RELOC-LLVM-NEXT: Entry { 17# RELOC-LLVM-NEXT: Function: referenced_by_symbol_foo 18# RELOC-LLVM-NEXT: Size: 0x10 19# RELOC-LLVM-NEXT: } 20# RELOC-LLVM-NEXT: Entry { 21# RELOC-LLVM-NEXT: Function: referenced_via_section_bar 22# RELOC-LLVM-NEXT: Size: 0x20 23# RELOC-LLVM-NEXT: } 24# RELOC-LLVM-NEXT: Entry { 25# RELOC-LLVM-NEXT: Function: 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 Function 109# SYMTAB-GNU-NEXT: warning: '[[FILE]]': unable to get the target of relocation with index 1 in SHT_RELA section with index 5: unable to access section [index 7] data at 0xffffef36: offset goes past the end of file 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 2 in SHT_RELA section with index 5: unable to access section [index 7] data at 0xffffef1e: offset goes past the end of file 114# SYMTAB-GNU-NEXT: 32 ? 115# SYMTAB-GNU-NEXT: warning: '[[FILE]]': unable to get the target of relocation with index 1 in SHT_RELA section with index 6: unable to access section [index 7] data at 0xffffef06: offset goes past the end of file 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 1 in SHT_RELA section with index 5: unable to access section [index 7] data at 0xffffef36: offset goes past the end of file 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: Function: ? 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 2 in SHT_RELA section with index 5: unable to access section [index 7] data at 0xffffef1e: offset goes past the end of file 128# SYMTAB-LLVM-NEXT: Entry { 129# SYMTAB-LLVM-NEXT: Function: ? 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 1 in SHT_RELA section with index 6: unable to access section [index 7] data at 0xffffef06: offset goes past the end of file 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: Function: ? 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 Function 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: Function: ? 164# SYM-LLVM-NEXT: Size: 0x10 165# SYM-LLVM-NEXT: } 166# SYM-LLVM-NEXT: Entry { 167# SYM-LLVM-NEXT: Function: ? 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: Function: ? 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 Function 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: Function: other 198# EXEC-LLVM-NEXT: Size: 0x10 199# EXEC-LLVM-NEXT: } 200# EXEC-LLVM-NEXT: Entry { 201# EXEC-LLVM-NEXT: Function: other_end 202# EXEC-LLVM-NEXT: Size: 0x20 203# EXEC-LLVM-NEXT: } 204# EXEC-LLVM-NEXT: Entry { 205# EXEC-LLVM-NEXT: Function: 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 ## If two symbols have the same value, the first is picked, regardless of 246 ## the sh_link value of the .stack_sizes section. 247 - Name: other_end 248 Section: .text 249 Value: 0x10 250 Type: STT_FUNC 251 Binding: STB_GLOBAL 252 - Name: foo 253 Section: .text2 254 Value: 0x10 255 Type: STT_FUNC 256 Binding: STB_GLOBAL 257 - Name: bar 258 Section: .text2 259 Value: 0x20 260 Type: STT_FUNC 261 Binding: STB_GLOBAL 262 263## Check that we report a warning when we find relocations whose offsets point outside 264## of the .stack_sizes section. 265 266# RUN: yaml2obj --docnum=3 %s -o %t03 267# RUN: llvm-readelf --stack-sizes %t03 2>&1 | FileCheck %s --check-prefix=SHORT-GNU -DFILE=%t03 268# RUN: llvm-readobj --stack-sizes %t03 2>&1 | FileCheck %s --check-prefix=SHORT-LLVM -DFILE=%t03 269 270# SHORT-GNU: Stack Sizes: 271# SHORT-GNU-NEXT: Size Function 272# SHORT-GNU-NEXT: 8 foo 273# 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 274# SHORT-GNU-NEXT: 8 foo 275 276# SHORT-LLVM: StackSizes [ 277# SHORT-LLVM-NEXT: Entry { 278# SHORT-LLVM-NEXT: Function: foo 279# SHORT-LLVM-NEXT: Size: 0x8 280# SHORT-LLVM-NEXT: } 281# 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 282# SHORT-LLVM-NEXT: Entry { 283# SHORT-LLVM-NEXT: Function: foo 284# SHORT-LLVM-NEXT: Size: 0x8 285# SHORT-LLVM-NEXT: } 286# SHORT-LLVM-NEXT: ] 287 288--- !ELF 289FileHeader: 290 Class: ELFCLASS64 291 Data: ELFDATA2LSB 292 Type: ET_REL 293 Machine: EM_X86_64 294Sections: 295 - Name: .text 296 Type: SHT_PROGBITS 297 Flags: [SHF_ALLOC] 298 Size: 16 299 - Name: .stack_sizes 300 Type: SHT_PROGBITS 301 Link: .text 302 Entries: 303 - Size: 0x8 304 - Name: .rela.stack_sizes 305 Type: SHT_RELA 306 Info: .stack_sizes 307 Relocations: 308 - Offset: 0x0 309 Symbol: foo 310 Type: R_X86_64_64 311 - Offset: 0x1 312 Symbol: foo 313 Type: R_X86_64_64 314 - Offset: 0x1 315 Symbol: foo 316 Type: R_X86_64_64 317 - Offset: 0x0 318 Symbol: foo 319 Type: R_X86_64_64 320Symbols: 321 - Name: foo 322 Section: .text 323 Type: STT_FUNC 324 Binding: STB_GLOBAL 325 326## Check that we warn about a function symbol that is not in the section 327## that is referenced by the stack sizes section's sh_link, for relocatable 328## output. 329 330# RUN: yaml2obj --docnum=4 %s -o %t04 331# RUN: llvm-readelf --stack-sizes %t04 2> %t04-gnu.err | FileCheck %s --check-prefix=WRONGSECTION-GNU 332# RUN: FileCheck %s < %t04-gnu.err --check-prefix=WRONGSECTION-ERR -DFILE=%t04 333# RUN: llvm-readobj --stack-sizes %t04 2> %t04-llvm.err | FileCheck %s --check-prefix=WRONGSECTION-LLVM 334# RUN: FileCheck %s < %t04-llvm.err --check-prefix=WRONGSECTION-ERR -DFILE=%t04 335 336# RUN: llvm-readelf --stack-sizes --demangle %t04 2>&1 | FileCheck %s --check-prefix=WRONGSECTION-DEMANGLE-ERR -DFILE=%t04 337# RUN: llvm-readobj --stack-sizes --demangle %t04 2>&1 | FileCheck %s --check-prefix=WRONGSECTION-DEMANGLE-ERR -DFILE=%t04 338 339# WRONGSECTION-GNU: Size Function 340# WRONGSECTION-GNU-NEXT: 8 _Z3foof 341 342# WRONGSECTION-LLVM: StackSizes [ 343# WRONGSECTION-LLVM-NEXT: Entry { 344# WRONGSECTION-LLVM-NEXT: Function: _Z3foof 345# WRONGSECTION-LLVM-NEXT: Size: 0x8 346# WRONGSECTION-LLVM-NEXT: } 347# WRONGSECTION-LLVM-NEXT: ] 348 349# WRONGSECTION-ERR: warning: '[[FILE]]': relocation symbol '_Z3foof' is not in the expected section 350# WRONGSECTION-DEMANGLE-ERR: warning: '[[FILE]]': relocation symbol 'foo(float)' is not in the expected section 351 352--- !ELF 353FileHeader: 354 Class: ELFCLASS64 355 Data: ELFDATA2LSB 356 Type: ET_REL 357 Machine: EM_X86_64 358Sections: 359 - Name: .text 360 Type: SHT_PROGBITS 361 Size: 8 362 - Name: .text2 363 Type: SHT_PROGBITS 364 Size: 8 365 Flags: [SHF_ALLOC] 366 - Name: .stack_sizes 367 Type: SHT_PROGBITS 368 Entries: 369 - Size: 0x8 370 Link: .text2 371 - Name: .rela.stack_sizes 372 Type: SHT_RELA 373 Info: .stack_sizes 374 Relocations: 375 - Offset: 0 376 Symbol: _Z3foof 377 Type: R_X86_64_64 378Symbols: 379 - Name: _Z3foof 380 Section: .text 381 Type: STT_FUNC 382 Binding: STB_GLOBAL 383 384## Check that we report a warning when a stack sizes section ends with an incomplete stack size entry. 385 386# RUN: yaml2obj --docnum=5 %s -o %t05 387# RUN: llvm-readelf --stack-sizes %t05 2>&1 | \ 388# RUN: FileCheck %s --check-prefix=SUDDENEND-GNU -DFILE=%t05 389# RUN: llvm-readobj --stack-sizes %t05 2>&1 | \ 390# RUN: FileCheck %s --check-prefix=SUDDENEND-LLVM -DFILE=%t05 391 392# SUDDENEND-GNU: Stack Sizes: 393# SUDDENEND-GNU-NEXT: Size Function 394# SUDDENEND-GNU-NEXT: 8 foo 395# SUDDENEND-GNU-NEXT: warning: '[[FILE]]': SHT_PROGBITS section with index 2 ended while trying to extract a stack size entry 396# SUDDENEND-GNU-NEXT: 8 foo 397# SUDDENEND-GNU-NEXT: warning: '[[FILE]]': SHT_PROGBITS section with index 3 ended while trying to extract a stack size entry 398 399# SUDDENEND-LLVM: StackSizes [ 400# SUDDENEND-LLVM-NEXT: Entry { 401# SUDDENEND-LLVM-NEXT: Function: foo 402# SUDDENEND-LLVM-NEXT: Size: 0x8 403# SUDDENEND-LLVM-NEXT: } 404# SUDDENEND-LLVM-NEXT: warning: '[[FILE]]': SHT_PROGBITS section with index 2 ended while trying to extract a stack size entry 405# SUDDENEND-LLVM-NEXT: Entry { 406# SUDDENEND-LLVM-NEXT: Function: foo 407# SUDDENEND-LLVM-NEXT: Size: 0x8 408# SUDDENEND-LLVM-NEXT: } 409# SUDDENEND-LLVM-NEXT: warning: '[[FILE]]': SHT_PROGBITS section with index 3 ended while trying to extract a stack size entry 410# SUDDENEND-LLVM-NEXT: ] 411 412--- !ELF 413FileHeader: 414 Class: ELFCLASS64 415 Data: ELFDATA2LSB 416 Type: ET_EXEC 417 Machine: EM_X86_64 418Sections: 419 - Name: .text 420 Type: SHT_PROGBITS 421 - Name: .stack_sizes 422 Type: SHT_PROGBITS 423 Link: .text 424 Entries: 425 - Size: 0x8 426 - Size: 0x10 427## 0x11 == the normal size minus 1. 428 ShSize: 0x11 429 - Name: .stack_sizes (1) 430 Type: SHT_PROGBITS 431 Link: .text 432 Entries: 433 - Size: 0x8 434 - Size: 0x10 435 ShSize: 0x11 436Symbols: 437 - Name: foo 438 Section: .text 439 Type: STT_FUNC 440 441## Check that we report an invalid stack size, which is represented by a ULEB that 442## ends in a byte with the high bit set. 443 444# RUN: yaml2obj --docnum=6 %s -o %t06 445# RUN: llvm-readelf --stack-sizes %t06 2>&1 | FileCheck %s --check-prefix=BADSIZE -DFILE=%t06 446# RUN: llvm-readobj --stack-sizes %t06 2>&1 | FileCheck %s --check-prefix=BADSIZE -DFILE=%t06 447 448# BADSIZE: warning: '[[FILE]]': could not extract a valid stack size from SHT_PROGBITS section with index 2 449# BADSIZE: warning: '[[FILE]]': could not extract a valid stack size from SHT_PROGBITS section with index 3 450 451--- !ELF 452FileHeader: 453 Class: ELFCLASS64 454 Data: ELFDATA2LSB 455 Type: ET_EXEC 456Sections: 457 - Name: .text 458 Type: SHT_PROGBITS 459 Flags: [SHF_ALLOC] 460 Size: 16 461 - Name: .stack_sizes 462 Type: SHT_PROGBITS 463 Content: "100000000000000080" 464 Link: .text 465 - Name: .stack_sizes (1) 466 Type: SHT_PROGBITS 467 Content: "100000000000000080" 468 Link: .text 469Symbols: 470 - Name: foo 471 Section: .text 472 Value: 0x10 473 Type: STT_FUNC 474 Binding: STB_GLOBAL 475 476## Check that we report a warning when a relocation symbol does not belong to a 477## valid section or when it has an invalid index. We expect a stack size entry 478## with an unknown symbol in the output. 479 480# RUN: yaml2obj --docnum=7 %s -o %t07 481# RUN: llvm-readelf --stack-sizes %t07 2>&1 | \ 482# RUN: FileCheck %s -DFILE=%t07 --check-prefix=BADSECTION-OUT-GNU --implicit-check-not=warning: 483# RUN: llvm-readobj --stack-sizes %t07 2>&1 | \ 484# RUN: FileCheck %s -DFILE=%t07 --check-prefix=BADSECTION-OUT-LLVM --implicit-check-not=warning: 485 486# BADSECTION-OUT-GNU: Stack Sizes: 487# BADSECTION-OUT-GNU-NEXT: Size Function 488# BADSECTION-OUT-GNU-NEXT: warning: '[[FILE]]': cannot identify the section for relocation symbol '_Z3foof': invalid section index: 10 489# BADSECTION-OUT-GNU-NEXT: warning: '[[FILE]]': unable to get address of symbol '_Z3foof': invalid section index: 10 490# BADSECTION-OUT-GNU-NEXT: warning: '[[FILE]]': could not identify function symbol for stack size entry in SHT_PROGBITS section with index 2 491# BADSECTION-OUT-GNU-NEXT: 8 ? 492# 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 access section [index 4] data at 0x18a0: offset goes past the end of file 493# BADSECTION-OUT-GNU-NEXT: 22 ? 494# BADSECTION-OUT-GNU-NEXT: warning: '[[FILE]]': unable to get the target of relocation with index 3 in SHT_RELA section with index 3: unable to access section [index 4] data at 0x18a0: offset goes past the end of file 495# BADSECTION-OUT-GNU-NEXT: 36 ? 496 497# BADSECTION-OUT-LLVM: StackSizes [ 498# BADSECTION-OUT-LLVM-NEXT: warning: '[[FILE]]': cannot identify the section for relocation symbol '_Z3foof': invalid section index: 10 499# BADSECTION-OUT-LLVM-NEXT: warning: '[[FILE]]': unable to get address of symbol '_Z3foof': invalid section index: 10 500# BADSECTION-OUT-LLVM-NEXT: warning: '[[FILE]]': could not identify function symbol for stack size entry in SHT_PROGBITS section with index 2 501# BADSECTION-OUT-LLVM-NEXT: Entry { 502# BADSECTION-OUT-LLVM-NEXT: Function: ? 503# BADSECTION-OUT-LLVM-NEXT: Size: 0x8 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 access section [index 4] data at 0x18a0: offset goes past the end of file 506# BADSECTION-OUT-LLVM-NEXT: Entry { 507# BADSECTION-OUT-LLVM-NEXT: Function: ? 508# BADSECTION-OUT-LLVM-NEXT: Size: 0x16 509# BADSECTION-OUT-LLVM-NEXT: } 510# BADSECTION-OUT-LLVM-NEXT: warning: '[[FILE]]': unable to get the target of relocation with index 3 in SHT_RELA section with index 3: unable to access section [index 4] data at 0x18a0: offset goes past the end of file 511# BADSECTION-OUT-LLVM-NEXT: Entry { 512# BADSECTION-OUT-LLVM-NEXT: Function: ? 513# BADSECTION-OUT-LLVM-NEXT: Size: 0x24 514# BADSECTION-OUT-LLVM-NEXT: } 515# BADSECTION-OUT-LLVM-NEXT: ] 516 517# RUN: llvm-readelf --stack-sizes --demangle %t07 2>&1 | FileCheck %s --check-prefix=BADSECTION-DEMANGLE-ERR -DFILE=%t07 518# RUN: llvm-readobj --stack-sizes --demangle %t07 2>&1 | FileCheck %s --check-prefix=BADSECTION-DEMANGLE-ERR -DFILE=%t07 519 520# BADSECTION-DEMANGLE-ERR: warning: '[[FILE]]': cannot identify the section for relocation symbol 'foo(float)' 521 522--- !ELF 523FileHeader: 524 Class: ELFCLASS64 525 Data: ELFDATA2LSB 526 Type: ET_REL 527 Machine: EM_X86_64 528Sections: 529 - Name: .text 530 Type: SHT_PROGBITS 531 Size: 16 532 - Name: .stack_sizes 533 Type: SHT_PROGBITS 534 Link: .text 535 Entries: 536 - Size: 0x8 537 - Size: 0x16 538 - Size: 0x24 539 - Name: .rela.stack_sizes 540 Type: SHT_RELA 541 Info: .stack_sizes 542 Relocations: 543 - Offset: 0 544 Symbol: _Z3foof 545 Type: R_X86_64_64 546 - Offset: 9 547## An invalid symbol index. 548 Symbol: 0xff 549 Type: R_X86_64_64 550## One more invalid symbol index with the same symbol value (0xff). 551 - Offset: 0x12 552 Symbol: 0xff 553 Type: R_X86_64_64 554Symbols: 555 - Name: _Z3foof 556## An invalid section index. 557 Index: 10 558 Type: STT_FUNC 559 Binding: STB_GLOBAL 560 561## Check that we report a warning when a stack sizes section does not come with 562## a corresponding relocation section. 563 564# RUN: yaml2obj --docnum=8 %s -o %t08 565# RUN: llvm-readelf --stack-sizes %t08 2> %t08-gnu.err | FileCheck %s --check-prefix=NORELOCSECTION-OUT-GNU 566# RUN: FileCheck %s < %t08-gnu.err --check-prefix=NORELOCSECTION-ERR -DFILE=%t08 567# RUN: llvm-readobj --stack-sizes %t08 2> %t08-llvm.err | FileCheck %s --check-prefix=NORELOCSECTION-OUT-LLVM 568# RUN: FileCheck %s < %t08-llvm.err --check-prefix=NORELOCSECTION-ERR -DFILE=%t08 569 570# NORELOCSECTION-OUT-GNU: Size Function 571# NORELOCSECTION-OUT-GNU-NOT: {{.}} 572 573# NORELOCSECTION-OUT-LLVM: StackSizes [ 574# NORELOCSECTION-OUT-LLVM-NEXT: ] 575 576# NORELOCSECTION-ERR: warning: '[[FILE]]': .stack_sizes (SHT_PROGBITS section with index 2) does not have a corresponding relocation section 577 578--- !ELF 579FileHeader: 580 Class: ELFCLASS64 581 Data: ELFDATA2LSB 582 Type: ET_REL 583Sections: 584 - Name: .text 585 Type: SHT_PROGBITS 586 Size: 8 587 - Name: .stack_sizes 588 Type: SHT_PROGBITS 589 Link: .text 590 Entries: 591 - Size: 0x1 592 593## Check that we handle multiple object files, separately and when they 594## are in an archive. This also checks whether we have blank lines between the 595## tables. 596 597# RUN: llvm-ar rc %t1.a %t01 %t02 598# RUN: llvm-readelf --stack-sizes %t01 %t02 \ 599# RUN: | FileCheck %s --check-prefixes=MULTIPLE-GNU,OBJECT -DFILE1=%t01 -DFILE2=%t02 600# RUN: llvm-readelf --stack-sizes %t1.a \ 601# RUN: | FileCheck %s --check-prefixes=MULTIPLE-GNU,ARCHIVE --strict-whitespace\ 602# RUN: --match-full-lines -DFILE=%t1.a 603# RUN: llvm-readobj --stack-sizes %t01 %t02 \ 604# RUN: | FileCheck %s --check-prefixes=MULTIPLE-LLVM,OBJECT -DFILE1=%t01 -DFILE2=%t02 605# RUN: llvm-readobj --stack-sizes %t1.a \ 606# RUN: | FileCheck %s --check-prefixes=MULTIPLE-LLVM,ARCHIVE -DFILE=%t1.a 607 608# OBJECT:File: [[FILE1]] 609# ARCHIVE:File: [[FILE]]({{.*01}}) 610 611# MULTIPLE-GNU:Stack Sizes: 612# MULTIPLE-GNU-NEXT: Size Function 613# MULTIPLE-GNU-NEXT: 16 referenced_by_symbol_foo 614# MULTIPLE-GNU-NEXT: 32 referenced_via_section_bar 615# MULTIPLE-GNU-NEXT: 8 separate_text_section_baz 616# MULTIPLE-GNU-EMPTY: 617 618# MULTIPLE-LLVM: StackSizes [ 619# MULTIPLE-LLVM-NEXT: Entry { 620# MULTIPLE-LLVM-NEXT: Function: referenced_by_symbol_foo 621# MULTIPLE-LLVM-NEXT: Size: 0x10 622# MULTIPLE-LLVM-NEXT: } 623# MULTIPLE-LLVM-NEXT: Entry { 624# MULTIPLE-LLVM-NEXT: Function: referenced_via_section_bar 625# MULTIPLE-LLVM-NEXT: Size: 0x20 626# MULTIPLE-LLVM-NEXT: } 627# MULTIPLE-LLVM-NEXT: Entry { 628# MULTIPLE-LLVM-NEXT: Function: separate_text_section_baz 629# MULTIPLE-LLVM-NEXT: Size: 0x8 630# MULTIPLE-LLVM-NEXT: } 631# MULTIPLE-LLVM-NEXT: ] 632 633# OBJECT:File: [[FILE2]] 634# ARCHIVE:File: [[FILE]]({{.*02}}) 635 636# MULTIPLE-GNU-EMPTY: 637# MULTIPLE-GNU-NEXT:Stack Sizes: 638# MULTIPLE-GNU-NEXT: Size Function 639# MULTIPLE-GNU-NEXT: 16 other 640# MULTIPLE-GNU-NEXT: 32 other_end 641# MULTIPLE-GNU-NEXT: 48 bar 642 643# MULTIPLE-LLVM: StackSizes [ 644# MULTIPLE-LLVM-NEXT: Entry { 645# MULTIPLE-LLVM-NEXT: Function: other 646# MULTIPLE-LLVM-NEXT: Size: 0x10 647# MULTIPLE-LLVM-NEXT: } 648# MULTIPLE-LLVM-NEXT: Entry { 649# MULTIPLE-LLVM-NEXT: Function: other_end 650# MULTIPLE-LLVM-NEXT: Size: 0x20 651# MULTIPLE-LLVM-NEXT: } 652# MULTIPLE-LLVM-NEXT: Entry { 653# MULTIPLE-LLVM-NEXT: Function: bar 654# MULTIPLE-LLVM-NEXT: Size: 0x30 655# MULTIPLE-LLVM-NEXT: } 656# MULTIPLE-LLVM-NEXT: ] 657 658## Check that we do not consider symbols that are not function symbols, even though 659## a relocation references them. 660 661# RUN: yaml2obj --docnum=9 %s -o %t14 662# RUN: llvm-readelf --stack-sizes %t14 2> %t14-gnu.err | FileCheck %s --check-prefix=NONFUNCTIONSYM-GNU 663# RUN: FileCheck %s < %t14-gnu.err --check-prefix=NONFUNCTIONSYM-ERR -DFILE=%t14 664# RUN: llvm-readobj --stack-sizes %t14 2> %t14-llvm.err | FileCheck %s --check-prefix=NONFUNCTIONSYM-LLVM 665# RUN: FileCheck %s < %t14-llvm.err --check-prefix=NONFUNCTIONSYM-ERR -DFILE=%t14 666 667# NONFUNCTIONSYM-GNU: Stack Sizes: 668# NONFUNCTIONSYM-GNU: 0 ? 669 670# NONFUNCTIONSYM-LLVM: StackSizes [ 671# NONFUNCTIONSYM-LLVM-NEXT: Entry { 672# NONFUNCTIONSYM-LLVM-NEXT: Function: ? 673# NONFUNCTIONSYM-LLVM-NEXT: Size: 0x0 674# NONFUNCTIONSYM-LLVM-NEXT: } 675# NONFUNCTIONSYM-LLVM-NEXT: ] 676 677# NONFUNCTIONSYM-ERR: warning: '[[FILE]]': could not identify function symbol for stack size entry in SHT_PROGBITS section with index 2 678 679--- !ELF 680FileHeader: 681 Class: ELFCLASS64 682 Data: ELFDATA2LSB 683 Type: ET_REL 684 Machine: EM_X86_64 685Sections: 686 - Name: .text 687 Type: SHT_PROGBITS 688 Size: 16 689 - Name: .stack_sizes 690 Type: SHT_PROGBITS 691 Entries: 692 - Size: 0 693 Link: .text 694 - Name: .rela.stack_sizes 695 Type: SHT_RELA 696 Info: .stack_sizes 697 Relocations: 698 - Offset: 0 699 Symbol: foo 700 Type: R_X86_64_64 701Symbols: 702 - Name: foo 703 Section: .text 704 Type: STT_OBJECT 705 Binding: STB_GLOBAL 706 707## Check that we report a warning when we find an unsupported relocation 708## in the section that contains the stack size entries' relocations. 709 710# RUN: yaml2obj --docnum=10 %s -o %t15 711# RUN: llvm-readelf --stack-sizes %t15 2>&1 | FileCheck %s --check-prefix=UNSUPPRELOC-GNU -DFILE=%t15 712# RUN: llvm-readobj --stack-sizes %t15 2>&1 | FileCheck %s --check-prefix=UNSUPPRELOC-LLVM -DFILE=%t15 713 714# UNSUPPRELOC-GNU: Stack Sizes: 715# UNSUPPRELOC-GNU-NEXT: Size Function 716# UNSUPPRELOC-GNU-NEXT: warning: '[[FILE]]': SHT_RELA section with index 3 contains an unsupported relocation with index 1: R_X86_64_RELATIVE 717# UNSUPPRELOC-GNU-NEXT: 0 foo 718# UNSUPPRELOC-GNU-NEXT: warning: '[[FILE]]': SHT_RELA section with index 3 contains an unsupported relocation with index 3: R_X86_64_RELATIVE 719 720# UNSUPPRELOC-LLVM: StackSizes [ 721# UNSUPPRELOC-LLVM-NEXT: warning: '[[FILE]]': SHT_RELA section with index 3 contains an unsupported relocation with index 1: R_X86_64_RELATIVE 722# UNSUPPRELOC-LLVM-NEXT: Entry { 723# UNSUPPRELOC-LLVM-NEXT: Function: foo 724# UNSUPPRELOC-LLVM-NEXT: Size: 0x0 725# UNSUPPRELOC-LLVM-NEXT: } 726# UNSUPPRELOC-LLVM-NEXT: warning: '[[FILE]]': SHT_RELA section with index 3 contains an unsupported relocation with index 3: R_X86_64_RELATIVE 727# UNSUPPRELOC-LLVM-NEXT: ] 728 729--- !ELF 730FileHeader: 731 Class: ELFCLASS64 732 Data: ELFDATA2LSB 733 Type: ET_REL 734 Machine: EM_X86_64 735Sections: 736 - Name: .text 737 Type: SHT_PROGBITS 738 Size: 8 739 - Name: .stack_sizes 740 Type: SHT_PROGBITS 741 Link: .text 742 Entries: 743 - Size: 0 744 - Name: .rela.stack_sizes 745 Type: SHT_RELA 746 Info: .stack_sizes 747 Relocations: 748 - Offset: 0 749 Symbol: foo 750 Type: R_X86_64_RELATIVE 751 - Offset: 0 752 Symbol: foo 753 Type: R_X86_64_64 754 - Offset: 0 755 Symbol: foo 756 Type: R_X86_64_RELATIVE 757Symbols: 758 - Name: foo 759 Section: .text 760 Type: STT_FUNC 761 Binding: STB_GLOBAL 762 763## Check that warning messages in archives do not impact other members. In the following 764## test, the first archive member generates a warning and we make sure all the information 765## is still dumped. 766 767# RUN: llvm-ar rc %t2.a %t04 %t01 768# RUN: llvm-readelf --stack-sizes %t2.a 2>&1 | FileCheck %s --check-prefix=ARCHIVEWARN-GNU \ 769# RUN: -DFILE=%t2.a --strict-whitespace --match-full-lines 770# RUN: llvm-readobj --stack-sizes %t2.a 2>&1 | FileCheck %s --check-prefix=ARCHIVEWARN-LLVM -DFILE=%t2.a 771 772# ARCHIVEWARN-GNU:File: [[FILE]]({{.*04}}) 773# ARCHIVEWARN-GNU:Stack Sizes: 774# ARCHIVEWARN-GNU-NEXT: Size Function 775# ARCHIVEWARN-GNU:{{.*}}: warning: '{{.*04}}': relocation symbol '_Z3foof' is not in the expected section 776# ARCHIVEWARN-GNU: 8 _Z3foof 777# ARCHIVEWARN-GNU:File: [[FILE]]({{.*01}}) 778# ARCHIVEWARN-GNU:Stack Sizes: 779# ARCHIVEWARN-GNU-NEXT: Size Function 780# ARCHIVEWARN-GNU-NEXT: 16 referenced_by_symbol_foo 781# ARCHIVEWARN-GNU-NEXT: 32 referenced_via_section_bar 782# ARCHIVEWARN-GNU-NEXT: 8 separate_text_section_baz 783# ARCHIVEWARN-GNU-NOT:{{.}} 784 785 786# ARCHIVEWARN-LLVM: File: [[FILE]]({{.*04}}) 787# ARCHIVEWARN-LLVM: StackSizes [ 788# ARCHIVEWARN-LLVM: warning: '{{.*04}}': relocation symbol '_Z3foof' is not in the expected section 789# ARCHIVEWARN-LLVM-NEXT: Entry { 790# ARCHIVEWARN-LLVM-NEXT: Function: _Z3foof 791# ARCHIVEWARN-LLVM-NEXT: Size: 0x8 792# ARCHIVEWARN-LLVM-NEXT: } 793# ARCHIVEWARN-LLVM-NEXT: ] 794# ARCHIVEWARN-LLVM: File: [[FILE]]({{.*01}}) 795# ARCHIVEWARN-LLVM: StackSizes [ 796# ARCHIVEWARN-LLVM-NEXT: Entry { 797# ARCHIVEWARN-LLVM-NEXT: Function: referenced_by_symbol_foo 798# ARCHIVEWARN-LLVM-NEXT: Size: 0x10 799# ARCHIVEWARN-LLVM-NEXT: } 800# ARCHIVEWARN-LLVM-NEXT: Entry { 801# ARCHIVEWARN-LLVM-NEXT: Function: referenced_via_section_bar 802# ARCHIVEWARN-LLVM-NEXT: Size: 0x20 803# ARCHIVEWARN-LLVM-NEXT: } 804# ARCHIVEWARN-LLVM-NEXT: Entry { 805# ARCHIVEWARN-LLVM-NEXT: Function: separate_text_section_baz 806# ARCHIVEWARN-LLVM-NEXT: Size: 0x8 807# ARCHIVEWARN-LLVM-NEXT: } 808# ARCHIVEWARN-LLVM-NEXT: ] 809 810## Check that we demangle function names when requested. 811 812# RUN: yaml2obj --docnum=11 %s -o %t16 813# RUN: llvm-readelf --stack-sizes --demangle %t16 | FileCheck %s --check-prefix=DEMANGLE-GNU 814# RUN: llvm-readobj --stack-sizes --demangle %t16 | FileCheck %s --check-prefix=DEMANGLE-LLVM 815 816# DEMANGLE-GNU: 16 foo(float) 817# DEMANGLE-LLVM: Function: foo(float) 818 819--- !ELF 820FileHeader: 821 Class: ELFCLASS64 822 Data: ELFDATA2LSB 823 Type: ET_EXEC 824Sections: 825 - Name: .text 826 Type: SHT_PROGBITS 827 Flags: [SHF_ALLOC] 828 Size: 16 829 - Name: .stack_sizes 830 Type: SHT_PROGBITS 831 Entries: 832 - Address: 0x10 833 Size: 0x10 834 Link: .text 835Symbols: 836 - Name: _Z3foof 837 Section: .text 838 Value: 0x10 839 Type: STT_FUNC 840 Binding: STB_GLOBAL 841 842## Check that we report a warning when we are unable to resolve a relocation for a given ELF architecture. 843## Here we have a 64-bit relocation used in a 32-bit object. 844 845# RUN: yaml2obj --docnum=12 %s -o %t17 846# RUN: llvm-readelf --stack-sizes %t17 2>&1 | FileCheck %s -DFILE=%t17 --check-prefix=UNSUPPRELOC2 847# RUN: llvm-readobj --stack-sizes %t17 2>&1 | FileCheck %s -DFILE=%t17 --check-prefix=UNSUPPRELOC2 848 849# UNSUPPRELOC2: warning: '[[FILE]]': SHT_RELA section with index 2 contains an unsupported relocation with index 1: R_X86_64_64 850 851--- !ELF 852FileHeader: 853 Class: ELFCLASS32 854 Data: ELFDATA2MSB 855 Type: ET_REL 856 Machine: EM_X86_64 857Sections: 858 - Name: .stack_sizes 859 Type: SHT_PROGBITS 860 Content: "00" 861 - Name: .rela.stack_sizes 862 Type: SHT_RELA 863 Info: .stack_sizes 864 Relocations: 865 - Offset: 0 866 Type: R_X86_64_64 867 868## Check we report a warning when dumping stack sizes if the relocated section 869## identified by the sh_info field is invalid. Here the sh_info value is larger than 870## the number of sections. 871 872# RUN: yaml2obj --docnum=13 %s -o %t18 873# RUN: llvm-readelf --stack-sizes %t18 2>&1 | \ 874# RUN: FileCheck %s --implicit-check-not="warning:" -DFILE=%t18 --check-prefix=INVALID-TARGET 875# RUN: llvm-readobj --stack-sizes %t18 2>&1 | \ 876# RUN: FileCheck %s --implicit-check-not="warning:" -DFILE=%t18 --check-prefix=INVALID-TARGET 877 878# INVALID-TARGET: warning: '[[FILE]]': SHT_RELA section with index 1: failed to get a relocated section: invalid section index: 255 879# INVALID-TARGET: warning: '[[FILE]]': SHT_RELA section with index 2: failed to get a relocated section: invalid section index: 255 880 881--- !ELF 882FileHeader: 883 Class: ELFCLASS32 884 Data: ELFDATA2MSB 885 Type: ET_REL 886Sections: 887 - Name: .rela.stack_sizes 888 Type: SHT_RELA 889 Link: 0 890 Info: 0xFF 891 Relocations: [] 892 - Name: .rela.stack_sizes (1) 893 Type: SHT_RELA 894 Link: 0 895 Info: 0xFF 896 Relocations: [] 897