1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554
|
## Check that llvm-objdump reports an error when
## .shstrtab has an invalid type.
# RUN: yaml2obj %s --docnum=1 -o %t1
# RUN: not llvm-objdump -s %t1 2>&1 | FileCheck %s --check-prefix=INVALIDERR
# INVALIDERR: error: reading file: Invalid data was encountered while parsing the file
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_DYN
Machine: EM_X86_64
Sections:
- Name: .shstrtab
Type: SHT_PROGBITS
## Check that llvm-objdump reports an error when
## .shstrtab has an invalid zero-size.
# RUN: yaml2obj %s --docnum=2 -o %t2
# RUN: not llvm-objdump -s %t2 2>&1 | FileCheck %s --check-prefix=INVALIDERR
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_DYN
Machine: EM_X86_64
Sections:
- Name: .shstrtab
Type: SHT_STRTAB
Size: 0
## Check that llvm-objdump reports an error when .shstrtab has an invalid
## size that goes past the end of the file.
# RUN: not llvm-objdump -s %p/Inputs/invalid-strtab-size.elf 2>&1 \
# RUN: | FileCheck %s --check-prefix=INVALIDERR
## Check that llvm-dwarfdump reports an error during relocation resolution
## when instead of expected SHT_RELA section it locates a section of a different type.
# RUN: yaml2obj %s --docnum=3 -o %t3
# RUN: not llvm-dwarfdump -debug-line %t3 2>&1 | FileCheck --check-prefix=RELA %s
# RELA: LLVM ERROR: Section is not SHT_RELA
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_REL
Machine: EM_X86_64
Sections:
- Name: .debug_line
Type: SHT_PROGBITS
## The exact content does not matter here. We can use any minimal valid debug section
## which is a target for relocation. The idea is to trigger the code that reads the
## relocation's addend during relocation resolution. It should fail if called on
## a non-SHT_RELA section.
Content: 380000000200210000000101FB0E0D00010101010000000100000100676C6F62616C2E63707000000000000009020000000000000000130237000101
- Name: .rela.debug_line
Type: SHT_REL
Info: .debug_line
Relocations:
- Offset: 0x000000000000002E
Type: R_X86_64_64
## Check that llvm-objdump reports an error when it tries to dump section names
## and .shstrtab is not null-terminated.
# RUN: yaml2obj %s --docnum=4 -o %t4
# RUN: not llvm-objdump -s %t4 2>&1 | FileCheck --check-prefix=INVALIDERR %s
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_DYN
Machine: EM_X86_64
Sections:
- Name: .shstrtab
Type: SHT_STRTAB
Content: "11"
## Check that llvm-objdump reports an error when it tries to dump a symbol name and
## .strtab is not null-terminated.
# RUN: yaml2obj %s --docnum=5 -o %t5
# RUN: not llvm-objdump -syms %t5 2>&1 | FileCheck --check-prefix=NONULL %s
# NONULL: error: {{.*}}: SHT_STRTAB string table section [index 1] is non-null terminated
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_DYN
Machine: EM_X86_64
Sections:
- Name: .strtab
Type: SHT_STRTAB
Content: "11"
Symbols:
- Name: foo
## Check that llvm-readobj reports an error if .symtab has an invalid sh_entsize.
# RUN: yaml2obj %s --docnum=6 -o %t6
# RUN: not llvm-readobj --symbols %t6 2>&1 | FileCheck --check-prefix=INVALID-SYM-SIZE %s
# INVALID-SYM-SIZE: error: section [index 1] has an invalid sh_entsize: 32
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_DYN
Machine: EM_X86_64
Sections:
- Name: .symtab
Type: SHT_SYMTAB
EntSize: 32
Symbols:
- Name: foo
## Check that llvm-readobj reports a warning if .dynsym has an invalid sh_entsize.
# RUN: yaml2obj %s --docnum=7 -o %t7
# RUN: llvm-readobj --dyn-symbols %t7 2>&1 | FileCheck --check-prefix=INVALID-DYNSYM-SIZE %s
# INVALID-DYNSYM-SIZE: warning: invalid section size (48) or entity size (32)
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_DYN
Machine: EM_X86_64
Sections:
- Name: .dynsym
Type: SHT_DYNSYM
EntSize: 32
DynamicSymbols:
- Name: foo
## Check that llvm-readobj reports an error if .symtab has an invalid sh_link value,
## which is greater than number of sections.
# RUN: yaml2obj %s --docnum=8 -o %t8
# RUN: not llvm-readobj --symbols %t8 2>&1 | FileCheck --check-prefix=INVALID-SYMTAB-LINK %s
# INVALID-SYMTAB-LINK: error: invalid section index: 255
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_REL
Machine: EM_X86_64
Sections:
- Name: .symtab
Type: SHT_SYMTAB
Link: 0xFF
## Check that llvm-readobj reports an error when trying to dump sections
## when the e_shentsize field is broken.
# RUN: yaml2obj %s --docnum=9 -o %t9
# RUN: not llvm-readobj -S %t9 2>&1 | FileCheck --check-prefix=INVALID-SH-ENTSIZE %s
# INVALID-SH-ENTSIZE: error: {{.*}}: invalid e_shentsize in ELF header: 1
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_REL
Machine: EM_X86_64
SHEntSize: 1
## Check that llvm-readobj reports an error if .symtab has sh_size
## that is not a multiple of sh_entsize.
# RUN: yaml2obj %s --docnum=10 -o %t10
# RUN: not llvm-readobj --symbols %t10 2>&1 | FileCheck --check-prefix=INVALID-SYMTAB-SIZE %s
# INVALID-SYMTAB-SIZE: error: section [index 1] has an invalid sh_size (1) which is not a multiple of its sh_entsize (24)
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_DYN
Machine: EM_X86_64
Sections:
- Name: .symtab
Type: SHT_SYMTAB
Size: 1
## Test that llvm-readobj reports an error if SHT_SYMTAB_SHNDX section has
## invalid sh_size which should be:
## sizeof(.symtab_shndx) = (sizeof(.symtab) / entsize(.symtab)) * entsize(.symtab_shndx)
# RUN: yaml2obj %s --docnum=11 -o %t11
# RUN: not llvm-readobj --symbols %t11 2>&1 | FileCheck --check-prefix=INVALID-XINDEX-SIZE %s
# INVALID-XINDEX-SIZE: error: {{.*}}: SHT_SYMTAB_SHNDX section has sh_size (24) which is not equal to the number of symbols (6)
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_DYN
Machine: EM_X86_64
Sections:
- Name: .symtab_shndx
Type: SHT_SYMTAB_SHNDX
Size: 0x18
EntSize: 4
Link: .symtab
## Check that llvm-readobj reports an error if the e_phentsize field is broken.
# RUN: not llvm-readobj --program-headers %p/Inputs/invalid-e_shnum.elf 2>&1 | \
# RUN: FileCheck --check-prefix=INVALID-PH-ENTSIZE %s
# INVALID-PH-ENTSIZE: error: invalid e_phentsize: 12336
## Check that llvm-readobj reports an error when we have no SHT_SYMTAB_SHNDX section,
## but have a symbol referencing it.
# RUN: not llvm-readobj --symbols %p/Inputs/invalid-ext-symtab-index.elf-x86-64 2>&1 | \
# RUN: FileCheck --check-prefix=INVALID-EXT-SYMTAB-INDEX %s
# INVALID-EXT-SYMTAB-INDEX: error: extended symbol index (0) is past the end of the SHT_SYMTAB_SHNDX section of size 0
## Check that llvm-readobj reports an error if a relocation section
## has a broken sh_offset (past the end of the file).
# RUN: yaml2obj %s --docnum=12 -o %t12
# RUN: yaml2obj %s --docnum=13 -o %t13
# RUN: not llvm-readobj -r %t12 2>&1 | FileCheck --check-prefix=INVALID-RELOC-SH-OFFSET %s
# RUN: not llvm-readobj -r %t13 2>&1 | FileCheck --check-prefix=INVALID-RELOC-SH-OFFSET %s
# INVALID-RELOC-SH-OFFSET: error: section [index 1] has a sh_offset (0x10000) + sh_size (0x0) that cannot be represented
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_REL
Machine: EM_386
Sections:
- Name: .rel
Type: SHT_REL
ShOffset: 0x10000
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_REL
Machine: EM_X86_64
Sections:
- Name: .rela
Type: SHT_RELA
ShOffset: 0x10000
## Check that llvm-objdump reports an error when .shstrtab has a broken sh_offset
## so large that sh_offset + sh_size overflows the platform address size type.
# RUN: yaml2obj %s --docnum=14 -o %t14
# RUN: not llvm-readobj --symbols %t14 2>&1 | FileCheck --check-prefix=INVALID-SECTION-SIZE2 %s
# INVALID-SECTION-SIZE2: error: section [index 1] has a sh_offset (0xffffffff) + sh_size (0x27) that cannot be represented
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_REL
Machine: EM_386
Sections:
- Name: .shstrtab
Type: SHT_STRTAB
ShOffset: 0xFFFFFFFF
## Check that llvm-readobj reports an error when trying to dump sections
## when the e_shnum field is broken (is greater than the actual number of sections).
# RUN: yaml2obj %s --docnum=15 -o %t15
# RUN: not llvm-readobj -S %t15 2>&1 | FileCheck --check-prefix=INVALID-SECTION-NUM %s
# INVALID-SECTION-NUM: error: {{.*}}: section table goes past the end of file
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_REL
Machine: EM_X86_64
SHNum: 0xFF
## Check that llvm-readobj reports an error if a relocation contains an
## incorrect (too large) symbol index.
# RUN: yaml2obj %s --docnum=16 -o %t16
# RUN: not llvm-readobj -r %t16 2>&1 | FileCheck --check-prefix=INVALID-REL-SYM %s
# INVALID-REL-SYM: error: unable to access section [index 2] data at 0x18000180: offset goes past the end of file
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_REL
Machine: EM_X86_64
Sections:
- Name: .rela.text
Type: SHT_RELA
Info: 0
Relocations:
- Offset: 0x0
Type: R_X86_64_64
Symbol: 0xFFFFFF
## Check llvm-readobj does not crash on a truncated ELF.
## Create a truncated ELF object with ELFCLASSNONE class using echo.
## 0x7f, 'E', 'L', 'F', ELFCLASS64(2), ELFDATA2LSB(1),
## EV_CURRENT(1), ELFOSABI_LINUX(3), <padding zero bytes>, ET_REL(1), EM_NONE(0)
# RUN: echo -e -n "\x7f\x45\x4c\x46\x02\x01\x01\x03\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00" > %t11
# RUN: not llvm-readobj -r %t11 2>&1 | FileCheck --check-prefix=INVALID-BUFFER %s
# INVALID-BUFFER: error: {{.*}}': invalid buffer: the size (18) is smaller than an ELF header (64)
# RUN: not llvm-readobj %p/Inputs/invalid-coff-header-too-small 2>&1 | FileCheck --check-prefix=COFF-HEADER %s
# COFF-HEADER: The file was not recognized as a valid object file
## Check that llvm-readobj reports an error if section name offset
## overflows the section name string table.
# RUN: yaml2obj %s --docnum=17 -o %t17
# RUN: not llvm-readobj --sections %t17 2>&1 | FileCheck --check-prefix=BROKEN-SECNAME %s
## BROKEN-SECNAME: error: a section [index 1] has an invalid sh_name (0x1) offset which goes past the end of the section name string table
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_REL
Machine: EM_X86_64
Sections:
- Name: .shstrtab
Type: SHT_STRTAB
Size: 1
## Check that llvm-readobj reports an error if a section has a broken offset
## that goes past the end of the file.
# RUN: yaml2obj %s --docnum=18 -o %t18
# RUN: not llvm-readobj --sections --section-data %t18 2>&1 \
# RUN: | FileCheck --check-prefix=BROKEN-SECSHOFFSET %s
# BROKEN-SECSHOFFSET: error: section [index 1] has a sh_offset (0xffff0000) + sh_size (0x0) that cannot be represented
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_REL
Machine: EM_X86_64
Sections:
- Name: .foo
Type: SHT_PROGBITS
ShOffset: 0xFFFF0000
## Check that llvm-readobj reports an error if symbol name
## offset goes past the end of the symbol string table.
# RUN: yaml2obj %s --docnum=19 -o %t19
# RUN: not llvm-readobj --symbols %t19 2>&1 | FileCheck --check-prefix=INVALID-SYM-NAME %s
# INVALID-SYM-NAME: error: Invalid data was encountered while parsing the file
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_REL
Machine: EM_X86_64
Sections:
- Name: .strtab
Type: SHT_STRTAB
Size: 1
Symbols:
- Name: foo
## Version index in .gnu.version overflows the version map.
## Check llvm-readobj reports it.
# RUN: yaml2obj %s --docnum=20 -o %t20
# RUN: not llvm-readobj -dt %t20 2>&1 | FileCheck --check-prefix=INVALID-VERSION %s
# INVALID-VERSION: error: Invalid version entry
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_DYN
Machine: EM_X86_64
Sections:
- Name: .gnu.version
Type: SHT_GNU_versym
Entries: [ 0xFF ]
DynamicSymbols:
- Name: foo
## ELF header contains e_phentsize field with a value != sizeof(Elf_Phdr).
## Check llvm-readobj reports it.
# RUN: not llvm-readobj -l %p/Inputs/corrupt-invalid-phentsize.elf.x86-64 2>&1 \
# RUN: | FileCheck --check-prefix=PHENTSIZE %s
# PHENTSIZE: error: invalid e_phentsize: 57
## The dynamic table contains DT_STRTAB with a value that is not in any loadable segment.
## Check llvm-readobj reports it.
# RUN: yaml2obj %s --docnum=21 -o %t21
# RUN: llvm-readobj --dynamic-table %t21 2>&1 | FileCheck --check-prefix=INVALID-DTSTRTAB %s
# INVALID-DTSTRTAB: warning: Unable to parse DT_STRTAB: virtual address is not in any segment: 0xffff0000
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_EXEC
Machine: EM_X86_64
Sections:
- Name: .dynamic
Type: SHT_DYNAMIC
Address: 0x1000
Entries:
- Tag: DT_STRTAB
Value: 0xFFFF0000
- Tag: DT_NULL
Value: 0x0
ProgramHeaders:
- Type: PT_LOAD
VAddr: 0x1000
Sections:
- Section: .dynamic
## Check that llvm-readobj reports a warning when a dynamic relocation section
## has sh_entsize field with size != sizeof(Elf_Rela).
# RUN: llvm-readobj --dyn-relocations \
# RUN: %p/Inputs/corrupt-invalid-relocation-size.elf.x86-64 2>&1 \
# RUN: | FileCheck --check-prefix=RELOC-BROKEN-ENTSIZE %s
# RELOC-BROKEN-ENTSIZE: warning: invalid section size (24) or entity size (25)
## Check that llvm-readobj reports a warning when .dynamic section has an invalid
## size, which isn't a multiple of the dynamic entry size.
# RUN: yaml2obj %s --docnum=22 -o %t22
# RUN: llvm-readobj --dyn-relocations %t22 2>&1 | FileCheck --check-prefix=DYN-TABLE-SIZE %s
# DYN-TABLE-SIZE: warning: invalid section size (1) or entity size (16)
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_EXEC
Machine: EM_X86_64
Sections:
- Name: .dynamic
Type: SHT_DYNAMIC
Content: "00"
## PT_DYNAMIC's p_offset field is so large that p_offset + p_filesz is larger
## than the object size. Check llvm-readobj reports it.
# RUN: yaml2obj %s --docnum=23 -o %t23
# RUN: not llvm-readobj --dyn-relocations %t23 2>&1 | FileCheck --check-prefix=DYN-TABLE-PHDR %s
# DYN-TABLE-PHDR: error: PT_DYNAMIC segment offset + size exceeds the size of the file
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_EXEC
Machine: EM_X86_64
Sections:
- Name: .dynamic
Type: SHT_DYNAMIC
Entries:
- Tag: DT_NULL
Value: 0
ProgramHeaders:
- Type: PT_DYNAMIC
Offset: 0xffff0000
Sections:
- Section: .dynamic
## PT_DYNAMIC's p_filesz field is so large that p_offset + p_filesz is larger
## than the object size. Check llvm-readobj reports it.
# RUN: yaml2obj %s --docnum=24 -o %t24
# RUN: not llvm-readobj --dyn-relocations %t24 2>&1 \
# RUN: | FileCheck --check-prefix=DYN-TABLE-PHDR %s
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_EXEC
Machine: EM_X86_64
Sections:
- Name: .dynamic
Type: SHT_DYNAMIC
Entries:
- Tag: DT_NULL
Value: 0
ProgramHeaders:
- Type: PT_DYNAMIC
FileSize: 0xffff0000
Sections:
- Section: .dynamic
# RUN: yaml2obj --docnum=25 %s -o %t25
# RUN: not obj2yaml 2>&1 %t25 | FileCheck %s -DFILE=%t25 --check-prefix=INVALID-SHSTRNDX
# INVALID-SHSTRNDX: Error reading file: [[FILE]]: section header string table index 255 does not exist
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_REL
Machine: EM_X86_64
SHStrNdx: 0xFF
Sections:
- Name: .foo
Type: SHT_PROGBITS
|