1 ## Here we check that we are able to define sections with a type of "Fill".
2 ## Fills are custom pieces of data that can be placed anywhere just like normal
3 ## output sections, but they are not real output sections and you'll never see them in
4 ## the section headers.
6 ## Check we can create named and unnamed fills and use "Pattern" and "Size" fields
7 ## to describe the data emitted.
8 ## Check the data emitted and how it affects regular sections offsets.
9 ## Check that the "Name" field is optional for fills.
10 ## Check that "Size" can be greater than or equal to the pattern data size.
12 # RUN: yaml2obj --docnum=1 %s -o %t1
13 # RUN: llvm-readelf --sections --headers %t1 | FileCheck %s --check-prefix=BASIC
15 # BASIC: Number of section headers: 5
16 # BASIC: Section Headers:
17 # BASIC-NEXT: [Nr] Name Type Address Off Size ES Flg Lk Inf Al
18 # BASIC-NEXT: [ 0] NULL 0000000000000000 000000 000000 00 0 0 0
19 # BASIC-NEXT: [ 1] .foo PROGBITS 0000000000000000 000043 000002 00 0 0 0
20 # BASIC-NEXT: [ 2] .bar PROGBITS 0000000000000000 000049 000001 00 0 0 0
21 # BASIC-NEXT: [ 3] .strtab STRTAB 0000000000000000 00004b 000001 00 0 0 1
22 # BASIC-NEXT: [ 4] .shstrtab STRTAB 0000000000000000 00004c 00001d 00 0 0 1
24 ## The fill we dump starts at (offset of .foo - 3), which is (0x43 - 3) = 0x40.
25 # RUN: od -t x1 -v -j 0x40 -N 11 %t1 | FileCheck %s --ignore-case --check-prefix=DATA
26 # DATA: aa bb aa 11 22 cc dd cc dd ff ee
51 ## Check we can have no explicit regular sections in the YAML description, and can
52 ## describe the content with the use of fills only.
53 ## Check that "Size" can be less than the pattern data size.
55 # RUN: yaml2obj --docnum=2 %s -o %t2
56 # RUN: llvm-readelf --sections --headers %t2 | FileCheck %s --check-prefix=NOSECTIONS
58 ## The fill we dump starts at (offset of .strtab - 3 - 2), which is (0x45 - 5) = 0x40.
59 # RUN: od -t x1 -v -j 0x40 -N 6 %t2 | FileCheck %s --ignore-case --check-prefix=NOSECTIONS-DATA
61 # NOSECTIONS: Number of section headers: 3
62 # NOSECTIONS: Section Headers:
63 # NOSECTIONS-NEXT: [Nr] Name Type Address Off Size ES Flg Lk Inf Al
64 # NOSECTIONS-NEXT: [ 0] NULL 0000000000000000 000000 000000 00 0 0 0
65 # NOSECTIONS-NEXT: [ 1] .strtab STRTAB 0000000000000000 000045 000001 00 0 0 1
66 # NOSECTIONS-NEXT: [ 2] .shstrtab STRTAB 0000000000000000 000046 000013 00 0 0 1
68 ## .strtab that follows fills starts at 0x46 and always has a null character at the begining.
69 # NOSECTIONS-DATA: aa bb cc dd ee 00
84 ## Check we can use named fills when describing program headers.
85 ## Check that fills consume the file size and therefore affect the p_filesz fields of segments.
86 ## Check that the fill does not affect the p_align field of the segment.
88 # RUN: yaml2obj --docnum=3 %s -o %t3
89 # RUN: llvm-readelf --sections --program-headers %t3 | FileCheck %s --check-prefix=PHDR
91 # PHDR: [Nr] Name Type Address Off Size ES Flg Lk Inf Al
92 # PHDR: [ 0] NULL 0000000000000000 000000 000000 00 0 0 0
93 # PHDR: [ 1] .bar PROGBITS 0000000000000100 0000c0 000005 00 0 0 2
94 # PHDR: [ 2] .strtab STRTAB 0000000000000000 00010a 000001 00 0 0 1
95 # PHDR: [ 3] .shstrtab STRTAB 0000000000000000 00010b 000018 00 0 0 1
97 # PHDR: Program Headers:
98 # PHDR: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
99 # PHDR: LOAD 0x0000b0 0x0000000000000100 0x0000000000000100 0x00005a 0x00005a 0x2
100 # PHDR: GNU_RELRO 0x0000c5 0x0000000000000105 0x0000000000000105 0x000045 0x000045 0x1
131 ## Check that the "Pattern" field is not mandatory.
132 # RUN: yaml2obj --docnum=4 2>&1 -o %t4 %s
133 # RUN: llvm-readelf --sections %t4 | FileCheck %s --check-prefix=NOPATTERN
135 ## The fill we dump starts at (offset of .strtab - 1 - 3 - 1), which is (0x45 - 5) = 0x40.
136 # RUN: od -t x1 -v -j 0x40 -N 5 %t4 | FileCheck %s --ignore-case --check-prefix=NOPATTERN-DATA
138 # NOPATTERN: [Nr] Name Type Address Off
139 # NOPATTERN: [ 1] .strtab STRTAB 0000000000000000 000045
141 # NOPATTERN-DATA: aa 00 00 00 bb
158 ## Check that the "Size" field is mandatory.
159 # RUN: not yaml2obj --docnum=5 2>&1 %s | FileCheck %s --check-prefix=NOSIZE
161 ## NOSIZE: error: missing required key 'Size'
172 ## Check that fills are not allowed to have duplicate names.
173 # RUN: not yaml2obj --docnum=6 2>&1 %s | FileCheck %s --check-prefix=UNIQUE-NAME
175 # UNIQUE-NAME: error: repeated section/fill name: 'foo' at YAML section/fill number 2
176 # UNIQUE-NAME: error: repeated section/fill name: 'foo' at YAML section/fill number 3
195 ## Check that "Pattern" can be empty, when "Size" is zero.
196 # RUN: yaml2obj --docnum=7 2>&1 %s -o %t7
197 # RUN: llvm-readelf --sections %t7 | FileCheck %s --check-prefix=NOOP
199 # NOOP: [Nr] Name Type Address Off
200 # NOOP: [ 1] begin PROGBITS 0000000000000000 000040
201 # NOOP: [ 2] end PROGBITS 0000000000000000 000041
219 ## Check that we can have an empty "Pattern", but have non-zero "Size".
220 ## In this case we emit Size number of zeroes to the output.
222 # RUN: yaml2obj --docnum=8 2>&1 -o %t8 %s
223 # RUN: llvm-readelf --sections %t8 | FileCheck %s --check-prefix=EMPTY-PATTERN
225 ## The fill we dump starts at (offset of .strtab - 1 - 3 - 1), which is (0x45 - 5) = 0x40.
226 # RUN: od -t x1 -v -j 0x40 -N 5 %t8 | FileCheck %s --ignore-case --check-prefix=EMPTY-PATTERN-DATA
228 # EMPTY-PATTERN: Section Headers:
229 # EMPTY-PATTERN-NEXT: [Nr] Name Type Address Off Size ES Flg Lk Inf Al
230 # EMPTY-PATTERN-NEXT: [ 0] NULL 0000000000000000 000000 000000 00 0 0 0
231 # EMPTY-PATTERN-NEXT: [ 1] .strtab STRTAB 0000000000000000 000045 000001 00 0 0 1
233 # EMPTY-PATTERN-DATA: aa 00 00 00 bb
251 ## Check that "Size" can't be 0, when "Pattern" is not empty.
252 # RUN: not yaml2obj --docnum=9 2>&1 %s | FileCheck %s --check-prefix=ZERO-SIZE-ERR
254 # ZERO-SIZE-ERR: error: "Size" can't be 0 when "Pattern" is not empty
266 ## Check we report an error when a program header references
267 ## an unknown section or fill and have at least one Fill defined.
269 # RUN: not yaml2obj --docnum=10 2>&1 %s | FileCheck %s --check-prefix=UNKNOWN-ERR
270 # UNKNOWN-ERR: error: unknown section or fill referenced: 'fill' by the 'FirstSec' key of the program header with index 0
271 # UNKNOWN-ERR: error: unknown section or fill referenced: 'fill' by the 'LastSec' key of the program header with index 0
287 ## Show that we can use the "Offset" key to set an arbitrary offset for a Fill.
289 ## 0x41 is the minimal possible valid offset for Fill,
290 ## because the .foo section of size 0x1 is placed at 0x40.
291 # RUN: yaml2obj --docnum=11 -DOFFSET=0x41 -o %t11 %s
292 # RUN: llvm-readelf --section-headers %t11 | FileCheck %s --check-prefix=OFFSET-MIN
294 ## 0x123 is an arbitrary offset.
295 # RUN: yaml2obj --docnum=11 -DOFFSET=0x123 -o %t12 %s
296 # RUN: llvm-readelf --section-headers %t12 | FileCheck %s --check-prefix=OFFSET
298 # OFFSET-MIN: Section Headers:
299 # OFFSET-MIN-NEXT: [Nr] Name Type Address Off Size
300 # OFFSET-MIN-NEXT: [ 0] NULL 0000000000000000 000000 000000
301 # OFFSET-MIN-NEXT: [ 1] .foo PROGBITS 0000000000000000 000040 000001
302 # OFFSET-MIN-NEXT: [ 2] .bar PROGBITS 0000000000000000 000042 000001
304 # OFFSET: Section Headers:
305 # OFFSET-NEXT: [Nr] Name Type Address Off Size
306 # OFFSET-NEXT: [ 0] NULL 0000000000000000 000000 000000
307 # OFFSET-NEXT: [ 1] .foo PROGBITS 0000000000000000 000040 000001
308 # OFFSET-NEXT: [ 2] .bar PROGBITS 0000000000000000 000124 000001
327 ## Show that the "Offset" value can't go backward.
328 # RUN: not yaml2obj --docnum=11 -DOFFSET=0x40 2>&1 %s | FileCheck %s --check-prefix=OFFSET-ERR
330 # OFFSET-ERR: error: the 'Offset' value (0x40) goes backward