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