1 ## Check that llvm-objdump reports an error when
2 ## .shstrtab has an invalid type.
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
7 # INVALID-SHTYPE: error: '[[FILE]]': invalid sh_type for string table section [index 1]: expected SHT_STRTAB, but got SHT_PROGBITS
19 ## Check that llvm-objdump reports an error when
20 ## .shstrtab has an invalid zero-size.
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
25 # STRTAB-EMPTY: error: '[[FILE]]': SHT_STRTAB string table section [index 1] is empty
38 ## Check that llvm-objdump reports an error when .shstrtab has an invalid
39 ## size that goes past the end of the file.
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
44 # INVALID-STRTAB-SIZE: error: '[[FILE]]': section [index 1] has a sh_offset (0x70) + sh_size (0x16777215) that cannot be represented
46 ## Check that llvm-dwarfdump reports an error during relocation resolution
47 ## when instead of expected SHT_RELA section it locates a section of a different type.
49 # RUN: yaml2obj %s --docnum=3 -o %t3
50 # RUN: not llvm-dwarfdump -debug-line %t3 2>&1 | FileCheck --check-prefix=RELA %s
52 # RELA: LLVM ERROR: Section is not SHT_RELA
63 ## The exact content does not matter here. We can use any minimal valid debug section
64 ## which is a target for relocation. The idea is to trigger the code that reads the
65 ## relocation's addend during relocation resolution. It should fail if called on
66 ## a non-SHT_RELA section.
67 Content: 380000000200210000000101FB0E0D00010101010000000100000100676C6F62616C2E63707000000000000009020000000000000000130237000101
68 - Name: .rela.debug_line
72 - Offset: 0x000000000000002E
75 ## Check that llvm-objdump reports an error when it tries to dump section names
76 ## and .shstrtab is not null-terminated.
78 # RUN: yaml2obj %s --docnum=4 -o %t4
79 # RUN: not llvm-objdump -s %t4 2>&1 | FileCheck -DFILE=%t4 --check-prefix=SHSTRTAB-NON-TERM %s
81 # SHSTRTAB-NON-TERM: error: '[[FILE]]': SHT_STRTAB string table section [index 1] is non-null terminated
94 ## Check that llvm-objdump reports an error when it tries to dump a symbol name and
95 ## .strtab is not null-terminated.
97 # RUN: yaml2obj %s --docnum=5 -o %t5
98 # RUN: not llvm-objdump -syms %t5 2>&1 | FileCheck --check-prefix=NONULL %s
100 # NONULL: error: {{.*}}: SHT_STRTAB string table section [index 1] is non-null terminated
115 ## Check that llvm-readobj reports an error if .symtab has an invalid sh_entsize.
117 # RUN: yaml2obj %s --docnum=6 -o %t6
118 # RUN: not llvm-readobj --symbols %t6 2>&1 | FileCheck -DFILE=%t6 --check-prefix=INVALID-SYM-SIZE %s
120 # INVALID-SYM-SIZE: error: '[[FILE]]': section [index 1] has an invalid sh_entsize: 32
135 ## Check that llvm-readobj reports a warning if .dynsym has an invalid sh_entsize.
137 # RUN: yaml2obj %s --docnum=7 -o %t7
138 # RUN: llvm-readobj --dyn-symbols %t7 2>&1 | FileCheck -DFILE=%t7 --check-prefix=INVALID-DYNSYM-SIZE %s
140 # INVALID-DYNSYM-SIZE: warning: '[[FILE]]': invalid section size (48) or entity size (32)
155 ## Check that llvm-readobj reports an error if .symtab has an invalid sh_link value,
156 ## which is greater than number of sections.
158 # RUN: yaml2obj %s --docnum=8 -o %t8
159 # RUN: not llvm-readobj --symbols %t8 2>&1 | FileCheck -DFILE=%t8 --check-prefix=INVALID-SYMTAB-LINK %s
161 # INVALID-SYMTAB-LINK: error: '[[FILE]]': invalid section index: 255
174 ## Check that llvm-readobj reports an error when trying to dump sections
175 ## when the e_shentsize field is broken.
177 # RUN: yaml2obj %s --docnum=9 -o %t9
178 # RUN: not llvm-readobj -S %t9 2>&1 | FileCheck --check-prefix=INVALID-SH-ENTSIZE %s
180 # INVALID-SH-ENTSIZE: error: {{.*}}: invalid e_shentsize in ELF header: 1
190 ## Check that llvm-readobj reports an error if .symtab has sh_size
191 ## that is not a multiple of sh_entsize.
193 # RUN: yaml2obj %s --docnum=10 -o %t10
194 # RUN: not llvm-readobj --symbols %t10 2>&1 | FileCheck -DFILE=%t10 --check-prefix=INVALID-SYMTAB-SIZE %s
196 # INVALID-SYMTAB-SIZE: error: '[[FILE]]': section [index 1] has an invalid sh_size (1) which is not a multiple of its sh_entsize (24)
209 ## Test that llvm-readobj reports an error if SHT_SYMTAB_SHNDX section has
210 ## invalid sh_size which should be:
211 ## sizeof(.symtab_shndx) = (sizeof(.symtab) / entsize(.symtab)) * entsize(.symtab_shndx)
213 # RUN: yaml2obj %s --docnum=11 -o %t11
214 # RUN: not llvm-readobj --symbols %t11 2>&1 | FileCheck --check-prefix=INVALID-XINDEX-SIZE %s
216 # INVALID-XINDEX-SIZE: error: {{.*}}: SHT_SYMTAB_SHNDX section has sh_size (24) which is not equal to the number of symbols (2)
225 - Name: .symtab_shndx
226 Type: SHT_SYMTAB_SHNDX
231 ## Check that llvm-readobj reports an error if the e_phentsize field is broken.
233 # RUN: not llvm-readobj --program-headers %p/Inputs/invalid-e_shnum.elf 2>&1 | \
234 # RUN: FileCheck -DFILE=%p/Inputs/invalid-e_shnum.elf --check-prefix=INVALID-PH-ENTSIZE %s
236 # INVALID-PH-ENTSIZE: error: '[[FILE]]': invalid e_phentsize: 12336
238 ## Check that llvm-readobj reports an error when we have no SHT_SYMTAB_SHNDX section,
239 ## but have a symbol referencing it.
241 # RUN: not llvm-readobj --symbols %p/Inputs/invalid-ext-symtab-index.elf-x86-64 2>&1 | \
242 # RUN: FileCheck -DFILE=%p/Inputs/invalid-ext-symtab-index.elf-x86-64 --check-prefix=INVALID-EXT-SYMTAB-INDEX %s
244 # INVALID-EXT-SYMTAB-INDEX: error: '[[FILE]]': extended symbol index (0) is past the end of the SHT_SYMTAB_SHNDX section of size 0
246 ## Check that llvm-readobj reports an error if a relocation section
247 ## has a broken sh_offset (past the end of the file).
249 # RUN: yaml2obj %s --docnum=12 -o %t12
250 # RUN: yaml2obj %s --docnum=13 -o %t13
251 # RUN: not llvm-readobj -r %t12 2>&1 | FileCheck -DFILE=%t12 --check-prefix=INVALID-RELOC-SH-OFFSET %s
252 # RUN: not llvm-readobj -r %t13 2>&1 | FileCheck -DFILE=%t13 --check-prefix=INVALID-RELOC-SH-OFFSET %s
254 # INVALID-RELOC-SH-OFFSET: error: '[[FILE]]': section [index 1] has a sh_offset (0x10000) + sh_size (0x0) that cannot be represented
278 ## Check that llvm-objdump reports an error when we try to print symbols and
279 ## .shstrtab has a broken sh_offset so large that sh_offset + sh_size overflows the platform address size type.
281 # RUN: yaml2obj %s --docnum=14 -o %t14
282 # RUN: not llvm-readobj --symbols %t14 2>&1 | FileCheck -DFILE=%t14 --check-prefix=INVALID-SECTION-SIZE2 %s
284 # INVALID-SECTION-SIZE2: error: '[[FILE]]': section [index 1] has a sh_offset (0xffffffff) + sh_size (0x27) that cannot be represented
298 ## Check that llvm-readobj reports an error when trying to dump sections
299 ## when the e_shnum field is broken (is greater than the actual number of sections).
301 # RUN: yaml2obj %s --docnum=15 -o %t15
302 # RUN: not llvm-readobj -S %t15 2>&1 | FileCheck --check-prefix=INVALID-SECTION-NUM %s
304 # INVALID-SECTION-NUM: error: {{.*}}: section table goes past the end of file
314 ## Check that llvm-readobj reports an error if a relocation contains an
315 ## incorrect (too large) symbol index.
317 # RUN: yaml2obj %s --docnum=16 -o %t16
318 # RUN: not llvm-readobj -r %t16 2>&1 | FileCheck -DFILE=%t16 --check-prefix=INVALID-REL-SYM %s
320 # INVALID-REL-SYM: error: '[[FILE]]': unable to access section [index 2] data at 0x18000040: offset goes past the end of file
337 ## Check llvm-readobj does not crash on a truncated ELF.
339 ## Create a truncated ELF object with ELFCLASSNONE class using echo.
340 ## 0x7f, 'E', 'L', 'F', ELFCLASS64(2), ELFDATA2LSB(1),
341 ## EV_CURRENT(1), ELFOSABI_LINUX(3), <padding zero bytes>, ET_REL(1), EM_NONE(0)
342 # RUN: echo -e -n "\x7f\x45\x4c\x46\x02\x01\x01\x03\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00" > %t11
343 # RUN: not llvm-readobj -r %t11 2>&1 | FileCheck --check-prefix=INVALID-BUFFER %s
345 # INVALID-BUFFER: error: {{.*}}': invalid buffer: the size (18) is smaller than an ELF header (64)
347 # RUN: not llvm-readobj %p/Inputs/invalid-coff-header-too-small 2>&1 | FileCheck --check-prefix=COFF-HEADER %s
348 # COFF-HEADER: The file was not recognized as a valid object file
350 ## Check that llvm-readobj reports an error if section name offset
351 ## overflows the section name string table.
353 # RUN: yaml2obj %s --docnum=17 -o %t17
354 # RUN: not llvm-readobj --sections %t17 2>&1 | FileCheck -DFILE=%t17 --check-prefix=BROKEN-SECNAME %s
356 ## BROKEN-SECNAME: error: '[[FILE]]': a section [index 1] has an invalid sh_name (0x1) offset which goes past the end of the section name string table
369 ## Check that llvm-readobj reports an error if a section has a broken offset
370 ## that goes past the end of the file.
372 # RUN: yaml2obj %s --docnum=18 -o %t18
373 # RUN: not llvm-readobj --sections --section-data %t18 2>&1 \
374 # RUN: | FileCheck -DFILE=%t18 --check-prefix=BROKEN-SECSHOFFSET %s
376 # BROKEN-SECSHOFFSET: error: '[[FILE]]': section [index 1] has a sh_offset (0xffff0000) + sh_size (0x0) that cannot be represented
389 ## Check that llvm-readobj reports an error if symbol name
390 ## offset goes past the end of the symbol string table.
392 # RUN: yaml2obj %s --docnum=19 -o %t19
393 # RUN: not llvm-readobj --symbols %t19 2>&1 | FileCheck -DFILE=%t19 --check-prefix=INVALID-SYM-NAME %s
395 # INVALID-SYM-NAME: error: '[[FILE]]': st_name (0x1) is past the end of the string table of size 0x1
410 ## Version index in .gnu.version overflows the version map.
411 ## Check llvm-readobj reports it.
413 # RUN: yaml2obj %s --docnum=20 -o %t20
414 # RUN: not llvm-readobj -dt %t20 2>&1 | FileCheck -DFILE=%t20 --check-prefix=INVALID-VERSION %s
416 # INVALID-VERSION: error: '[[FILE]]': Invalid version entry
431 ## ELF header contains e_phentsize field with a value != sizeof(Elf_Phdr).
432 ## Check llvm-readobj reports it.
434 # RUN: not llvm-readobj -l %p/Inputs/corrupt-invalid-phentsize.elf.x86-64 2>&1 \
435 # RUN: | FileCheck -DFILE=%p/Inputs/corrupt-invalid-phentsize.elf.x86-64 --check-prefix=PHENTSIZE %s
437 # PHENTSIZE: error: '[[FILE]]': invalid e_phentsize: 57
439 ## The dynamic table contains DT_STRTAB with a value that is not in any loadable segment.
440 ## Check llvm-readobj reports it.
442 # RUN: yaml2obj %s --docnum=21 -o %t21
443 # RUN: llvm-readobj --dynamic-table %t21 2>&1 | FileCheck -DFILE=%t21 --check-prefix=INVALID-DTSTRTAB %s
445 # INVALID-DTSTRTAB: warning: '[[FILE]]': Unable to parse DT_STRTAB: virtual address is not in any segment: 0xffff0000
468 ## Check that llvm-readobj reports a warning when a dynamic relocation section
469 ## has sh_entsize field with size != sizeof(Elf_Rela).
471 # RUN: llvm-readobj --dyn-relocations \
472 # RUN: %p/Inputs/corrupt-invalid-relocation-size.elf.x86-64 2>&1 \
473 # RUN: | FileCheck -DFILE=%p/Inputs/corrupt-invalid-relocation-size.elf.x86-64 --check-prefix=RELOC-BROKEN-ENTSIZE %s
475 # RELOC-BROKEN-ENTSIZE: warning: '[[FILE]]': invalid section size (24) or entity size (25)
477 ## Check that llvm-readobj reports a warning when .dynamic section has an invalid
478 ## size, which isn't a multiple of the dynamic entry size.
480 # RUN: yaml2obj %s --docnum=22 -o %t22
481 # RUN: llvm-readobj --dyn-relocations %t22 2>&1 | FileCheck -DFILE=%t22 --check-prefix=DYN-TABLE-SIZE %s
483 # DYN-TABLE-SIZE: warning: '[[FILE]]': invalid section size (1) or entity size (16)
496 ## PT_DYNAMIC's p_offset field is so large that p_offset + p_filesz is larger
497 ## than the object size. Check llvm-readobj reports it.
499 # RUN: yaml2obj %s --docnum=23 -o %t23
500 # RUN: llvm-readobj --dyn-relocations %t23 2>&1 | FileCheck -DFILE=%t23 --check-prefix=DYN-TABLE-PHDR %s
502 # DYN-TABLE-PHDR: warning: '[[FILE]]': PT_DYNAMIC segment offset + size exceeds the size of the file
522 ## PT_DYNAMIC's p_filesz field is so large that p_offset + p_filesz is larger
523 ## than the object size. Check llvm-readobj reports it.
525 # RUN: yaml2obj %s --docnum=24 -o %t24
526 # RUN: llvm-readobj --dyn-relocations %t24 2>&1 \
527 # RUN: | FileCheck -DFILE=%t24 --check-prefix=DYN-TABLE-PHDR %s
547 # RUN: yaml2obj --docnum=25 %s -o %t25
548 # RUN: not obj2yaml 2>&1 %t25 | FileCheck %s -DFILE=%t25 --check-prefix=INVALID-SHSTRNDX
550 # INVALID-SHSTRNDX: Error reading file: [[FILE]]: section header string table index 255 does not exist
563 ## We report an error if the number of sections stored in sh_size
564 ## is greater than UINT64_MAX / sizeof(Elf_Shdr) == 288230376151711743.
565 ## Here we check that do not crash on a border value.
567 # RUN: yaml2obj --docnum=26 %s -o %t26
568 # RUN: not llvm-readobj -h %t26 2>&1 | FileCheck -DFILE=%t26 --check-prefix=INVALID-SEC-NUM1 %s
570 # INVALID-SEC-NUM1: error: '[[FILE]]': invalid section header table offset (e_shoff = 0x58) or invalid number of sections specified in the first section header's sh_size field (0x3ffffffffffffff)
581 Size: 288230376151711743
583 ## See above, but now we test the UINT64_MAX / sizeof(Elf_Shdr) value.
584 ## The error is slightly different in this case.
586 # RUN: yaml2obj --docnum=27 %s -o %t27
587 # RUN: not llvm-readobj -h %t27 2>&1 | FileCheck -DFILE=%t27 --check-prefix=INVALID-SEC-NUM2 %s
589 # INVALID-SEC-NUM2: error: '[[FILE]]': invalid number of sections specified in the NULL section's sh_size field (288230376151711744)
600 Size: 288230376151711744
602 ## Check the case when SHOff is too large. SHOff + sizeof(Elf_Shdr) overflows the uint64 type.
604 # RUN: yaml2obj --docnum=28 %s -o %t28
605 # RUN: not llvm-readobj -h %t28 2>&1 | FileCheck -DFILE=%t28 --check-prefix=INVALID-SEC-NUM3 %s
607 # INVALID-SEC-NUM3: error: '[[FILE]]': section header table goes past the end of the file: e_shoff = 0xffffffffffffffff
615 SHOff: 0xffffffffffffffff
617 ## Check that llvm-objdump reports an error when it tries to dump a
618 ## symbol name and .strtab is empty.
620 # RUN: yaml2obj %s --docnum=29 -o %t29
621 # RUN: not llvm-objdump -syms %t29 2>&1 | FileCheck -DFILE=%t29 --check-prefix=STRTAB-EMPTY2 %s
623 # STRTAB-EMPTY2: error: '[[FILE]]': SHT_STRTAB string table section [index 1] is empty
638 ## Check that we report an error if SHT_GNU_versym has invalid
639 ## sh_entsize value (3 instead of 2) when trying to access the entries.
641 # RUN: yaml2obj %s --docnum=30 -o %t30
642 # RUN: not llvm-readobj -V %t30 2>&1 | FileCheck -DFILE=%t30 --check-prefix=INVALID-VER-SHENTSIZE %s
644 # INVALID-VER-SHENTSIZE: error: '[[FILE]]': section [index 1] has invalid sh_entsize: expected 2, but got 3
650 OSABI: ELFOSABI_FREEBSD
656 EntSize: 0x0000000000000003
658 ## Needed to trigger creation of .dynsym.
663 ## Check the case when e_shstrndx == SHN_XINDEX, but null section's sh_link contains
664 ## the index of a section header string table that is larger than the number of the sections.
666 # RUN: yaml2obj --docnum=31 %s -o %t31
667 # RUN: not llvm-objcopy %t31 2>&1 | FileCheck %s -DFILE=%t31 --check-prefix=INVALID-SHSTRTAB-INDEX
669 # INVALID-SHSTRTAB-INDEX: error: section header string table index 255 does not exist
677 ## SHN_XINDEX == 0xffff.