• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1## Check how yaml2obj produces SHT_GNU_HASH sections.
2
3## Check we can describe a SHT_GNU_HASH section using the "Content" tag.
4## Check we set sh_link to index of the .dynsym by default.
5
6# RUN: yaml2obj --docnum=1 %s -o %t1
7# RUN: llvm-readobj --sections --section-data %t1 | FileCheck %s --check-prefix=CONTENT
8
9# CONTENT:      Name: .gnu.hash
10# CONTENT-NEXT: Type: SHT_GNU_HASH
11# CONTENT-NEXT: Flags [
12# CONTENT-NEXT: ]
13# CONTENT-NEXT: Address: 0x0
14# CONTENT-NEXT: Offset: 0x40
15# CONTENT-NEXT: Size: 3
16# CONTENT-NEXT: Link: 2
17# CONTENT-NEXT: Info: 0
18# CONTENT-NEXT: AddressAlignment: 0
19# CONTENT-NEXT: EntrySize: 0
20# CONTENT-NEXT: SectionData (
21# CONTENT-NEXT:   0000: 001122 |
22# CONTENT-NEXT: )
23# CONTENT:      Index: 2
24# CONTENT-NEXT: Name: .dynsym (9)
25
26--- !ELF
27FileHeader:
28  Class: ELFCLASS64
29  Data:  ELFDATA2LSB
30  Type:  ET_DYN
31Sections:
32  - Name:  .gnu.hash
33    Type:  SHT_GNU_HASH
34    Content: "001122"
35## Used to trigger .dynsym creation.
36DynamicSymbols: []
37
38## Check we can use "Header", "BloomFilter", "HashBuckets" and "HashValues" keys to describe
39## the hash section. Check we can set sh_link to any arbitrary value. Check both ELFCLASS32 and 64 bit output.
40
41# RUN: yaml2obj --docnum=2 %s -o %t2
42# RUN: yaml2obj --docnum=3 %s -o %t3
43# RUN: llvm-readobj --sections --section-data %t2 | FileCheck %s --check-prefix=CONTENT32
44# RUN: llvm-readobj --sections --section-data %t3 | FileCheck %s --check-prefix=CONTENT64
45
46# CONTENT32:      Name: .gnu.hash
47# CONTENT32-NEXT: Type: SHT_GNU_HASH
48# CONTENT32-NEXT: Flags [
49# CONTENT32-NEXT:   SHF_ALLOC
50# CONTENT32-NEXT: ]
51# CONTENT32-NEXT: Address: 0x0
52# CONTENT32-NEXT: Offset: 0x34
53# CONTENT32-NEXT: Size: 52
54# CONTENT32-NEXT: Link: 254
55# CONTENT32-NEXT: Info: 0
56# CONTENT32-NEXT: AddressAlignment: 0
57# CONTENT32-NEXT: EntrySize: 0
58# CONTENT32-NEXT: SectionData (
59# CONTENT32-NEXT:   0000: 03000000 01000000 02000000 02000000 |
60# CONTENT32-NEXT:   0010: 03000000 04000000 05000000 06000000 |
61# CONTENT32-NEXT:   0020: 07000000 08000000 09000000 0A000000 |
62# CONTENT32-NEXT:   0030: 0B000000                            |
63# CONTENT32-NEXT: )
64
65# CONTENT64:      Name: .gnu.hash
66# CONTENT64-NEXT: Type: SHT_GNU_HASH
67# CONTENT64-NEXT: Flags [
68# CONTENT64-NEXT:   SHF_ALLOC
69# CONTENT64-NEXT: ]
70# CONTENT64-NEXT: Address: 0x0
71# CONTENT64-NEXT: Offset: 0x40
72# CONTENT64-NEXT: Size: 60
73# CONTENT64-NEXT: Link: 254
74# CONTENT64-NEXT: Info: 0
75# CONTENT64-NEXT: AddressAlignment: 0
76# CONTENT64-NEXT: EntrySize: 0
77# CONTENT64-NEXT: SectionData (
78# CONTENT64-NEXT:   0000: 03000000 01000000 02000000 02000000 |
79# CONTENT64-NEXT:   0010: 03000000 00000000 04000000 00000000 |
80# CONTENT64-NEXT:   0020: 05000000 06000000 07000000 08000000 |
81# CONTENT64-NEXT:   0030: 09000000 0A000000 0B000000          |
82# CONTENT64-NEXT: )
83
84--- !ELF
85FileHeader:
86  Class: ELFCLASS32
87  Data:  ELFDATA2LSB
88  Type:  ET_DYN
89Sections:
90  - Name:  .gnu.hash
91    Type:  SHT_GNU_HASH
92    Flags: [ SHF_ALLOC ]
93    Header:
94      SymNdx: 0x1
95      Shift2: 0x2
96    BloomFilter: [0x3, 0x4]
97    HashBuckets: [0x5, 0x6, 0x7]
98    HashValues:  [0x8, 0x9, 0xA, 0xB]
99    Link: 0xFE
100
101--- !ELF
102FileHeader:
103  Class: ELFCLASS64
104  Data:  ELFDATA2LSB
105  Type:  ET_DYN
106Sections:
107  - Name:  .gnu.hash
108    Type:  SHT_GNU_HASH
109    Flags: [ SHF_ALLOC ]
110    Header:
111      SymNdx: 0x1
112      Shift2: 0x2
113    BloomFilter: [0x3, 0x4]
114    HashBuckets: [0x5, 0x6, 0x7]
115    HashValues:  [0x8, 0x9, 0xA, 0xB]
116    Link: 0xFE
117
118## Check we only can use "Header", "BloomFilter", "HashBuckets" and "HashValues" together.
119
120# RUN: not yaml2obj --docnum=4 %s -o %t4 2>&1 | FileCheck %s --check-prefix=ERR
121# RUN: not yaml2obj --docnum=5 %s -o %t5 2>&1 | FileCheck %s --check-prefix=ERR
122# RUN: not yaml2obj --docnum=6 %s -o %t6 2>&1 | FileCheck %s --check-prefix=ERR
123# RUN: not yaml2obj --docnum=7 %s -o %t7 2>&1 | FileCheck %s --check-prefix=ERR
124
125# ERR: error: "Header", "BloomFilter", "HashBuckets" and "HashValues" must be used together
126
127--- !ELF
128FileHeader:
129  Class: ELFCLASS64
130  Data:  ELFDATA2LSB
131  Type:  ET_DYN
132Sections:
133  - Name:  .gnu.hash.no.header
134    Type:  SHT_GNU_HASH
135    BloomFilter: []
136    HashBuckets: []
137    HashValues: []
138
139--- !ELF
140FileHeader:
141  Class: ELFCLASS64
142  Data:  ELFDATA2LSB
143  Type:  ET_DYN
144Sections:
145  - Name:  .gnu.hash.no.bloomfilter
146    Type:  SHT_GNU_HASH
147    Header:
148      SymNdx: 0x0
149      Shift2: 0x0
150    HashBuckets: []
151    HashValues: []
152
153--- !ELF
154FileHeader:
155  Class: ELFCLASS64
156  Data:  ELFDATA2LSB
157  Type:  ET_DYN
158Sections:
159  - Name:  .gnu.hash.no.nobuckets
160    Type:  SHT_GNU_HASH
161    Header:
162      SymNdx: 0x0
163      Shift2: 0x0
164    BloomFilter: []
165    HashValues: []
166
167--- !ELF
168FileHeader:
169  Class: ELFCLASS64
170  Data:  ELFDATA2LSB
171  Type:  ET_DYN
172Sections:
173  - Name:  .gnu.hash.no.novalues
174    Type:  SHT_GNU_HASH
175    Header:
176      SymNdx: 0x0
177      Shift2: 0x0
178    BloomFilter: []
179    HashBuckets: []
180
181## Check that "SymNdx" and "Shift2" fields are mandatory when we specify the "Header".
182
183# RUN: not yaml2obj --docnum=8 %s -o %t8 2>&1 | FileCheck %s --check-prefix=ERR2
184# ERR2: error: missing required key 'SymNdx'
185
186# RUN: not yaml2obj --docnum=9 %s -o %t9 2>&1 | FileCheck %s --check-prefix=ERR3
187# ERR3: error: missing required key 'Shift2'
188
189--- !ELF
190FileHeader:
191  Class: ELFCLASS64
192  Data:  ELFDATA2LSB
193  Type:  ET_DYN
194Sections:
195  - Name:  .gnu.hash
196    Type:  SHT_GNU_HASH
197    Header:
198      Shift2: 0x0
199
200--- !ELF
201FileHeader:
202  Class: ELFCLASS64
203  Data:  ELFDATA2LSB
204  Type:  ET_DYN
205Sections:
206  - Name:  .gnu.hash
207    Type:  SHT_GNU_HASH
208    Header:
209      SymNdx: 0x0
210
211## Check we emit an empty section if neither "Content", "Header",
212## "BloomFilter", "HashBuckets" nor "HashBuckets" were set.
213
214# NOKEYS: Section Headers:
215# NOKEYS:  [Nr] Name      Type     Address          Off    Size
216# NOKEYS:  [ 1] .gnu.hash GNU_HASH 0000000000000000 000040 000000
217
218# RUN: yaml2obj --docnum=10 %s -o %t10
219# RUN: llvm-readelf --sections %t10 | FileCheck %s --check-prefix=NOKEYS
220
221--- !ELF
222FileHeader:
223  Class: ELFCLASS64
224  Data:  ELFDATA2LSB
225  Type:  ET_DYN
226Sections:
227  - Name:  .gnu.hash
228    Type:  SHT_GNU_HASH
229
230## Test that "Header", "BloomFilter", "HashBuckets" and "HashValues" can't be used together with the "Content" or "Size"
231
232# RUN: not yaml2obj --docnum=11 -DCONTENT="" %s 2>&1 | FileCheck %s --check-prefix=TOGETHER
233# RUN: not yaml2obj --docnum=11 -DSIZE=0 %s 2>&1 | FileCheck %s --check-prefix=TOGETHER
234# TOGETHER: error: "Header", "BloomFilter", "HashBuckets" and "HashValues" cannot be used with "Content" or "Size"
235
236--- !ELF
237FileHeader:
238  Class: ELFCLASS32
239  Data:  ELFDATA2LSB
240  Type:  ET_DYN
241Sections:
242  - Name:    .gnu.hash
243    Type:    SHT_GNU_HASH
244    Content: [[CONTENT=<none>]]
245    Size:    [[SIZE=<none>]]
246    Header:
247      SymNdx: 0x0
248      Shift2: 0x0
249    BloomFilter: []
250    HashBuckets: []
251    HashValues:  []
252
253## Test we can override the number of buckets and the number of words in the Bloom filter
254## using the "NBuckets" and "Shift2" keys.
255
256# RUN: yaml2obj --docnum=12 %s -o %t12
257# RUN: llvm-readobj --sections --section-data %t12 | FileCheck %s --check-prefix=OVERRIDE-CONTENT
258
259# OVERRIDE-CONTENT:      Name: .gnu.hash
260# OVERRIDE-CONTENT:      SectionData (
261# OVERRIDE-CONTENT-NEXT:   0000: 01000000 02000000 03000000 04000000  |
262# OVERRIDE-CONTENT-NEXT: )
263
264--- !ELF
265FileHeader:
266  Class: ELFCLASS32
267  Data:  ELFDATA2LSB
268  Type:  ET_DYN
269Sections:
270  - Name:  .gnu.hash
271    Type:  SHT_GNU_HASH
272    Header:
273      NBuckets:  0x1
274      SymNdx:    0x2
275      MaskWords: 0x3
276      Shift2:    0x4
277    BloomFilter: []
278    HashBuckets: []
279    HashValues:  []
280
281## Check we can use the "Content" key with the "Size" key when the size is greater
282## than or equal to the content size.
283
284# RUN: not yaml2obj --docnum=13 -DSIZE=1 -DCONTENT="'0011'" %s 2>&1 | \
285# RUN:   FileCheck %s --check-prefix=CONTENT-SIZE-ERR
286
287# CONTENT-SIZE-ERR: error: Section size must be greater than or equal to the content size
288
289--- !ELF
290FileHeader:
291  Class: ELFCLASS64
292  Data:  ELFDATA2LSB
293  Type:  ET_DYN
294Sections:
295  - Name:    .gnu.hash
296    Type:    SHT_GNU_HASH
297    Size:    [[SIZE=<none>]]
298    Content: [[CONTENT=<none>]]
299
300# RUN: yaml2obj --docnum=13 -DSIZE=2 -DCONTENT="'0011'" %s -o %t.cont.size.eq.o
301# RUN: llvm-readobj --sections --section-data %t.cont.size.eq.o | \
302# RUN:   FileCheck %s --check-prefix=CHECK-CONTENT -DDATA="0011"
303
304# RUN: yaml2obj --docnum=13 -DSIZE=3 -DCONTENT="'0011'" %s -o %t.cont.size.gr.o
305# RUN: llvm-readobj --sections --section-data %t.cont.size.gr.o | \
306# RUN:   FileCheck %s --check-prefix=CHECK-CONTENT -DDATA="001100"
307
308# CHECK-CONTENT:      Name: .gnu.hash
309# CHECK-CONTENT:      SectionData (
310# CHECK-CONTENT-NEXT:   0000: [[DATA]] |
311# CHECK-CONTENT-NEXT: )
312
313## Check we can use the "Size" key alone to create the section.
314
315# RUN: yaml2obj --docnum=13 -DSIZE=3 %s -o %t.size.o
316# RUN: llvm-readobj --sections --section-data %t.size.o | \
317# RUN:   FileCheck %s --check-prefix=CHECK-CONTENT -DDATA="000000"
318
319## Check we can use the "Content" key alone to create the section.
320
321# RUN: yaml2obj --docnum=13 -DCONTENT="'112233'" %s -o %t.content.o
322# RUN: llvm-readobj --sections --section-data %t.content.o | \
323# RUN:   FileCheck %s --check-prefix=CHECK-CONTENT -DDATA="112233"
324