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