1 ## In this test we check that can redefine the null section in the YAML.
3 ## Test the default output first.
5 # RUN: yaml2obj --docnum=1 %s -o %t1
6 # RUN: llvm-readelf --sections %t1 | FileCheck %s --check-prefix=DEFAULT
8 # DEFAULT: Section Headers:
9 # DEFAULT-NEXT: [Nr] Name Type Address Off Size ES Flg Lk Inf Al
10 # DEFAULT-NEXT: [ 0] NULL 0000000000000000 000000 000000 00 0 0 0
11 # DEFAULT-NEXT: [ 1] .strtab STRTAB 0000000000000000 000040 000001 00 0 0 1
12 # DEFAULT-NEXT: [ 2] .shstrtab STRTAB 0000000000000000 000041 000013 00 0 0 1
20 ## Now define a SHT_NULL section with fields all zeroed.
21 ## In this case it is equal to the section created by default.
23 # RUN: yaml2obj --docnum=2 %s -o %t2
24 # RUN: llvm-readelf --sections %t2 | FileCheck %s --check-prefix=DEFAULT
42 ## Check we can redefine fields of the first SHT_NULL section.
44 # RUN: yaml2obj --docnum=3 %s -o %t3
45 # RUN: llvm-readelf --sections %t3 | FileCheck %s --check-prefix=REDEF
47 # REDEF: Section Headers:
48 # REDEF-NEXT: [Nr] Name Type Address Off Size ES Flg Lk Inf Al
49 # REDEF-NEXT: [ 0] .foo NULL 0000000000000006 000000 000002 03 A 4 5 1
67 ## Check that file size does not change if we redefine the Size
68 ## of the first SHT_NULL section.
70 # RUN: yaml2obj --docnum=4 %s -o %t4
71 # RUN: wc -c < %t3 > %t.txt
72 # RUN: wc -c < %t4 >> %t.txt
73 # RUN: FileCheck %s --input-file=%t.txt --check-prefix=SIZE
75 # SIZE: [[FILESIZE:.*]]
94 ## Check we are still able to describe other sections too.
96 # RUN: yaml2obj --docnum=5 %s -o %t5
97 # RUN: llvm-readelf --sections %t5 | FileCheck %s --check-prefix=OTHER-SECTION
99 # OTHER-SECTION: Section Headers:
100 # OTHER-SECTION-NEXT: [Nr] Name Type Address Off Size ES Flg Lk Inf Al
101 # OTHER-SECTION-NEXT: [ 0] NULL 0000000000000000 000000 000000 00 0 0 0
102 # OTHER-SECTION-NEXT: [ 1] foo PROGBITS 0000000000000000 000040 000000 00 0 0 0
103 # OTHER-SECTION-NEXT: [ 2] .strtab STRTAB 0000000000000000 000040 000001 00 0 0 1
104 # OTHER-SECTION-NEXT: [ 3] .shstrtab STRTAB 0000000000000000 000041 000017 00 0 0 1
122 ## Check we report an error if null section sh_link field refers to an unknown section.
124 # RUN: not yaml2obj --docnum=6 %s -o %t6 2>&1 | FileCheck %s --check-prefix=CASE4
126 # CASE4: error: unknown section referenced: '.foo' by YAML section '(index 0)'
127 # CASE4-NEXT: error: unknown section referenced: '.bar' by YAML section '(index 1)'
140 ## Check that null section fields are set to zero, if they are unspecified.
142 # RUN: yaml2obj --docnum=7 %s -o %t7
143 # RUN: llvm-readelf --sections %t7 | FileCheck %s --check-prefix=DEFAULT
153 ## Check we do not crash if we have more than one SHT_NULL section.
155 # RUN: yaml2obj --docnum=8 %s -o %t8
156 # RUN: llvm-readelf --sections %t8 | FileCheck %s --check-prefix=MULTIPLE
158 # MULTIPLE: Section Headers:
159 # MULTIPLE-NEXT: [Nr] Name Type Address Off Size ES Flg Lk Inf Al
160 # MULTIPLE-NEXT: [ 0] NULL 0000000000000000 000000 000000 00 0 0 0
161 # MULTIPLE-NEXT: [ 1] .foo NULL 0000000000000123 000040 000020 10 A 1 2 0
179 ## Check we can override the sh_offset/sh_size fields of the first SHT_NULL section if requested.
181 # RUN: yaml2obj --docnum=9 %s -o %t9
182 # RUN: llvm-readelf --sections %t9 | FileCheck %s --check-prefix=OVERRIDE
184 # OVERRIDE: Section Headers:
185 # OVERRIDE-NEXT: [Nr] Name Type Address Off Size ES Flg Lk Inf Al
186 # OVERRIDE-NEXT: [ 0] NULL 0000000000000000 000007 000008 00 0 0 0
199 ## Check that we can set an offset for the SHT_NULL section explicitly using the "Offset" key.
200 ## Check it affects the section header table offset.
201 # RUN: yaml2obj --docnum=10 %s -DOFFSET=0x100 -o %t10
202 # RUN: llvm-readelf --headers --sections %t10 | FileCheck %s --check-prefix=EXPLICIT-OFFSET-A
203 # RUN: yaml2obj --docnum=10 %s -DOFFSET=0x200 -o %t11
204 # RUN: llvm-readelf --headers --sections %t11 | FileCheck %s --check-prefix=EXPLICIT-OFFSET-B
206 # EXPLICIT-OFFSET-A: Start of section headers: 280 (bytes into file)
207 # EXPLICIT-OFFSET-A: [Nr] Name Type Address Off
208 # EXPLICIT-OFFSET-A-NEXT: [ 0] NULL 0000000000000000 000100
210 # EXPLICIT-OFFSET-B: Start of section headers: 536 (bytes into file)
211 # EXPLICIT-OFFSET-B: [Nr] Name Type Address Off
212 # EXPLICIT-OFFSET-B-NEXT: [ 0] NULL 0000000000000000 000200