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 (0x16777215) that cannot be represented
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 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: not llvm-readobj --symbols %t6 2>&1 | FileCheck -DFILE=%t6 --check-prefix=INVALID-SYM-SIZE %s
119
120# INVALID-SYM-SIZE: error: '[[FILE]]': 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]]': invalid section size (48) or entity size (32)
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 an error 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: not llvm-readobj --symbols %t8 2>&1 | FileCheck -DFILE=%t8 --check-prefix=INVALID-SYMTAB-LINK %s
160
161# INVALID-SYMTAB-LINK: error: '[[FILE]]': 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  SHEntSize: 1
189
190## Check that llvm-readobj reports an error 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: not llvm-readobj --symbols %t10 2>&1 | FileCheck -DFILE=%t10 --check-prefix=INVALID-SYMTAB-SIZE %s
195
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)
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 an error if the e_phentsize field is broken.
232
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
235
236# INVALID-PH-ENTSIZE: error: '[[FILE]]': 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 cannot be represented
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-objdump reports an error when we try to print 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: not llvm-readobj --symbols %t14 2>&1 | FileCheck -DFILE=%t14 --check-prefix=INVALID-SECTION-SIZE2 %s
284
285# INVALID-SECTION-SIZE2: error: '[[FILE]]': section [index 1] has a sh_offset (0xffffffff) + sh_size (0x27) that cannot be represented
286
287--- !ELF
288FileHeader:
289  Class:   ELFCLASS64
290  Data:    ELFDATA2LSB
291  Type:    ET_REL
292  Machine: EM_386
293Sections:
294  - Name:     .shstrtab
295    Type:     SHT_STRTAB
296    ShOffset: 0xFFFFFFFF
297Symbols: []
298
299## Check that llvm-readobj reports an error when trying to dump sections
300## when the e_shnum field is broken (is greater than the actual number of sections).
301
302# RUN: yaml2obj %s --docnum=15 -o %t15
303# RUN: not llvm-readobj -S %t15 2>&1 | FileCheck --check-prefix=INVALID-SECTION-NUM %s
304
305# INVALID-SECTION-NUM: error: {{.*}}: section table goes past the end of file
306
307--- !ELF
308FileHeader:
309  Class:   ELFCLASS64
310  Data:    ELFDATA2LSB
311  Type:    ET_REL
312  Machine: EM_X86_64
313  SHNum:   0xFF
314
315## Check that llvm-readobj reports an error if a relocation contains an
316## incorrect (too large) symbol index.
317
318# RUN: yaml2obj %s --docnum=16 -o %t16
319# RUN: not llvm-readobj -r %t16 2>&1 | FileCheck -DFILE=%t16 --check-prefix=INVALID-REL-SYM %s
320
321# INVALID-REL-SYM: error: '[[FILE]]': unable to access section [index 2] data at 0x18000040: offset goes past the end of file
322
323--- !ELF
324FileHeader:
325  Class:   ELFCLASS64
326  Data:    ELFDATA2LSB
327  Type:    ET_REL
328  Machine: EM_X86_64
329Sections:
330  - Name: .rela.text
331    Type: SHT_RELA
332    Info: 0
333    Relocations:
334      - Offset: 0x0
335        Type:   R_X86_64_64
336        Symbol: 0xFFFFFF
337Symbols: []
338
339## Check llvm-readobj does not crash on a truncated ELF.
340
341## Create a truncated ELF object with ELFCLASSNONE class using echo.
342## 0x7f, 'E', 'L', 'F', ELFCLASS64(2), ELFDATA2LSB(1),
343## EV_CURRENT(1), ELFOSABI_LINUX(3), <padding zero bytes>, ET_REL(1), EM_NONE(0)
344# RUN: echo -e -n "\x7f\x45\x4c\x46\x02\x01\x01\x03\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00" > %t11
345# RUN: not llvm-readobj -r %t11 2>&1 | FileCheck --check-prefix=INVALID-BUFFER %s
346
347# INVALID-BUFFER: error: {{.*}}': invalid buffer: the size (18) is smaller than an ELF header (64)
348
349# RUN: not llvm-readobj %p/Inputs/invalid-coff-header-too-small 2>&1 | FileCheck --check-prefix=COFF-HEADER %s
350# COFF-HEADER: The file was not recognized as a valid object file
351
352## Check that llvm-readobj reports an error if section name offset
353## overflows the section name string table.
354
355# RUN: yaml2obj %s --docnum=17 -o %t17
356# RUN: not llvm-readobj --sections %t17 2>&1 | FileCheck -DFILE=%t17 --check-prefix=BROKEN-SECNAME %s
357
358## 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
359
360--- !ELF
361FileHeader:
362  Class:   ELFCLASS64
363  Data:    ELFDATA2LSB
364  Type:    ET_REL
365  Machine: EM_X86_64
366Sections:
367  - Name: .shstrtab
368    Type: SHT_STRTAB
369    Size: 1
370
371## Check that llvm-readobj reports an error if a section has a broken offset
372## that goes past the end of the file.
373
374# RUN: yaml2obj %s --docnum=18 -o %t18
375# RUN: not llvm-readobj --sections --section-data %t18 2>&1 \
376# RUN:  | FileCheck -DFILE=%t18 --check-prefix=BROKEN-SECSHOFFSET %s
377
378# BROKEN-SECSHOFFSET: error: '[[FILE]]': section [index 1] has a sh_offset (0xffff0000) + sh_size (0x0) that cannot be represented
379
380--- !ELF
381FileHeader:
382  Class:   ELFCLASS64
383  Data:    ELFDATA2LSB
384  Type:    ET_REL
385  Machine: EM_X86_64
386Sections:
387  - Name:     .foo
388    Type:     SHT_PROGBITS
389    ShOffset: 0xFFFF0000
390
391## Check that llvm-readobj reports an error if symbol name
392## offset goes past the end of the symbol string table.
393
394# RUN: yaml2obj %s --docnum=19 -o %t19
395# RUN: not llvm-readobj --symbols %t19 2>&1 | FileCheck -DFILE=%t19 --check-prefix=INVALID-SYM-NAME %s
396
397# INVALID-SYM-NAME: error: '[[FILE]]': st_name (0x1) is past the end of the string table of size 0x1
398
399--- !ELF
400FileHeader:
401  Class:   ELFCLASS64
402  Data:    ELFDATA2LSB
403  Type:    ET_REL
404  Machine: EM_X86_64
405Sections:
406  - Name: .strtab
407    Type: SHT_STRTAB
408    Size: 1
409Symbols:
410  - Name: foo
411
412## Version index in .gnu.version overflows the version map.
413## Check llvm-readobj reports it.
414
415# RUN: yaml2obj %s --docnum=20 -o %t20
416# RUN: not llvm-readobj -dt %t20 2>&1 | FileCheck -DFILE=%t20 --check-prefix=INVALID-VERSION %s
417
418# INVALID-VERSION: error: '[[FILE]]': Invalid version entry
419
420--- !ELF
421FileHeader:
422  Class:   ELFCLASS64
423  Data:    ELFDATA2LSB
424  Type:    ET_DYN
425  Machine: EM_X86_64
426Sections:
427  - Name:    .gnu.version
428    Type:    SHT_GNU_versym
429    Entries: [ 0xFF ]
430DynamicSymbols:
431  - Name: foo
432
433## ELF header contains e_phentsize field with a value != sizeof(Elf_Phdr).
434## Check llvm-readobj reports it.
435
436# RUN: not llvm-readobj -l %p/Inputs/corrupt-invalid-phentsize.elf.x86-64 2>&1 \
437# RUN:   | FileCheck -DFILE=%p/Inputs/corrupt-invalid-phentsize.elf.x86-64 --check-prefix=PHENTSIZE %s
438
439# PHENTSIZE: error: '[[FILE]]': invalid e_phentsize: 57
440
441## The dynamic table contains DT_STRTAB with a value that is not in any loadable segment.
442## Check llvm-readobj reports it.
443
444# RUN: yaml2obj %s --docnum=21 -o %t21
445# RUN: llvm-readobj --dynamic-table %t21 2>&1 | FileCheck -DFILE=%t21 --check-prefix=INVALID-DTSTRTAB %s
446
447# INVALID-DTSTRTAB: warning: '[[FILE]]': Unable to parse DT_STRTAB: virtual address is not in any segment: 0xffff0000
448
449--- !ELF
450FileHeader:
451  Class:   ELFCLASS64
452  Data:    ELFDATA2LSB
453  Type:    ET_EXEC
454  Machine: EM_X86_64
455Sections:
456  - Name:    .dynamic
457    Type:    SHT_DYNAMIC
458    Address: 0x1000
459    Entries:
460      - Tag:   DT_STRTAB
461        Value: 0xFFFF0000
462      - Tag:   DT_NULL
463        Value: 0x0
464ProgramHeaders:
465  - Type: PT_LOAD
466    VAddr: 0x1000
467    Sections:
468      - Section: .dynamic
469
470## Check that llvm-readobj reports a warning when a dynamic relocation section
471## has sh_entsize field with size != sizeof(Elf_Rela).
472
473# RUN: llvm-readobj --dyn-relocations \
474# RUN:   %p/Inputs/corrupt-invalid-relocation-size.elf.x86-64 2>&1 \
475# RUN:    | FileCheck -DFILE=%p/Inputs/corrupt-invalid-relocation-size.elf.x86-64 --check-prefix=RELOC-BROKEN-ENTSIZE %s
476
477# RELOC-BROKEN-ENTSIZE: warning: '[[FILE]]': invalid section size (24) or entity size (25)
478
479## Check that llvm-readobj reports a warning when .dynamic section has an invalid
480## size, which isn't a multiple of the dynamic entry size.
481
482# RUN: yaml2obj %s --docnum=22 -o %t22
483# RUN: llvm-readobj --dyn-relocations %t22 2>&1 | FileCheck -DFILE=%t22 --check-prefix=DYN-TABLE-SIZE %s
484
485# DYN-TABLE-SIZE: warning: '[[FILE]]': invalid section size (1) or entity size (16)
486
487--- !ELF
488FileHeader:
489  Class:   ELFCLASS64
490  Data:    ELFDATA2LSB
491  Type:    ET_EXEC
492  Machine: EM_X86_64
493Sections:
494  - Name:    .dynamic
495    Type:    SHT_DYNAMIC
496    Content: "00"
497
498## PT_DYNAMIC's p_offset field is so large that p_offset + p_filesz is larger
499## than the object size. Check llvm-readobj reports it.
500
501# RUN: yaml2obj %s --docnum=23 -o %t23
502# RUN: llvm-readobj --dyn-relocations %t23 2>&1 | FileCheck -DFILE=%t23 --check-prefix=DYN-TABLE-PHDR %s
503
504# DYN-TABLE-PHDR: warning: '[[FILE]]': PT_DYNAMIC segment offset + size exceeds the size of the file
505
506--- !ELF
507FileHeader:
508  Class:   ELFCLASS64
509  Data:    ELFDATA2LSB
510  Type:    ET_EXEC
511  Machine: EM_X86_64
512Sections:
513  - Name: .dynamic
514    Type: SHT_DYNAMIC
515    Entries:
516      - Tag:   DT_NULL
517        Value: 0
518ProgramHeaders:
519  - Type:   PT_DYNAMIC
520    Offset: 0xffff0000
521    Sections:
522      - Section: .dynamic
523
524## PT_DYNAMIC's p_filesz field is so large that p_offset + p_filesz is larger
525## than the object size. Check llvm-readobj reports it.
526
527# RUN: yaml2obj %s --docnum=24 -o %t24
528# RUN: llvm-readobj --dyn-relocations %t24 2>&1 \
529# RUN:  | FileCheck -DFILE=%t24 --check-prefix=DYN-TABLE-PHDR %s
530
531--- !ELF
532FileHeader:
533  Class:   ELFCLASS64
534  Data:    ELFDATA2LSB
535  Type:    ET_EXEC
536  Machine: EM_X86_64
537Sections:
538  - Name: .dynamic
539    Type: SHT_DYNAMIC
540    Entries:
541      - Tag:   DT_NULL
542        Value: 0
543ProgramHeaders:
544  - Type:     PT_DYNAMIC
545    FileSize: 0xffff0000
546    Sections:
547      - Section: .dynamic
548
549# RUN: yaml2obj --docnum=25 %s -o %t25
550# RUN: not obj2yaml 2>&1 %t25 | FileCheck %s -DFILE=%t25 --check-prefix=INVALID-SHSTRNDX
551
552# INVALID-SHSTRNDX: Error reading file: [[FILE]]: section header string table index 255 does not exist
553
554--- !ELF
555FileHeader:
556  Class:    ELFCLASS64
557  Data:     ELFDATA2LSB
558  Type:     ET_REL
559  Machine:  EM_X86_64
560  SHStrNdx: 0xFF
561Sections:
562  - Name: .foo
563    Type: SHT_PROGBITS
564
565## We report an error if the number of sections stored in sh_size
566## is greater than UINT64_MAX / sizeof(Elf_Shdr) == 288230376151711743.
567## Here we check that do not crash on a border value.
568
569# RUN: yaml2obj --docnum=26 %s -o %t26
570# RUN: not llvm-readobj -h %t26 2>&1 | FileCheck -DFILE=%t26 --check-prefix=INVALID-SEC-NUM1 %s
571
572# 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)
573
574--- !ELF
575FileHeader:
576  Class:   ELFCLASS64
577  Data:    ELFDATA2LSB
578  Type:    ET_REL
579  Machine: EM_X86_64
580  SHNum:   0x0
581Sections:
582  - Type: SHT_NULL
583    Size: 288230376151711743
584
585## See above, but now we test the UINT64_MAX / sizeof(Elf_Shdr) value.
586## The error is slightly different in this case.
587
588# RUN: yaml2obj --docnum=27 %s -o %t27
589# RUN: not llvm-readobj -h %t27 2>&1 | FileCheck -DFILE=%t27 --check-prefix=INVALID-SEC-NUM2 %s
590
591# INVALID-SEC-NUM2: error: '[[FILE]]': invalid number of sections specified in the NULL section's sh_size field (288230376151711744)
592
593--- !ELF
594FileHeader:
595  Class:   ELFCLASS64
596  Data:    ELFDATA2LSB
597  Type:    ET_REL
598  Machine: EM_X86_64
599  SHNum:   0x0
600Sections:
601  - Type: SHT_NULL
602    Size: 288230376151711744
603
604## Check the case when SHOff is too large. SHOff + sizeof(Elf_Shdr) overflows the uint64 type.
605
606# RUN: yaml2obj --docnum=28 %s -o %t28
607# RUN: not llvm-readobj -h %t28 2>&1 | FileCheck -DFILE=%t28 --check-prefix=INVALID-SEC-NUM3 %s
608
609# INVALID-SEC-NUM3: error: '[[FILE]]': section header table goes past the end of the file: e_shoff = 0xffffffffffffffff
610
611--- !ELF
612FileHeader:
613  Class:    ELFCLASS64
614  Data:     ELFDATA2LSB
615  Type:     ET_REL
616  Machine:  EM_X86_64
617  SHOff:    0xffffffffffffffff
618
619## Check that llvm-objdump reports an error when it tries to dump a
620## symbol name and .strtab is empty.
621
622# RUN: yaml2obj %s --docnum=29 -o %t29
623# RUN: not llvm-objdump -syms %t29 2>&1 | FileCheck -DFILE=%t29 --check-prefix=STRTAB-EMPTY2 %s
624
625# STRTAB-EMPTY2: error: '[[FILE]]': SHT_STRTAB string table section [index 1] is empty
626
627--- !ELF
628FileHeader:
629  Class:   ELFCLASS64
630  Data:    ELFDATA2LSB
631  Type:    ET_DYN
632  Machine: EM_X86_64
633Sections:
634  - Name: .strtab
635    Type: SHT_STRTAB
636    Content: ""
637Symbols:
638  - Name: foo
639
640## Check that we report an error if SHT_GNU_versym has invalid
641## sh_entsize value (3 instead of 2) when trying to access the entries.
642
643# RUN: yaml2obj %s --docnum=30 -o %t30
644# RUN: not llvm-readobj -V %t30 2>&1 | FileCheck -DFILE=%t30 --check-prefix=INVALID-VER-SHENTSIZE %s
645
646# INVALID-VER-SHENTSIZE: error: '[[FILE]]': section [index 1] has invalid sh_entsize: expected 2, but got 3
647
648--- !ELF
649FileHeader:
650  Class:   ELFCLASS64
651  Data:    ELFDATA2LSB
652  OSABI:   ELFOSABI_FREEBSD
653  Type:    ET_DYN
654  Machine: EM_X86_64
655Sections:
656  - Name:    .gnu.version
657    Type:    SHT_GNU_versym
658    EntSize: 0x0000000000000003
659    Entries: [ ]
660## Needed to trigger creation of .dynsym.
661DynamicSymbols:
662  - Name:    foo
663    Binding: STB_GLOBAL
664
665## Check the case when e_shstrndx == SHN_XINDEX, but null section's sh_link contains
666## the index of a section header string table that is larger than the number of the sections.
667
668# RUN: yaml2obj --docnum=31 %s -o %t31
669# RUN: not llvm-objcopy %t31 2>&1 | FileCheck %s -DFILE=%t31 --check-prefix=INVALID-SHSTRTAB-INDEX
670
671# INVALID-SHSTRTAB-INDEX: error: section header string table index 255 does not exist
672
673--- !ELF
674FileHeader:
675  Class:    ELFCLASS64
676  Data:     ELFDATA2LSB
677  Type:     ET_REL
678  Machine:  EM_X86_64
679## SHN_XINDEX == 0xffff.
680  SHStrNdx: 0xffff
681Sections:
682  - Type: SHT_NULL
683    Link: 0xff
684