1## Check how yaml2obj produces SHT_NOTE sections.
2
3## Check we can describe SHT_NOTE using the "Notes" tag. We can define
4## notes using names, descriptions and types.
5## Check we produce a valid name size and description size fields.
6## Check we produce valid paddings.
7
8# RUN: yaml2obj --docnum=1 %s -o %t1
9# RUN: llvm-readobj --sections --section-data %t1 | FileCheck %s --check-prefix=NOTE
10
11# NOTE:      Section {
12# NOTE:        Index: 1
13# NOTE-NEXT:   Name: .note.foo (1)
14# NOTE-NEXT:   Type: SHT_NOTE (0x7)
15# NOTE-NEXT:   Flags [ (0x2)
16# NOTE-NEXT:     SHF_ALLOC (0x2)
17# NOTE-NEXT:   ]
18# NOTE-NEXT:   Address:
19# NOTE-NEXT:   Offset:
20# NOTE-NEXT:   Size: 36
21# NOTE-NEXT:   Link: 0
22# NOTE-NEXT:   Info: 0
23# NOTE-NEXT:   AddressAlignment: 0
24# NOTE-NEXT:   EntrySize: 0
25# NOTE-NEXT:   SectionData (
26## namesz == (0x03000000) == sizeof("AB") + NUL terminator.
27## descsz == (0x00000000) for an empty description.
28## Check we produce a valid 2 bytes zeroes padding after the Name.
29# NOTE-NEXT:     0000: 03000000 00000000 FF000000 41420000  |............AB..|
30## namesz == (0x04000000) == sizeof("ABC") + NUL terminator.
31## descsz == (0x06000000) == sizeof("123456").
32## Check we produce a valid (zero align to 4) 1 byte padding after the Name.
33## Check we produce a valid (zero align to 4) 2 bytes padding after the Desc.
34# NOTE-NEXT:     0010: 04000000 03000000 FE000000 41424300  |............ABC.|
35# NOTE-NEXT:     0020: 12345600                             |.4V.|
36# NOTE-NEXT:   )
37
38--- !ELF
39FileHeader:
40  Class: ELFCLASS64
41  Data:  ELFDATA2LSB
42  Type:  ET_REL
43Sections:
44  - Name:  .note.foo
45    Type:  SHT_NOTE
46    Flags: [ SHF_ALLOC ]
47    Notes:
48      - Name: AB
49        Desc: ''
50        Type: 0xFF
51      - Name: ABC
52        Desc: '123456'
53        Type: 254
54
55## Check that for 32-bit little-endian case we produce the same section content.
56
57# RUN: yaml2obj --docnum=2 %s -o %t2
58# RUN: llvm-readobj --sections --section-data %t2 | FileCheck %s --check-prefix=NOTE
59
60--- !ELF
61FileHeader:
62  Class: ELFCLASS32
63  Data:  ELFDATA2LSB
64  Type:  ET_REL
65Sections:
66  - Name:  .note.foo
67    Type:  SHT_NOTE
68    Flags: [ SHF_ALLOC ]
69    Notes:
70      - Name: AB
71        Desc: ''
72        Type: 0xFF
73      - Name: ABC
74        Desc: '123456'
75        Type: 254
76
77## Check big-endian 32/64 bit cases.
78## Check they produce the same content.
79
80# RUN: yaml2obj --docnum=3 %s -o %t3
81# RUN: llvm-readobj --sections --section-data %t3 | FileCheck %s --check-prefix=NOTE-BE
82# RUN: yaml2obj --docnum=4 %s -o %t4
83# RUN: llvm-readobj --sections --section-data %t4 | FileCheck %s --check-prefix=NOTE-BE
84
85# NOTE-BE:      Name: .note.foo
86# NOTE-BE:      SectionData (
87# NOTE-BE-NEXT:   0000: 00000004 00000003 000000FE 41424300  |
88# NOTE-BE-NEXT:   0010: 12345600                             |
89# NOTE-BE-NEXT: )
90
91--- !ELF
92FileHeader:
93  Class: ELFCLASS32
94  Data:  ELFDATA2MSB
95  Type:  ET_REL
96Sections:
97  - Name: .note.foo
98    Type: SHT_NOTE
99    Notes:
100      - Name: ABC
101        Desc: '123456'
102        Type: 254
103
104--- !ELF
105FileHeader:
106  Class: ELFCLASS64
107  Data:  ELFDATA2MSB
108  Type:  ET_REL
109Sections:
110  - Name: .note.foo
111    Type: SHT_NOTE
112    Notes:
113      - Name: ABC
114        Desc: '123456'
115        Type: 254
116
117## Check that 'Type' field is mandatory.
118
119# RUN: not yaml2obj --docnum=5 %s 2>&1 | FileCheck %s --check-prefix=TYPE-REQ
120# TYPE-REQ: error: missing required key 'Type'
121
122--- !ELF
123FileHeader:
124  Class: ELFCLASS64
125  Data:  ELFDATA2LSB
126  Type:  ET_REL
127Sections:
128  - Name: .note.foo
129    Type: SHT_NOTE
130    Notes:
131      - Name: ''
132        Desc: ''
133
134## Check that neither `Name` nor `Desc` are mandatory fields.
135
136# RUN: yaml2obj --docnum=6 %s -o %t6
137# RUN: llvm-readobj --sections --section-data %t6 | FileCheck %s --check-prefix=NAME-DESC
138
139# NAME-DESC:      Name: .note.foo
140# NAME-DESC:      SectionData (
141# NAME-DESC-NEXT:   0000: 00000000 00000000 FF000000 |
142# NAME-DESC-NEXT: )
143
144--- !ELF
145FileHeader:
146  Class: ELFCLASS64
147  Data:  ELFDATA2LSB
148  Type:  ET_REL
149Sections:
150  - Name: .note.foo
151    Type: SHT_NOTE
152    Notes:
153      - Type: 0xFF
154
155## Check we can use the "Content" tag to specify any data for SHT_NOTE sections.
156
157# RUN: yaml2obj --docnum=7 %s -o %t7
158# RUN: llvm-readobj --sections --section-data %t7 | FileCheck %s --check-prefix=CONTENT
159
160# CONTENT:      Name: .note.foo
161# CONTENT:      SectionData (
162# CONTENT-NEXT:   0000: 11223344 55 |
163# CONTENT-NEXT: )
164
165--- !ELF
166FileHeader:
167  Class: ELFCLASS64
168  Data:  ELFDATA2LSB
169  Type:  ET_DYN
170Sections:
171  - Name:    .note.foo
172    Type:    SHT_NOTE
173    Content: "1122334455"
174
175## Check we emit an empty section if neither "Content", "Size" nor "Notes" were set.
176
177# RUN: yaml2obj --docnum=8 %s -o %t8
178# RUN: llvm-readelf --sections %t8 | FileCheck %s --check-prefix=NO-TAGS
179
180# NO-TAGS: [Nr] Name      Type Address          Off    Size
181# NO-TAGS: [ 1] .note.foo NOTE 0000000000000000 000040 000000
182
183--- !ELF
184FileHeader:
185  Class: ELFCLASS64
186  Data:  ELFDATA2LSB
187  Type:  ET_DYN
188Sections:
189  - Name: .note.foo
190    Type: SHT_NOTE
191
192## "Content" and "Notes" cannot be used together to describe the SHT_NOTE section.
193
194# RUN: not yaml2obj --docnum=9 %s 2>&1 | FileCheck %s --check-prefix=CONTENT-NOTES
195
196# CONTENT-NOTES: error: "Notes" cannot be used with "Content" or "Size"
197
198--- !ELF
199FileHeader:
200  Class: ELFCLASS64
201  Data:  ELFDATA2LSB
202  Type:  ET_DYN
203Sections:
204  - Name:    .note.foo
205    Type:    SHT_NOTE
206    Content: ""
207    Notes:   []
208
209## "Size" and "Notes" cannot be used together to describe the SHT_NOTE section.
210
211# RUN: not yaml2obj --docnum=10 %s 2>&1 | FileCheck %s --check-prefix=CONTENT-NOTES
212
213--- !ELF
214FileHeader:
215  Class: ELFCLASS64
216  Data:  ELFDATA2LSB
217  Type:  ET_DYN
218Sections:
219  - Name:  .note.foo
220    Type:  SHT_NOTE
221    Size:  1
222    Notes: []
223
224## Check we can use only "Size" to create a SHT_NOTE section.
225
226# RUN: yaml2obj --docnum=11 %s -o %t11
227# RUN: llvm-readobj --sections --section-data %t11 | FileCheck %s --check-prefix=SIZE
228
229# SIZE:      Name: .note.foo
230# SIZE:      SectionData (
231# SIZE-NEXT:   0000: 00000000 00000000 00000000 00000000  |
232# SIZE-NEXT:   0010: 00                                   |
233# SIZE-NEXT: )
234
235--- !ELF
236FileHeader:
237  Class: ELFCLASS64
238  Data:  ELFDATA2LSB
239  Type:  ET_EXEC
240Sections:
241  - Name: .note.foo
242    Type: SHT_NOTE
243    Size: 0x11
244
245## Check we can use "Size" and "Content" together to create a SHT_NOTE section.
246
247# RUN: yaml2obj --docnum=12 %s -o %t12
248# RUN: llvm-readobj --sections --section-data %t12 | FileCheck %s --check-prefix=SIZE-CONTENT
249
250# SIZE-CONTENT:      Name: .note.sizegr
251# SIZE-CONTENT:      SectionData (
252# SIZE-CONTENT-NEXT:   0000: 11223300 00 |
253# SIZE-CONTENT-NEXT: )
254
255# SIZE-CONTENT:      Name: .note.sizeeq
256# SIZE-CONTENT:      SectionData (
257# SIZE-CONTENT-NEXT:   0000: 112233 |
258# SIZE-CONTENT-NEXT: )
259
260--- !ELF
261FileHeader:
262  Class: ELFCLASS64
263  Data:  ELFDATA2LSB
264  Type:  ET_EXEC
265Sections:
266  - Name:    .note.sizegr
267    Type:    SHT_NOTE
268    Size:    0x5
269    Content: "112233"
270  - Name:    .note.sizeeq
271    Type:    SHT_NOTE
272    Size:    0x3
273    Content: "112233"
274
275## Check that when "Size" and "Content" are used together, the size
276## must be greater than or equal to the content size.
277
278# RUN: not yaml2obj --docnum=13 %s 2>&1 | FileCheck %s --check-prefix=SIZE-CONTENT-ERR
279# SIZE-CONTENT-ERR: error: Section size must be greater than or equal to the content size
280
281--- !ELF
282FileHeader:
283  Class: ELFCLASS64
284  Data:  ELFDATA2LSB
285  Type:  ET_EXEC
286Sections:
287  - Name:    .note
288    Type:    SHT_NOTE
289    Size:    0x1
290    Content: "1122"
291
292## Check we can't use "Size" and "Notes" tags together.
293
294# RUN: not yaml2obj --docnum=14 %s 2>&1 | FileCheck %s --check-prefix=CONTENT-NOTES
295
296--- !ELF
297FileHeader:
298  Class: ELFCLASS64
299  Data:  ELFDATA2LSB
300  Type:  ET_EXEC
301Sections:
302  - Name:  .note
303    Type:  SHT_NOTE
304    Size:  0x1
305    Notes: []
306