1## Test cases related to the value of the e_shnum field of the ELF header live here.
2
3## Normally an object that does not have sections has e_shnum == 0.
4## Also, e_shnum might be 0, when the the number of entries in the section
5## header table is larger than or equal to SHN_LORESERVE (0xff00). In this case
6## the real number of entries in the section header table is held in the sh_size
7## member of the initial entry in the section header table.
8
9## In the test case below we have an object that has e_shnum = 0 and the real
10## number of sections is written to the sh_size member of the initial entry in
11## the section header table. Check that we emit the `EShNum` key properly.
12
13# RUN: yaml2obj %s -o %t1
14# RUN: obj2yaml %t1 | FileCheck %s --check-prefix=PRESERVE
15
16# PRESERVE:      --- !ELF
17# PRESERVE-NEXT: FileHeader:
18# PRESERVE-NEXT:   Class:  ELFCLASS64
19# PRESERVE-NEXT:   Data:   ELFDATA2LSB
20# PRESERVE-NEXT:   Type:   ET_REL
21# PRESERVE-NEXT:   EShNum: 0x0
22# PRESERVE-NEXT: Sections:
23# PRESERVE-NEXT:   - Type: SHT_NULL
24# PRESERVE-NEXT:     Size: 0x3
25# PRESERVE-NEXT: ...
26
27--- !ELF
28FileHeader:
29  Class:  ELFCLASS64
30  Data:   ELFDATA2LSB
31  Type:   ET_REL
32  EShNum: 0x0
33  EShOff: [[ESHOFF=<none>]]
34Sections:
35 - Type: SHT_NULL
36## 3 sections total: SHT_NULL + 2 implicit sections: .strtab and .shstrtab.
37   Size: [[SIZE=0x3]]
38
39## In the test case below we have an object with a non-zero section header table
40## file offset and an initial entry in the section header table with sh_size of 0.
41## Here we check that we are able to dump such objects properly.
42
43# RUN: yaml2obj %s -DSIZE=0x0 -o %t2
44# RUN: obj2yaml %t2 | FileCheck %s --check-prefix=NO-SECTIONS
45
46# NO-SECTIONS:      --- !ELF
47# NO-SECTIONS-NEXT: FileHeader:
48# NO-SECTIONS-NEXT:   Class:  ELFCLASS64
49# NO-SECTIONS-NEXT:   Data:   ELFDATA2LSB
50# NO-SECTIONS-NEXT:   Type:   ET_REL
51# NO-SECTIONS-NEXT:   EShNum: 0x0
52## Note: yaml2obj will create the SHT_NULL section with sh_size = 0 implicitly.
53# NO-SECTIONS-NEXT: ...
54
55## In the test case below we have an object without a section header table and e_shnum == 0.
56## Document how we dump it.
57## FIXME: we should emit the `SectionHeaderTable` key with `NoHeaders=true` for this case.
58
59# RUN: yaml2obj %s -DESHOFF=0x0 -o %t3
60# RUN: obj2yaml %t3 | FileCheck %s --check-prefix=NO-HEADERS
61
62# NO-HEADERS:      --- !ELF
63# NO-HEADERS-NEXT: FileHeader:
64# NO-HEADERS-NEXT:   Class: ELFCLASS64
65# NO-HEADERS-NEXT:   Data:  ELFDATA2LSB
66# NO-HEADERS-NEXT:   Type:  ET_REL
67# NO-HEADERS-NEXT: ...
68