1 ## Check how the "Offset" field is dumped by obj2yaml.
2 ## For each section we calulate the expected offset.
3 ## When it does not match the actual offset, we emit the "Offset" key.
5 # RUN: yaml2obj %s -o %t1.o
6 # RUN: obj2yaml %t1.o | FileCheck %s --check-prefix=BASIC
9 # BASIC-NEXT: FileHeader:
10 # BASIC-NEXT: Class: ELFCLASS64
11 # BASIC-NEXT: Data: ELFDATA2LSB
12 # BASIC-NEXT: Type: ET_REL
13 # BASIC-NEXT: Sections:
14 # BASIC-NEXT: - Name: .foo1
15 # BASIC-NEXT: Type: SHT_PROGBITS
16 # BASIC-NEXT: Content: '00'
17 # BASIC-NEXT: - Name: .foo2
18 # BASIC-NEXT: Type: SHT_PROGBITS
19 # BASIC-NEXT: Content: '00'
20 # BASIC-NEXT: - Name: .foo3
21 # BASIC-NEXT: Type: SHT_PROGBITS
22 # BASIC-NEXT: Content: '00'
23 # BASIC-NEXT: - Name: .bar1
24 # BASIC-NEXT: Type: SHT_PROGBITS
25 # BASIC-NEXT: Offset: 0x100
26 # BASIC-NEXT: Content: '00'
27 # BASIC-NEXT: - Name: .bar2
28 # BASIC-NEXT: Type: SHT_PROGBITS
29 # BASIC-NEXT: AddressAlign: 0x10
30 # BASIC-NEXT: Content: '00'
31 # BASIC-NEXT: - Name: .bar3
32 # BASIC-NEXT: Type: SHT_PROGBITS
33 # BASIC-NEXT: AddressAlign: 0x10
34 # BASIC-NEXT: Offset: 0x200
35 # BASIC-NEXT: - Name: .bar4
36 # BASIC-NEXT: Type: SHT_PROGBITS
37 # BASIC-NEXT: AddressAlign: 0x100000000
38 # BASIC-NEXT: Offset: 0x210
39 # HEADERS-NEXT: - Type: SectionHeaderTable
40 # HEADERS-NEXT: Sections:
41 # HEADERS-NEXT: - Name: .bar4
42 # HEADERS-NEXT: - Name: .bar3
43 # HEADERS-NEXT: - Name: .bar2
44 # HEADERS-NEXT: - Name: .bar1
45 # HEADERS-NEXT: - Name: .foo3
46 # HEADERS-NEXT: - Name: .foo2
47 # HEADERS-NEXT: - Name: .foo1
48 # HEADERS-NEXT: - Name: .strtab
49 # HEADERS-NEXT: - Name: .shstrtab
58 ## The offset of .foo1 by default is 0x40, because it is placed right
59 ## after the ELF header. In this case we don't dump the "Offset" key,
60 ## because the file offset is naturally expected.
64 Offset: [[FIRSTOFF=<none>]]
65 AddressAlign: [[FIRSTADDRALIGN=0]]
66 ## Offset of .foo2 == offset of .foo1 + size of .foo1.
67 ## We don't dump the "Offset" key in this case.
68 ## sh_offset of .foo2 is 0x41.
72 ## Offset of .foo3 == offset of .foo2 + size of .foo2,
73 ## We don't dump the "Offset" key in this case.
74 ## sh_offset of .foo3 is 0x42.
78 ## Offset of .bar1 != offset of .foo3 + size of .foo3.
79 ## We dump the "Offset" key in this case.
80 ## sh_offset of .bar1 is 0x100.
85 ## [Offset of .bar1 + size of .bar1] aligned by 0x10 is equal to the offset
86 ## of .bar2. We don't dump the "Offset" key in this case.
87 ## sh_offset of .bar2 is 0x110.
93 ## [Offset of .bar2 + size of .bar2] aligned by 0x10 is not equal to the offset
94 ## of .bar3. We dump the "Offset" key in this case.
95 ## sh_offset of .bar3 is 0x200.
100 ## A case where AddressAlign > MAX_UINT32 and (uint32_t)AddressAlign == 0.
101 ## Check we dump an offset in this case properly.
104 AddressAlign: 0x100000000
106 - Type: SectionHeaderTable
108 ## By default we have the same order of sections as defined by the "Sections" key.
109 - Name: [[SEC1=.foo1]]
110 - Name: [[SEC2=.foo2]]
111 - Name: [[SEC3=.foo3]]
112 - Name: [[SEC4=.bar1]]
113 - Name: [[SEC5=.bar2]]
114 - Name: [[SEC6=.bar3]]
115 - Name: [[SEC7=.bar4]]
119 ## In this case we change the order of sections in the section header table.
120 ## Check that we still dump offsets correctly.
122 # RUN: yaml2obj %s -DSEC1=.bar4 -DSEC2=.bar3 -DSEC3=.bar2 \
123 # RUN: -DSEC4=.bar1 -DSEC5=.foo3 -DSEC6=.foo2 -DSEC7=.foo1 -o %t1-sechdr.o
124 # RUN: obj2yaml %t1-sechdr.o | FileCheck --check-prefixes=BASIC,HEADERS %s
126 ## Show we dump the "Offset" key for the first section when
127 ## it has an unexpected file offset.
129 # RUN: yaml2obj %s -DFIRSTOFF=0x40 -o %t2a.o
130 # RUN: obj2yaml %t2a.o | FileCheck %s --check-prefix=BASIC
131 # RUN: yaml2obj %s -DFIRSTOFF=0x41 -o %t2b.o
132 # RUN: obj2yaml %t2b.o | FileCheck %s --check-prefix=FIRSTSEC
134 # FIRSTSEC: Sections:
135 # FIRSTSEC-NEXT: - Name: .foo1
136 # FIRSTSEC-NEXT: Type: SHT_PROGBITS
137 # FIRSTSEC-NEXT: Offset: 0x41
138 # FIRSTSEC-NEXT: Content: '00'
140 ## Test that we take the alignment of the first section into account
141 ## when calculating the expected offset for it. In this case we don't
142 ## dump the "Offset", because it is expected.
144 # RUN: yaml2obj %s -DFIRSTOFF=0x80 -DFIRSTADDRALIGN=0x80 -o %t3.o
145 # RUN: obj2yaml %t3.o | FileCheck %s --check-prefix=FIRSTSECALIGN
147 # FIRSTSECALIGN: - Name: .foo1
148 # FIRSTSECALIGN-NEXT: Type: SHT_PROGBITS
149 # FIRSTSECALIGN-NEXT: AddressAlign: 0x80
150 # FIRSTSECALIGN-NEXT: Content: '00'
151 # FIRSTSECALIGN-NEXT: - Name:
153 ## Test that we take the program headers offset and size into account when calculating
154 ## the expected file offset of the first section.
156 # RUN: yaml2obj %s --docnum=2 -o %t4a.o
157 # RUN: obj2yaml %t4a.o | FileCheck %s --check-prefix=FIRSTSECPHDRS
158 ## The expected file offset of the first section is:
159 ## 0x40 (start of program headers) + 0x38 (size of program headers) * 2(number of program headers) = 0xB0
160 # RUN: yaml2obj %s --docnum=2 -DFIRSTOFF=0xB0 -o %t4b.o
161 # RUN: obj2yaml %t4b.o | FileCheck %s --check-prefix=FIRSTSECPHDRS
162 # RUN: yaml2obj %s --docnum=2 -DFIRSTOFF=0xB1 -o %t4c.o
163 # RUN: obj2yaml %t4c.o | FileCheck %s --check-prefixes=FIRSTSECPHDRS,FIRSTSECPHDRSOFFSET
165 # FIRSTSECPHDRS: Sections:
166 # FIRSTSECPHDRS-NEXT: - Name: .foo
167 # FIRSTSECPHDRS-NEXT: Type: SHT_PROGBITS
168 # FIRSTSECPHDRSOFFSET-NEXT: Offset: 0xB1
169 # FIRSTSECPHDRS-NEXT: ...
179 Offset: [[FIRSTOFF=<none>]]
184 ## Test that when there are no program headers in the file, we don't take SHT_NOBITS
185 ## section sizes into account, but respect their alignment when calculating the expected
188 # RUN: yaml2obj %s --docnum=3 -o %t5.o
189 # RUN: obj2yaml %t5.o | FileCheck %s --check-prefix=NOBITS
192 # NOBITS-NEXT: - Name: .progbits1
193 # NOBITS-NEXT: Type: SHT_PROGBITS
194 # NOBITS-NEXT: Content: '00'
195 # NOBITS-NEXT: - Name: .nobits1
196 # NOBITS-NEXT: Type: SHT_NOBITS
197 # NOBITS-NEXT: Size: 0x10
198 # NOBITS-NEXT: - Name: .progbits2
199 # NOBITS-NEXT: Type: SHT_PROGBITS
200 # NOBITS-NEXT: Content: '0000'
201 # NOBITS-NEXT: - Name: .nobits2
202 # NOBITS-NEXT: Type: SHT_NOBITS
203 # NOBITS-NEXT: AddressAlign: 0x100
204 # NOBITS-NEXT: Size: 0x100
205 # NOBITS-NEXT: - Name: .progbits3
206 # NOBITS-NEXT: Type: SHT_PROGBITS
207 # NOBITS-NEXT: Content: '000000'
216 ## sh_offset == 0x40.
220 ## sh_offset == 0x41.
224 ## sh_offset == 0x41.
228 ## sh_offset == 0x100.
233 ## sh_offset == 0x100.
238 ## Check that we might take sizes of SHT_NOBITS sections into account when calculating
239 ## the expected offsets when there are program headers in the file. The rule is the following:
240 ## we assume that the file space is allocated for the SHT_NOBITS section when there are
241 ## other non-nobits sections in the same segment that follows it.
243 # RUN: yaml2obj %s --docnum=4 -o %t6.o
244 # RUN: obj2yaml %t6.o | FileCheck %s --check-prefix=NOBITS-PHDRS
246 # NOBITS-PHDRS: Sections:
247 # NOBITS-PHDRS-NEXT: - Name: .nobits1
248 # NOBITS-PHDRS-NEXT: Type: SHT_NOBITS
249 # NOBITS-PHDRS-NEXT: Size: 0x1
250 # NOBITS-PHDRS-NEXT: - Name: .progbits
251 # NOBITS-PHDRS-NEXT: Type: SHT_PROGBITS
252 # NOBITS-PHDRS-NEXT: Content: '0000'
253 # NOBITS-PHDRS-NEXT: - Name: .nobits3
254 # NOBITS-PHDRS-NEXT: Type: SHT_NOBITS
255 # NOBITS-PHDRS-NEXT: Size: 0x100
256 # NOBITS-PHDRS-NEXT: - Name: .nobits4
257 # NOBITS-PHDRS-NEXT: Type: SHT_NOBITS
258 # NOBITS-PHDRS-NEXT: Size: 0x200
259 # NOBITS-PHDRS-NEXT: - Name: .nobits5
260 # NOBITS-PHDRS-NEXT: Type: SHT_NOBITS
261 # NOBITS-PHDRS-NEXT: Offset: 0x100
262 # NOBITS-PHDRS-NEXT: Size: 0x300
263 # NOBITS-PHDRS-NEXT: ...
271 ## sh_offset == 0xe8.
275 ## sh_offset == 0xe9.
279 ## sh_offset == 0xeb.
283 ## sh_offset == 0xeb.
287 ## sh_offset == 0x100.