xref: /llvm-project/llvm/test/tools/yaml2obj/ELF/versym-section.yaml (revision 9c89dcf80736a7c0710dc4c237ec35f0687e1efd)
1## Check we are able to produce a valid SHT_GNU_versym
2## section from its description.
3
4# RUN: yaml2obj --docnum=1 %s -o %t1
5# RUN: llvm-readobj -V %t1 | FileCheck %s
6
7# CHECK:      VersionSymbols [
8# CHECK-NEXT:   Symbol {
9# CHECK-NEXT:     Version: 0
10# CHECK-NEXT:     Name:
11# CHECK-NEXT:   }
12# CHECK-NEXT:   Symbol {
13# CHECK-NEXT:     Version: 3
14# CHECK-NEXT:     Name: f1@v1
15# CHECK-NEXT:   }
16# CHECK-NEXT:   Symbol {
17# CHECK-NEXT:     Version: 4
18# CHECK-NEXT:     Name: f2@v2
19# CHECK-NEXT:   }
20# CHECK-NEXT: ]
21# CHECK-NEXT: VersionDefinitions [
22# CHECK-NEXT: ]
23# CHECK-NEXT: VersionRequirements [
24# CHECK-NEXT:   Dependency {
25# CHECK-NEXT:     Version: 1
26# CHECK-NEXT:     Count: 2
27# CHECK-NEXT:     FileName: dso.so.0
28# CHECK-NEXT:     Entries [
29# CHECK-NEXT:       Entry {
30# CHECK-NEXT:         Hash: 1937
31# CHECK-NEXT:         Flags [ (0x0)
32# CHECK-NEXT:         ]
33# CHECK-NEXT:         Index: 3
34# CHECK-NEXT:         Name: v1
35# CHECK-NEXT:       }
36# CHECK-NEXT:       Entry {
37# CHECK-NEXT:         Hash: 1938
38# CHECK-NEXT:         Flags [ (0x0)
39# CHECK-NEXT:         ]
40# CHECK-NEXT:         Index: 4
41# CHECK-NEXT:         Name: v2
42# CHECK-NEXT:       }
43# CHECK-NEXT:     ]
44# CHECK-NEXT:   }
45# CHECK-NEXT: ]
46
47--- !ELF
48FileHeader:
49  Class: ELFCLASS64
50  Data:  ELFDATA2LSB
51  Type:  ET_EXEC
52  Entry: 0x0000000000201000
53Sections:
54  - Name:            .gnu.version
55    Type:            SHT_GNU_versym
56    Flags:           [ SHF_ALLOC ]
57    Address:         0x0000000000200210
58    AddressAlign:    0x0000000000000002
59    EntSize:         0x0000000000000002
60    Entries:         [ 0, 3, 4 ]
61  - Name:            .gnu.version_r
62    Type:            SHT_GNU_verneed
63    Flags:           [ SHF_ALLOC ]
64    Address:         0x0000000000200250
65    AddressAlign:    0x0000000000000004
66    Dependencies:
67      - Version:         1
68        File:            dso.so.0
69        Entries:
70          - Name:            v1
71            Hash:            1937
72            Flags:           0
73            Other:           3
74          - Name:            v2
75            Hash:            1938
76            Flags:           0
77            Other:           4
78DynamicSymbols:
79  - Name:    f1
80    Binding: STB_GLOBAL
81  - Name:    f2
82    Binding: STB_GLOBAL
83...
84
85## Check we are able to set custom sh_entsize field for SHT_GNU_versym section.
86## Check we link the SHT_GNU_versym section to the .dynsym section by default.
87
88# RUN: yaml2obj --docnum=2 %s -o %t2
89# RUN: llvm-readelf -S %t2 | FileCheck %s -DLINK=2 --check-prefix=FIELDS
90
91# FIELDS: Section Headers:
92# FIELDS:   [Nr] Name         Type   Address          Off    Size   ES Flg Lk
93# FIELDS:   [ 1] .gnu.version VERSYM 0000000000000000 000040 000000 03     [[LINK]]
94# FIELDS:   [ 2] .dynsym      DYNSYM 0000000000000000 000040 000018 18   A 3
95
96--- !ELF
97FileHeader:
98  Class: ELFCLASS64
99  Data:  ELFDATA2LSB
100  OSABI: ELFOSABI_FREEBSD
101  Type:  ET_DYN
102Sections:
103  - Name:    .gnu.version
104    Type:    SHT_GNU_versym
105    EntSize: 0x0000000000000003
106    Entries: [ ]
107    Link:    [[LINK=<none>]]
108## Needed to emit the .dynsym section.
109DynamicSymbols: []
110
111## Check we are able to set the sh_link field to an arbitrary value.
112
113# RUN: yaml2obj --docnum=2 -DLINK=0xff %s -o %t2.link
114# RUN: llvm-readelf -S %t2.link | FileCheck %s -DLINK=255 --check-prefix=FIELDS
115
116## Check we can use the "Content" key with the "Size" key when the size is greater
117## than or equal to the content size.
118## Also, check that we set the sh_link field to 0 when there is no .dynsym section.
119
120# RUN: not yaml2obj --docnum=3 -DSIZE=1 -DCONTENT="'0011'" %s 2>&1 | \
121# RUN:   FileCheck %s --check-prefix=CONTENT-SIZE-ERR
122
123# CONTENT-SIZE-ERR: error: Section size must be greater than or equal to the content size
124
125--- !ELF
126FileHeader:
127  Class: ELFCLASS64
128  Data:  ELFDATA2LSB
129  Type:  ET_DYN
130Sections:
131  - Name:    .gnu.version
132    Type:    SHT_GNU_versym
133    Size:    [[SIZE=<none>]]
134    Content: [[CONTENT=<none>]]
135    Entries: [[ENTRIES=<none>]]
136
137# RUN: yaml2obj --docnum=3 -DSIZE=2 -DCONTENT="'0011'" %s -o %t.cont.size.eq.o
138# RUN: llvm-readobj --sections --section-data %t.cont.size.eq.o | \
139# RUN:   FileCheck %s --check-prefix=CHECK-CONTENT -DDATA="0011"
140
141# RUN: yaml2obj --docnum=3 -DSIZE=3 -DCONTENT="'0011'" %s -o %t.cont.size.gr.o
142# RUN: llvm-readobj --sections --section-data %t.cont.size.gr.o | \
143# RUN:   FileCheck %s --check-prefix=CHECK-CONTENT -DDATA="001100"
144
145# CHECK-CONTENT:        Name: .gnu.version
146# CHECK-CONTENT-NEXT:   Type: SHT_GNU_versym (0x6FFFFFFF)
147# CHECK-CONTENT-NEXT:   Flags [ (0x0)
148# CHECK-CONTENT-NEXT:   ]
149# CHECK-CONTENT-NEXT:   Address:
150# CHECK-CONTENT-NEXT:   Offset:
151# CHECK-CONTENT-NEXT:   Size:
152# CHECK-CONTENT-NEXT:   Link: 0
153# CHECK-CONTENT:        SectionData (
154# CHECK-CONTENT-NEXT:   0000: [[DATA]] |
155# CHECK-CONTENT-NEXT: )
156
157## Check we can use the "Size" key alone to create the section.
158
159# RUN: yaml2obj --docnum=3 -DSIZE=3 %s -o %t.size.o
160# RUN: llvm-readobj --sections --section-data %t.size.o | \
161# RUN:   FileCheck %s --check-prefix=CHECK-CONTENT -DDATA="000000"
162
163## Check we can use the "Content" key alone to create the section.
164
165# RUN: yaml2obj --docnum=3 -DCONTENT="'112233'" %s -o %t.content.o
166# RUN: llvm-readobj --sections --section-data %t.content.o | \
167# RUN:   FileCheck %s --check-prefix=CHECK-CONTENT -DDATA="112233"
168
169## Check we can't use the "Entries" key together with the "Content" or "Size" keys.
170
171# RUN: not yaml2obj --docnum=3 -DSIZE=0 -DENTRIES="[]" %s 2>&1 | \
172# RUN:   FileCheck %s --check-prefix=ENTRIES-ERR
173# RUN: not yaml2obj --docnum=3 -DCONTENT="'00'" -DENTRIES="[]" %s 2>&1 | \
174# RUN:   FileCheck %s --check-prefix=ENTRIES-ERR
175
176# ENTRIES-ERR: error: "Entries" cannot be used with "Content" or "Size"
177
178## Check we set the sh_link field to 0 when the .dynsym section is excluded
179## from the section header table.
180
181# RUN: yaml2obj --docnum=4 %s -o %t4
182# RUN: llvm-readelf --sections %t4 | FileCheck %s --check-prefix=EXCLUDED
183
184# EXCLUDED: [Nr] Name         {{.*}} ES Flg Lk Inf
185# EXCLUDED: [ 1] .gnu.version {{.*}} 02     0   0
186
187--- !ELF
188FileHeader:
189  Class: ELFCLASS64
190  Data:  ELFDATA2LSB
191  Type:  ET_DYN
192Sections:
193  - Name: .gnu.version
194    Type: SHT_GNU_versym
195  - Name: .dynsym
196    Type: SHT_DYNSYM
197  - Type: SectionHeaderTable
198    Sections:
199      - Name: .gnu.version
200      - Name: .strtab
201      - Name: .shstrtab
202    Excluded:
203      - Name: .dynsym
204