xref: /llvm-project/llvm/test/tools/yaml2obj/ELF/note-section.yaml (revision ba373096e8ac83a7136fc44bc4e71a7bc53417a6)
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
307## Check that we can use NT_* names for the note type.
308
309# RUN: yaml2obj --docnum=15 %s -o %t15
310# RUN: llvm-readobj --sections --section-data %t15 | FileCheck %s --check-prefix=TEXTUAL-TYPE
311
312# TEXTUAL-TYPE:      Name: .note.foo
313# TEXTUAL-TYPE:      SectionData (
314# TEXTUAL-TYPE-NEXT:   0000: 03000000 00000000 03000000 41420000  |............AB..|
315# TEXTUAL-TYPE-NEXT:   0010: 04000000 03000000 01000000 41424300  |............ABC.|
316# TEXTUAL-TYPE-NEXT:   0020: 12345600                             |.4V.|
317# TEXTUAL-TYPE-NEXT: )
318
319
320--- !ELF
321FileHeader:
322  Class: ELFCLASS64
323  Data:  ELFDATA2LSB
324  Type:  ET_EXEC
325Sections:
326  - Name:  .note.foo
327    Type:  SHT_NOTE
328    Flags: [ SHF_ALLOC ]
329    Notes:
330      - Name: AB
331        Desc: ''
332        Type: NT_GNU_BUILD_ID
333      - Name: ABC
334        Desc: '123456'
335        Type: NT_VERSION
336
337## Check that an incorrect alignment is reported.
338
339# RUN: not yaml2obj --docnum=16 %s 2>&1 | FileCheck %s --check-prefix=ERR_ALIGN1
340# ERR_ALIGN1: error: .note.foo: invalid alignment for a note section: 0x1
341
342--- !ELF
343FileHeader:
344  Class: ELFCLASS64
345  Data:  ELFDATA2LSB
346  Type:  ET_EXEC
347Sections:
348  - Name:         .note.foo
349    Type:         SHT_NOTE
350    AddressAlign: 1
351    Notes:
352      - Type: 0x1
353
354## Check that note entries and their "Desc" fields are aligned according to the
355## specified section alignment.
356
357# RUN: yaml2obj --docnum=17 -D ELFCLASS=64 %s -o - | \
358# RUN:   llvm-readobj --sections --section-data --notes - | \
359# RUN:   FileCheck %s --check-prefix=TEST17
360
361# RUN: yaml2obj --docnum=17 -D ELFCLASS=32 %s -o - | \
362# RUN:   llvm-readobj --sections --section-data --notes - | \
363# RUN:   FileCheck %s --check-prefix=TEST17
364
365# TEST17:      Name: .note.foo4
366# TEST17:      SectionData (
367# TEST17-NEXT:   0000: 05000000 02000000 01000000 41424344  |............ABCD|
368# TEST17-NEXT:   0010: 00000000 01020000 00000000 03000000  |................|
369# TEST17-NEXT:   0020: 02000000 03040500 04000000 00000000  |................|
370# TEST17-NEXT:   0030: 03000000 474E5500                    |....GNU.|
371# TEST17-NEXT: )
372# TEST17:      Name: .note.foo8
373# TEST17:      SectionData (
374# TEST17-NEXT:   0000: 05000000 02000000 01000000 41424344  |............ABCD|
375# TEST17-NEXT:   0010: 00000000 00000000 01020000 00000000  |................|
376# TEST17-NEXT:   0020: 00000000 03000000 02000000 00000000  |................|
377# TEST17-NEXT:   0030: 03040500 00000000 04000000 00000000  |................|
378# TEST17-NEXT:   0040: 03000000 474E5500                    |....GNU.|
379# TEST17-NEXT: )
380# TEST17:      NoteSections [
381# TEST17-NEXT:   NoteSection {
382# TEST17-NEXT:     Name: .note.foo4
383# TEST17-NEXT:     Offset:
384# TEST17-NEXT:     Size:
385# TEST17-NEXT:     Notes [
386# TEST17-NEXT:       {
387# TEST17-NEXT:         Owner: ABCD
388# TEST17-NEXT:         Data size: 0x2
389# TEST17-NEXT:         Type: NT_VERSION (version)
390# TEST17-NEXT:         Description data (
391# TEST17-NEXT:           0000: 0102                                 |..|
392# TEST17-NEXT:         )
393# TEST17-NEXT:       }
394# TEST17-NEXT:       {
395# TEST17-NEXT:         Owner:
396# TEST17-NEXT:         Data size: 0x3
397# TEST17-NEXT:         Type: NT_ARCH (architecture)
398# TEST17-NEXT:         Description data (
399# TEST17-NEXT:           0000: 030405                               |...|
400# TEST17-NEXT:         )
401# TEST17-NEXT:       }
402# TEST17-NEXT:       {
403# TEST17-NEXT:         Owner: GNU
404# TEST17-NEXT:         Data size: 0x0
405# TEST17-NEXT:         Type: NT_GNU_BUILD_ID (unique build ID bitstring)
406# TEST17-NEXT:         Build ID:
407# TEST17-NEXT:       }
408# TEST17-NEXT:     ]
409# TEST17-NEXT:   }
410# TEST17-NEXT:   NoteSection {
411# TEST17-NEXT:     Name: .note.foo8
412# TEST17-NEXT:     Offset:
413# TEST17-NEXT:     Size:
414# TEST17-NEXT:     Notes [
415# TEST17-NEXT:       {
416# TEST17-NEXT:         Owner: ABCD
417# TEST17-NEXT:         Data size: 0x2
418# TEST17-NEXT:         Type: NT_VERSION (version)
419# TEST17-NEXT:         Description data (
420# TEST17-NEXT:           0000: 0102                                 |..|
421# TEST17-NEXT:         )
422# TEST17-NEXT:       }
423# TEST17-NEXT:       {
424# TEST17-NEXT:         Owner:
425# TEST17-NEXT:         Data size: 0x3
426# TEST17-NEXT:         Type: NT_ARCH (architecture)
427# TEST17-NEXT:         Description data (
428# TEST17-NEXT:           0000: 030405                               |...|
429# TEST17-NEXT:         )
430# TEST17-NEXT:       }
431# TEST17-NEXT:       {
432# TEST17-NEXT:         Owner: GNU
433# TEST17-NEXT:         Data size: 0x0
434# TEST17-NEXT:         Type: NT_GNU_BUILD_ID (unique build ID bitstring)
435# TEST17-NEXT:         Build ID:
436# TEST17-NEXT:       }
437# TEST17-NEXT:     ]
438# TEST17-NEXT:   }
439# TEST17-NEXT: ]
440
441--- !ELF
442FileHeader:
443  Class: ELFCLASS[[ELFCLASS]]
444  Data:  ELFDATA2LSB
445  Type:  ET_EXEC
446Sections:
447  - Name:         .note.foo4
448    Type:         SHT_NOTE
449    AddressAlign: 4
450    Notes:
451      - Name: ABCD
452        Type: NT_VERSION
453        Desc: 0102
454      - Type: NT_ARCH
455        Desc: 030405
456      - Name: GNU
457        Type: NT_GNU_BUILD_ID
458  - Name:        .note.foo8
459    Type:         SHT_NOTE
460    AddressAlign: 8
461    Notes:
462      - Name: ABCD
463        Type: NT_VERSION
464        Desc: 0102
465      - Type: NT_ARCH
466        Desc: 030405
467      - Name: GNU
468        Type: NT_GNU_BUILD_ID
469
470## Check that the alignment for note entries is taken from the "AddressAlign"
471## field even if "ShAddrAlign" is also specified; an unexpected value in the
472## "ShAddrAlign" property does not trigger an incorrect alignment error.
473
474# RUN: yaml2obj --docnum=18 -D ADDRALIGN=0 -D SHADDRALIGN=8 %s -o - | \
475# RUN:   llvm-readobj --sections --section-data --notes - | \
476# RUN:   FileCheck %s --check-prefixes=TEST18,TEST18_4
477
478# RUN: yaml2obj --docnum=18 -D ADDRALIGN=4 -D SHADDRALIGN=3 %s -o - | \
479# RUN:   llvm-readobj --sections --section-data --notes - | \
480# RUN:   FileCheck %s --check-prefixes=TEST18,TEST18_4
481
482# RUN: yaml2obj --docnum=18 -D ADDRALIGN=8 -D SHADDRALIGN=4 %s -o - | \
483# RUN:   llvm-readobj --sections --section-data --notes - | \
484# RUN:   FileCheck %s --check-prefixes=TEST18,TEST18_8
485
486# TEST18:        Name: .note
487# TEST18:        SectionData (
488# TEST18_4-NEXT:   0000: 05000000 02000000 01000000 41424344  |............ABCD|
489# TEST18_4-NEXT:   0010: 00000000 01020000 00000000 03000000  |................|
490# TEST18_4-NEXT:   0020: 02000000 03040500 04000000 00000000  |................|
491# TEST18_4-NEXT:   0030: 03000000 474E5500                    |....GNU.|
492# TEST18_8-NEXT:   0000: 05000000 02000000 01000000 41424344  |............ABCD|
493# TEST18_8-NEXT:   0010: 00000000 00000000 01020000 00000000  |................|
494# TEST18_8-NEXT:   0020: 00000000 03000000 02000000 00000000  |................|
495# TEST18_8-NEXT:   0030: 03040500 00000000 04000000 00000000  |................|
496# TEST18_8-NEXT:   0040: 03000000 474E5500                    |....GNU.|
497# TEST18-NEXT:   )
498
499--- !ELF
500FileHeader:
501  Class: ELFCLASS64
502  Data:  ELFDATA2LSB
503  Type:  ET_EXEC
504Sections:
505  - Name:         .note
506    Type:         SHT_NOTE
507    AddressAlign: [[ADDRALIGN]]
508    ShAddrAlign:  [[SHADDRALIGN]]
509    Notes:
510      - Name: ABCD
511        Type: NT_VERSION
512        Desc: 0102
513      - Type: NT_ARCH
514        Desc: 030405
515      - Name: GNU
516        Type: NT_GNU_BUILD_ID
517
518## Check that an incorrect offset for generating notes is reported.
519
520# RUN: not yaml2obj --docnum=19 %s 2>&1 | FileCheck %s --check-prefix=ERR_OFFSET
521# ERR_OFFSET: error: .note: invalid offset of a note section: 0x501, should be aligned to 4
522
523--- !ELF
524FileHeader:
525  Class: ELFCLASS32
526  Data:  ELFDATA2LSB
527  Type:  ET_EXEC
528Sections:
529  - Name:   .note
530    Type:   SHT_NOTE
531    Offset: 0x501
532    Notes:
533      - Type: 0x1
534
535## Do not issue an error if the notes array is empty.
536
537# RUN: yaml2obj --docnum=20 %s -o - | \
538# RUN:   llvm-readobj --sections --section-data - | \
539# RUN:   FileCheck %s --check-prefix=TEST20
540
541# TEST20:      Section {
542# TEST20:      Name: .note
543# TEST20-NEXT:   Type: SHT_NOTE
544# TEST20-NEXT:   Flags [ (0x0)
545# TEST20-NEXT:   ]
546# TEST20-NEXT:   Address:
547# TEST20-NEXT:   Offset: 0x501
548# TEST20-NEXT:   Size: 0
549# TEST20-NEXT:   Link:
550# TEST20-NEXT:   Info:
551# TEST20-NEXT:   AddressAlignment: 5
552# TEST20-NEXT:   EntrySize:
553# TEST20-NEXT:   SectionData (
554# TEST20-NEXT:   )
555# TEST20-NEXT: }
556
557--- !ELF
558FileHeader:
559  Class: ELFCLASS32
560  Data:  ELFDATA2LSB
561  Type:  ET_EXEC
562Sections:
563  - Name:         .note
564    Type:         SHT_NOTE
565    Offset:       0x501
566    AddressAlign: 5
567    Notes:        []
568