1## Check that llvm-objdump reports an error when 2## .shstrtab has an invalid type. 3 4# RUN: yaml2obj %s --docnum=1 -o %t1 5# RUN: not llvm-objdump -s %t1 2>&1 | FileCheck %s -DFILE=%t1 --check-prefix=INVALID-SHTYPE 6 7# INVALID-SHTYPE: error: '[[FILE]]': invalid sh_type for string table section [index 1]: expected SHT_STRTAB, but got SHT_PROGBITS 8 9--- !ELF 10FileHeader: 11 Class: ELFCLASS64 12 Data: ELFDATA2LSB 13 Type: ET_DYN 14 Machine: EM_X86_64 15Sections: 16 - Name: .shstrtab 17 Type: SHT_PROGBITS 18 19## Check that llvm-objdump reports an error when 20## .shstrtab has an invalid zero-size. 21 22# RUN: yaml2obj %s --docnum=2 -o %t2 23# RUN: not llvm-objdump -s %t2 2>&1 | FileCheck %s -DFILE=%t2 --check-prefix=STRTAB-EMPTY 24 25# STRTAB-EMPTY: error: '[[FILE]]': SHT_STRTAB string table section [index 1] is empty 26 27--- !ELF 28FileHeader: 29 Class: ELFCLASS64 30 Data: ELFDATA2LSB 31 Type: ET_DYN 32 Machine: EM_X86_64 33Sections: 34 - Name: .shstrtab 35 Type: SHT_STRTAB 36 Size: 0 37 38## Check that llvm-objdump reports an error when .shstrtab has an invalid 39## size that goes past the end of the file. 40 41# RUN: not llvm-objdump -s %p/Inputs/invalid-strtab-size.elf 2>&1 \ 42# RUN: | FileCheck %s -DFILE=%p/Inputs/invalid-strtab-size.elf --check-prefix=INVALID-STRTAB-SIZE 43 44# INVALID-STRTAB-SIZE: error: '[[FILE]]': section [index 1] has a sh_offset (0x70) + sh_size (0xffffff) that is greater than the file size (0x218) 45 46## Document that llvm-dwarfdump doesn't reports errors/warnings during relocation resolution 47## when instead of SHT_RELA section we have a SHT_REL section in an object. 48## In this case it just doesn't try to read relocation addends and assumes they are 0. 49 50## Note: we don't check the output, because the intention of this test is just to check the 51## exit code and to document the fact that no warnings are reported. 52# RUN: yaml2obj %s --docnum=3 -o %t3 53# RUN: llvm-dwarfdump -debug-line %t3 2>&1 | FileCheck --implicit-check-not=warning: %s 54 55--- !ELF 56FileHeader: 57 Class: ELFCLASS64 58 Data: ELFDATA2LSB 59 Type: ET_REL 60 Machine: EM_X86_64 61Sections: 62 - Name: .debug_line 63 Type: SHT_PROGBITS 64## The exact content does not matter here. We can use any minimal valid debug section 65## which is a target for relocation. The idea is to trigger the code that reads the 66## relocation's addend during relocation resolution. It should fail if called on 67## a non-SHT_RELA section. 68 Content: 380000000200210000000101FB0E0D00010101010000000100000100676C6F62616C2E63707000000000000009020000000000000000130237000101 69 - Name: .rela.debug_line 70 Type: SHT_REL 71 Info: .debug_line 72 Relocations: 73 - Offset: 0x000000000000002E 74 Type: R_X86_64_64 75 76## Check that llvm-objdump reports an error when it tries to dump section names 77## and .shstrtab is not null-terminated. 78 79# RUN: yaml2obj %s --docnum=4 -o %t4 80# RUN: not llvm-objdump -s %t4 2>&1 | FileCheck -DFILE=%t4 --check-prefix=SHSTRTAB-NON-TERM %s 81 82# SHSTRTAB-NON-TERM: error: '[[FILE]]': SHT_STRTAB string table section [index 1] is non-null terminated 83 84--- !ELF 85FileHeader: 86 Class: ELFCLASS64 87 Data: ELFDATA2LSB 88 Type: ET_DYN 89 Machine: EM_X86_64 90Sections: 91 - Name: .shstrtab 92 Type: SHT_STRTAB 93 Content: "11" 94 95## Check that llvm-objdump reports an error when it tries to dump a symbol name and 96## .strtab is not null-terminated. 97 98# RUN: yaml2obj %s --docnum=5 -o %t5 99# RUN: not llvm-objdump --syms %t5 2>&1 | FileCheck --check-prefix=NONULL %s 100 101# NONULL: error: {{.*}}: SHT_STRTAB string table section [index 1] is non-null terminated 102 103--- !ELF 104FileHeader: 105 Class: ELFCLASS64 106 Data: ELFDATA2LSB 107 Type: ET_DYN 108 Machine: EM_X86_64 109Sections: 110 - Name: .strtab 111 Type: SHT_STRTAB 112 Content: "11" 113Symbols: 114 - Name: foo 115 116## Check that llvm-readobj reports an error if .symtab has an invalid sh_entsize. 117 118# RUN: yaml2obj %s --docnum=6 -o %t6 119# RUN: llvm-readobj --symbols %t6 2>&1 | FileCheck -DFILE=%t6 --check-prefix=INVALID-SYM-SIZE %s 120 121# INVALID-SYM-SIZE: warning: '[[FILE]]': unable to read symbols from the SHT_SYMTAB section: section [index 1] has an invalid sh_entsize: 32 122 123--- !ELF 124FileHeader: 125 Class: ELFCLASS64 126 Data: ELFDATA2LSB 127 Type: ET_DYN 128 Machine: EM_X86_64 129Sections: 130 - Name: .symtab 131 Type: SHT_SYMTAB 132 EntSize: 32 133Symbols: 134 - Name: foo 135 136## Check that llvm-readobj reports a warning if .dynsym has an invalid sh_entsize. 137 138# RUN: yaml2obj %s --docnum=7 -o %t7 139# RUN: llvm-readobj --dyn-symbols %t7 2>&1 | FileCheck -DFILE=%t7 --check-prefix=INVALID-DYNSYM-SIZE %s 140 141# INVALID-DYNSYM-SIZE: warning: '[[FILE]]': SHT_DYNSYM section with index 1 has invalid size (0x30) or entry size (0x20) 142 143--- !ELF 144FileHeader: 145 Class: ELFCLASS64 146 Data: ELFDATA2LSB 147 Type: ET_DYN 148 Machine: EM_X86_64 149Sections: 150 - Name: .dynsym 151 Type: SHT_DYNSYM 152 EntSize: 32 153DynamicSymbols: 154 - Name: foo 155 156## Check that llvm-readobj reports a warning if .symtab has an invalid sh_link value, 157## which is greater than number of sections. 158 159# RUN: yaml2obj %s --docnum=8 -o %t8 160# RUN: llvm-readobj --symbols %t8 2>&1 | FileCheck -DFILE=%t8 --check-prefix=INVALID-SYMTAB-LINK %s 161 162# INVALID-SYMTAB-LINK: warning: '[[FILE]]': unable to get the string table for the SHT_SYMTAB section: invalid section index: 255 163 164--- !ELF 165FileHeader: 166 Class: ELFCLASS64 167 Data: ELFDATA2LSB 168 Type: ET_REL 169 Machine: EM_X86_64 170Sections: 171 - Name: .symtab 172 Type: SHT_SYMTAB 173 Link: 0xFF 174 175## Check that llvm-readobj reports an error when trying to dump sections 176## when the e_shentsize field is broken. 177 178# RUN: yaml2obj %s --docnum=9 -o %t9 179# RUN: not llvm-readobj -S %t9 2>&1 | \ 180# RUN: FileCheck -DFILE=%t9 --implicit-check-not=warning: --check-prefix=INVALID-SH-ENTSIZE %s 181 182# INVALID-SH-ENTSIZE: LoadName: <Not found> 183# INVALID-SH-ENTSIZE-NEXT: error: '[[FILE]]': unable to continue dumping, the file is corrupt: invalid e_shentsize in ELF header: 1 184 185--- !ELF 186FileHeader: 187 Class: ELFCLASS64 188 Data: ELFDATA2LSB 189 Type: ET_REL 190 Machine: EM_X86_64 191 EShEntSize: 1 192 193## Check that llvm-readobj reports a warning if .symtab has sh_size 194## that is not a multiple of sh_entsize. 195 196# RUN: yaml2obj %s --docnum=10 -o %t10 197# RUN: llvm-readobj --symbols %t10 2>&1 | FileCheck -DFILE=%t10 --check-prefix=INVALID-SYMTAB-SIZE %s 198 199# INVALID-SYMTAB-SIZE: warning: '[[FILE]]': unable to read symbols from the SHT_SYMTAB section: section [index 1] has an invalid sh_size (1) which is not a multiple of its sh_entsize (24) 200 201--- !ELF 202FileHeader: 203 Class: ELFCLASS64 204 Data: ELFDATA2LSB 205 Type: ET_DYN 206 Machine: EM_X86_64 207Sections: 208 - Name: .symtab 209 Type: SHT_SYMTAB 210 Size: 1 211 212## Test that llvm-readobj reports an error if SHT_SYMTAB_SHNDX section has 213## invalid sh_size which should be: 214## sizeof(.symtab_shndx) = (sizeof(.symtab) / entsize(.symtab)) * entsize(.symtab_shndx) 215 216# RUN: yaml2obj %s --docnum=11 -o %t11 217# RUN: llvm-readobj --symbols %t11 2>&1 | FileCheck --check-prefix=INVALID-XINDEX-SIZE %s 218 219# INVALID-XINDEX-SIZE: warning: {{.*}}: SHT_SYMTAB_SHNDX has 2 entries, but the symbol table associated has 1 220 221--- !ELF 222FileHeader: 223 Class: ELFCLASS64 224 Data: ELFDATA2LSB 225 Type: ET_DYN 226 Machine: EM_X86_64 227Sections: 228 - Name: .symtab_shndx 229 Type: SHT_SYMTAB_SHNDX 230 Entries: [ 0, 1 ] 231 Link: .symtab 232Symbols: [] 233 234## Check that llvm-readobj reports a warning when the e_phentsize field is broken. 235 236# RUN: llvm-readobj --program-headers %p/Inputs/invalid-e_shnum.elf 2>&1 | \ 237# RUN: FileCheck -DFILE=%p/Inputs/invalid-e_shnum.elf --check-prefix=INVALID-PH-ENTSIZE %s 238 239# INVALID-PH-ENTSIZE: warning: '[[FILE]]': unable to dump program headers: invalid e_phentsize: 12336 240 241## Check that llvm-readobj reports a warning when we have no SHT_SYMTAB_SHNDX section, 242## but have a symbol referencing it. 243 244# RUN: llvm-readobj --symbols %p/Inputs/invalid-ext-symtab-index.elf-x86-64 2>&1 | \ 245# RUN: FileCheck -DFILE=%p/Inputs/invalid-ext-symtab-index.elf-x86-64 --check-prefix=INVALID-EXT-SYMTAB-INDEX %s 246 247# INVALID-EXT-SYMTAB-INDEX: warning: '[[FILE]]': extended symbol index (0) is past the end of the SHT_SYMTAB_SHNDX section of size 0 248# INVALID-EXT-SYMTAB-INDEX: Section: Reserved (0xFFFF) 249 250## Check that llvm-readobj reports an error if a relocation section 251## has a broken sh_offset (past the end of the file). 252 253# RUN: yaml2obj %s --docnum=12 -o %t12 254# RUN: yaml2obj %s --docnum=13 -o %t13 255# RUN: llvm-readobj -r %t12 2>&1 | FileCheck -DFILE=%t12 --check-prefix=INVALID-RELOC-SH-OFFSET -DTYPE=SHT_REL %s 256# RUN: llvm-readobj -r %t13 2>&1 | FileCheck -DFILE=%t13 --check-prefix=INVALID-RELOC-SH-OFFSET -DTYPE=SHT_RELA %s 257 258# INVALID-RELOC-SH-OFFSET: warning: '[[FILE]]': unable to read relocations from [[TYPE]] section with index 1: section [index 1] has a sh_offset (0x10000) + sh_size (0x0) that is greater than the file size (0x160) 259 260--- !ELF 261FileHeader: 262 Class: ELFCLASS64 263 Data: ELFDATA2LSB 264 Type: ET_REL 265 Machine: EM_386 266Sections: 267 - Name: .rel 268 Type: SHT_REL 269 ShOffset: 0x10000 270 271--- !ELF 272FileHeader: 273 Class: ELFCLASS64 274 Data: ELFDATA2LSB 275 Type: ET_REL 276 Machine: EM_X86_64 277Sections: 278 - Name: .rela 279 Type: SHT_RELA 280 ShOffset: 0x10000 281 282## Check that llvm-readobj reports a warning when we try to print section symbols and 283## .shstrtab has a broken sh_offset so large that sh_offset + sh_size overflows the platform address size type. 284 285# RUN: yaml2obj %s --docnum=14 -o %t14 286# RUN: llvm-readobj --symbols %t14 2>&1 | FileCheck -DFILE=%t14 --check-prefix=INVALID-SECTION-SIZE2 %s 287 288# INVALID-SECTION-SIZE2: Symbol { 289# INVALID-SECTION-SIZE2: Name: symbol (1) 290# INVALID-SECTION-SIZE2-NEXT: Value: 0x123 291# INVALID-SECTION-SIZE2-NEXT: Size: 0 292# INVALID-SECTION-SIZE2-NEXT: Binding: Local (0x0) 293# INVALID-SECTION-SIZE2-NEXT: Type: None (0x0) 294# INVALID-SECTION-SIZE2-NEXT: Other: 0 295# INVALID-SECTION-SIZE2-NEXT: warning: '[[FILE]]': section [index 1] has a sh_offset (0xffffffff) + sh_size (0x1b) that cannot be represented 296# INVALID-SECTION-SIZE2-NEXT: Section: <?> (0x1) 297# INVALID-SECTION-SIZE2-NEXT: } 298 299--- !ELF 300FileHeader: 301 Class: ELFCLASS32 302 Data: ELFDATA2LSB 303 Type: ET_REL 304 Machine: EM_386 305Sections: 306 - Name: .shstrtab 307 Type: SHT_STRTAB 308 ShOffset: 0xFFFFFFFF 309Symbols: 310 - Name: symbol 311 Section: .shstrtab 312 Value: 0x123 313 314## Check that llvm-readobj reports an error when trying to dump sections 315## when the e_shnum field is broken (is greater than the actual number of sections). 316 317# RUN: yaml2obj %s --docnum=15 -o %t15 318# RUN: not llvm-readobj -S %t15 2>&1 | \ 319# RUN: FileCheck -DFILE=%t15 --implicit-check-not=warning: --check-prefix=INVALID-SECTION-NUM %s 320 321# INVALID-SECTION-NUM: LoadName: <Not found> 322# INVALID-SECTION-NUM-NEXT: error: '[[FILE]]': unable to continue dumping, the file is corrupt: section table goes past the end of file 323 324--- !ELF 325FileHeader: 326 Class: ELFCLASS64 327 Data: ELFDATA2LSB 328 Type: ET_REL 329 Machine: EM_X86_64 330 EShNum: 0xFF 331 332## Check llvm-readobj does not crash on a truncated ELF. 333 334## Create a truncated ELF object with ELFCLASSNONE class using echo. 335## 0x7f, 'E', 'L', 'F', ELFCLASS64(2), ELFDATA2LSB(1), 336## EV_CURRENT(1), ELFOSABI_LINUX(3), <padding zero bytes>, ET_REL(1), EM_NONE(0) 337# RUN: echo -e -n "\x7f\x45\x4c\x46\x02\x01\x01\x03\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00" > %t11 338# RUN: not llvm-readobj -r %t11 2>&1 | FileCheck --check-prefix=INVALID-BUFFER %s 339 340# INVALID-BUFFER: error: {{.*}}': invalid buffer: the size (18) is smaller than an ELF header (64) 341 342# RUN: not llvm-readobj %p/Inputs/invalid-coff-header-too-small 2>&1 | FileCheck --check-prefix=COFF-HEADER %s 343# COFF-HEADER: The file was not recognized as a valid object file 344 345## Check that llvm-readobj reports an error if section name offset 346## overflows the section name string table. 347 348# RUN: yaml2obj %s --docnum=16 -o %t16 349# RUN: llvm-readobj --sections %t16 2>&1 | FileCheck -DFILE=%t16 --check-prefix=BROKEN-SECNAME %s 350 351## BROKEN-SECNAME: warning: '[[FILE]]': unable to get the name of SHT_STRTAB section with index 2: a section [index 2] has an invalid sh_name (0xb) offset which goes past the end of the section name string table 352 353--- !ELF 354FileHeader: 355 Class: ELFCLASS64 356 Data: ELFDATA2LSB 357 Type: ET_REL 358 Machine: EM_X86_64 359Sections: 360 - Name: .shstrtab 361 Type: SHT_STRTAB 362 Size: 1 363 364## Check that llvm-readobj reports an error if a section has a broken offset 365## that goes past the end of the file. 366 367# RUN: yaml2obj %s --docnum=17 -o %t17 368# RUN: not llvm-readobj --sections --section-data %t17 2>&1 \ 369# RUN: | FileCheck -DFILE=%t17 --check-prefix=BROKEN-SECSHOFFSET %s 370 371# BROKEN-SECSHOFFSET: error: '[[FILE]]': section [index 1] has a sh_offset (0xffff0000) + sh_size (0x0) that is greater than the file size (0x160) 372 373--- !ELF 374FileHeader: 375 Class: ELFCLASS64 376 Data: ELFDATA2LSB 377 Type: ET_REL 378 Machine: EM_X86_64 379Sections: 380 - Name: .foo 381 Type: SHT_PROGBITS 382 ShOffset: 0xFFFF0000 383 384## Check that llvm-readobj reports a warning if symbol name 385## offset goes past the end of the symbol string table. 386 387# RUN: yaml2obj %s --docnum=18 -o %t18 388# RUN: llvm-readobj --symbols %t18 2>&1 | FileCheck -DFILE=%t18 --check-prefix=INVALID-SYM-NAME %s 389 390# INVALID-SYM-NAME: warning: '[[FILE]]': st_name (0x1) is past the end of the string table of size 0x1 391 392--- !ELF 393FileHeader: 394 Class: ELFCLASS64 395 Data: ELFDATA2LSB 396 Type: ET_REL 397 Machine: EM_X86_64 398Sections: 399 - Name: .strtab 400 Type: SHT_STRTAB 401 Size: 1 402Symbols: 403 - Name: foo 404 405## Version index in .gnu.version overflows the version map. 406## Check llvm-readobj reports it. 407 408# RUN: yaml2obj %s --docnum=19 -o %t19 409# RUN: llvm-readobj -dt %t19 2>&1 | FileCheck -DFILE=%t19 --check-prefix=INVALID-VERSION %s 410 411# INVALID-VERSION: warning: '[[FILE]]': SHT_GNU_versym section refers to a version index 255 which is missing 412 413--- !ELF 414FileHeader: 415 Class: ELFCLASS64 416 Data: ELFDATA2LSB 417 Type: ET_DYN 418 Machine: EM_X86_64 419Sections: 420 - Name: .gnu.version 421 Type: SHT_GNU_versym 422 Entries: [ 0xFF ] 423DynamicSymbols: 424 - Name: foo 425 426## ELF header contains e_phentsize field with a value != sizeof(Elf_Phdr). 427## Check llvm-readobj reports it. 428 429# RUN: llvm-readobj -l %p/Inputs/corrupt-invalid-phentsize.elf.x86-64 2>&1 \ 430# RUN: | FileCheck -DFILE=%p/Inputs/corrupt-invalid-phentsize.elf.x86-64 --check-prefix=PHENTSIZE %s 431 432# PHENTSIZE: warning: '[[FILE]]': unable to read program headers to locate the PT_DYNAMIC segment: invalid e_phentsize: 57 433 434## The dynamic table contains DT_STRTAB with a value that is not in any loadable segment. 435## Check llvm-readobj reports it. 436 437# RUN: yaml2obj %s --docnum=20 -o %t20 438# RUN: llvm-readobj --dynamic-table %t20 2>&1 | FileCheck -DFILE=%t20 --check-prefix=INVALID-DTSTRTAB %s 439 440# INVALID-DTSTRTAB: warning: '[[FILE]]': unable to parse DT_STRTAB: virtual address is not in any segment: 0xffff0000 441 442--- !ELF 443FileHeader: 444 Class: ELFCLASS64 445 Data: ELFDATA2LSB 446 Type: ET_EXEC 447 Machine: EM_X86_64 448Sections: 449 - Name: .dynamic 450 Type: SHT_DYNAMIC 451 Address: 0x1000 452 Entries: 453 - Tag: DT_STRTAB 454 Value: 0xFFFF0000 455 - Tag: DT_NULL 456 Value: 0x0 457ProgramHeaders: 458 - Type: PT_LOAD 459 VAddr: 0x1000 460 FirstSec: .dynamic 461 LastSec: .dynamic 462 463## Check that llvm-readobj reports a warning when a dynamic relocation section 464## has sh_entsize field with size != sizeof(Elf_Rela). 465 466# RUN: llvm-readobj --dyn-relocations \ 467# RUN: %p/Inputs/corrupt-invalid-relocation-size.elf.x86-64 2>&1 \ 468# RUN: | FileCheck -DFILE=%p/Inputs/corrupt-invalid-relocation-size.elf.x86-64 --check-prefix=RELOC-BROKEN-ENTSIZE %s 469 470# RELOC-BROKEN-ENTSIZE: warning: '[[FILE]]': invalid DT_RELASZ value (0x18) or DT_RELAENT value (0x19) 471 472## Check that llvm-readobj reports a warning when .dynamic section has an invalid 473## size, which isn't a multiple of the dynamic entry size. 474 475# RUN: yaml2obj %s --docnum=21 -o %t21 476# RUN: llvm-readobj --dyn-relocations %t21 2>&1 | FileCheck -DFILE=%t21 --check-prefix=DYN-TABLE-SIZE %s 477 478# DYN-TABLE-SIZE: warning: '[[FILE]]': SHT_DYNAMIC section with index 1 has invalid size (0x1){{$}} 479 480--- !ELF 481FileHeader: 482 Class: ELFCLASS64 483 Data: ELFDATA2LSB 484 Type: ET_EXEC 485 Machine: EM_X86_64 486Sections: 487 - Name: .dynamic 488 Type: SHT_DYNAMIC 489 Content: "00" 490 491## PT_DYNAMIC's p_offset field is so large that p_offset + p_filesz is larger 492## than the object size. Check llvm-readobj reports it. 493 494# RUN: yaml2obj %s --docnum=22 -o %t22 495# RUN: llvm-readobj --dyn-relocations %t22 2>&1 | FileCheck -DFILE=%t22 --check-prefix=DYN-TABLE-PHDR %s 496 497# DYN-TABLE-PHDR: warning: '[[FILE]]': PT_DYNAMIC segment offset (0xffff0000) + file size (0x0) exceeds the size of the file (0x150) 498 499--- !ELF 500FileHeader: 501 Class: ELFCLASS64 502 Data: ELFDATA2LSB 503 Type: ET_EXEC 504 Machine: EM_X86_64 505ProgramHeaders: 506 - Type: PT_DYNAMIC 507 Offset: 0xffff0000 508 509## PT_DYNAMIC's p_filesz field is so large that p_offset + p_filesz is larger 510## than the object size. Check llvm-readobj reports it. 511 512# RUN: yaml2obj %s --docnum=23 -o %t23 513# RUN: llvm-readobj --dyn-relocations %t23 2>&1 \ 514# RUN: | FileCheck -DFILE=%t23 --check-prefix=DYN-TABLE-PHDR2 %s 515 516# DYN-TABLE-PHDR2: warning: '[[FILE]]': PT_DYNAMIC segment offset (0x78) + file size (0xffff0000) exceeds the size of the file (0x1a8) 517 518--- !ELF 519FileHeader: 520 Class: ELFCLASS64 521 Data: ELFDATA2LSB 522 Type: ET_EXEC 523 Machine: EM_X86_64 524Sections: 525 - Name: .dynamic 526 Type: SHT_DYNAMIC 527 Entries: 528 - Tag: DT_NULL 529 Value: 0 530ProgramHeaders: 531 - Type: PT_DYNAMIC 532 FileSize: 0xffff0000 533 FirstSec: .dynamic 534 LastSec: .dynamic 535 536# RUN: yaml2obj --docnum=24 %s -o %t24 537# RUN: not obj2yaml 2>&1 %t24 | FileCheck %s -DFILE=%t24 --check-prefix=INVALID-SHSTRNDX 538 539# INVALID-SHSTRNDX: Error reading file: [[FILE]]: section header string table index 255 does not exist 540 541--- !ELF 542FileHeader: 543 Class: ELFCLASS64 544 Data: ELFDATA2LSB 545 Type: ET_REL 546 Machine: EM_X86_64 547 EShStrNdx: 0xFF 548Sections: 549 - Name: .foo 550 Type: SHT_PROGBITS 551 552## We report an error if the number of sections stored in sh_size 553## is greater than UINT64_MAX / sizeof(Elf_Shdr) == 288230376151711743. 554## Here we check that do not crash on a border value. 555 556# RUN: yaml2obj --docnum=25 %s -o %t25 557# RUN: not llvm-readobj -h %t25 2>&1 | FileCheck -DFILE=%t25 --check-prefix=INVALID-SEC-NUM1 %s 558 559# INVALID-SEC-NUM1: error: '[[FILE]]': unable to continue dumping, the file is corrupt: invalid section header table offset (e_shoff = 0x58) or invalid number of sections specified in the first section header's sh_size field (0x3ffffffffffffff) 560 561--- !ELF 562FileHeader: 563 Class: ELFCLASS64 564 Data: ELFDATA2LSB 565 Type: ET_REL 566 Machine: EM_X86_64 567 EShNum: 0x0 568Sections: 569 - Type: SHT_NULL 570 Size: 288230376151711743 571 572## See above, but now we test the UINT64_MAX / sizeof(Elf_Shdr) value. 573## The error is slightly different in this case. 574 575# RUN: yaml2obj --docnum=26 %s -o %t26 576# RUN: not llvm-readobj -h %t26 2>&1 | FileCheck -DFILE=%t26 --check-prefix=INVALID-SEC-NUM2 %s 577 578# INVALID-SEC-NUM2: error: '[[FILE]]': unable to continue dumping, the file is corrupt: invalid number of sections specified in the NULL section's sh_size field (288230376151711744) 579 580--- !ELF 581FileHeader: 582 Class: ELFCLASS64 583 Data: ELFDATA2LSB 584 Type: ET_REL 585 Machine: EM_X86_64 586 EShNum: 0x0 587Sections: 588 - Type: SHT_NULL 589 Size: 288230376151711744 590 591## Check the case when SHOff is too large. SHOff + sizeof(Elf_Shdr) overflows the uint64 type. 592 593# RUN: yaml2obj --docnum=27 %s -o %t27 594# RUN: not llvm-readobj -h %t27 2>&1 | FileCheck -DFILE=%t27 --check-prefix=INVALID-SEC-NUM3 %s 595 596# INVALID-SEC-NUM3: error: '[[FILE]]': unable to continue dumping, the file is corrupt: section header table goes past the end of the file: e_shoff = 0xffffffffffffffff 597 598--- !ELF 599FileHeader: 600 Class: ELFCLASS64 601 Data: ELFDATA2LSB 602 Type: ET_REL 603 Machine: EM_X86_64 604 EShOff: 0xffffffffffffffff 605 606## Check that llvm-objdump reports an error when it tries to dump a 607## symbol name and .strtab is empty. 608 609# RUN: yaml2obj %s --docnum=28 -o %t28 610# RUN: not llvm-objdump --syms %t28 2>&1 | FileCheck -DFILE=%t28 --check-prefix=STRTAB-EMPTY2 %s 611 612# STRTAB-EMPTY2: error: '[[FILE]]': SHT_STRTAB string table section [index 1] is empty 613 614--- !ELF 615FileHeader: 616 Class: ELFCLASS64 617 Data: ELFDATA2LSB 618 Type: ET_DYN 619 Machine: EM_X86_64 620Sections: 621 - Name: .strtab 622 Type: SHT_STRTAB 623 Content: "" 624Symbols: 625 - Name: foo 626 627## Check that we report a warning if SHT_GNU_versym has invalid 628## sh_entsize value (3 instead of 2) when trying to access the entries. 629 630# RUN: yaml2obj %s --docnum=29 -o %t29 631# RUN: llvm-readobj -V %t29 2>&1 | FileCheck -DFILE=%t29 --check-prefix=INVALID-VER-SHENTSIZE %s 632 633# INVALID-VER-SHENTSIZE: warning: '[[FILE]]': cannot read content of SHT_GNU_versym section with index 1: section [index 1] has an invalid sh_entsize: 3 634 635--- !ELF 636FileHeader: 637 Class: ELFCLASS64 638 Data: ELFDATA2LSB 639 OSABI: ELFOSABI_FREEBSD 640 Type: ET_DYN 641 Machine: EM_X86_64 642Sections: 643 - Name: .gnu.version 644 Type: SHT_GNU_versym 645 EntSize: 0x0000000000000003 646 Entries: [ ] 647 Link: .dynsym 648## Needed to trigger creation of .dynsym. 649DynamicSymbols: 650 - Name: foo 651 Binding: STB_GLOBAL 652 653## Check the case when e_shstrndx == SHN_XINDEX, but null section's sh_link contains 654## the index of a section header string table that is larger than the number of the sections. 655 656# RUN: yaml2obj --docnum=30 %s -o %t30 657# RUN: not llvm-objcopy %t30 2>&1 | FileCheck %s -DFILE=%t30 --check-prefix=INVALID-SHSTRTAB-INDEX 658 659# INVALID-SHSTRTAB-INDEX: error: section header string table index 255 does not exist 660 661--- !ELF 662FileHeader: 663 Class: ELFCLASS64 664 Data: ELFDATA2LSB 665 Type: ET_REL 666 Machine: EM_X86_64 667## SHN_XINDEX == 0xffff. 668 EShStrNdx: 0xffff 669Sections: 670 - Type: SHT_NULL 671 Link: 0xff 672 673## Check the case when the e_phoff field is invalid. 674# RUN: yaml2obj --docnum=31 %s -o %t31 675# RUN: not llvm-objdump --private-headers %t31 2>&1 | FileCheck -DFILE=%t31 %s --check-prefix=INVALID-PHOFF 676 677# INVALID-PHOFF: error: '[[FILE]]': program headers are longer than binary of size 280: e_phoff = 0xffffff, e_phnum = 0, e_phentsize = 0 678 679--- !ELF 680FileHeader: 681 Class: ELFCLASS64 682 Data: ELFDATA2LSB 683 Type: ET_EXEC 684 Machine: EM_X86_64 685 EPhOff: 0xffffff 686