1## Check how yaml2obj produces SHT_LLVM_ADDRSIG sections.
2
3## Check we can describe SHT_LLVM_ADDRSIG using the "Symbols" tag. We can define
4## symbols either using names or indexes.
5
6# RUN: yaml2obj --docnum=1 %s -o %t1
7# RUN: llvm-readobj --sections --section-data %t1 | FileCheck %s --check-prefix=SYMBOLS
8
9# SYMBOLS:      Section {
10# SYMBOLS:        Index: 1
11# SYMBOLS-NEXT:   Name: .llvm_addrsig
12# SYMBOLS-NEXT:   Type: SHT_LLVM_ADDRSIG
13# SYMBOLS-NEXT:   Flags [
14# SYMBOLS-NEXT:   ]
15# SYMBOLS-NEXT:   Address: 0x0
16# SYMBOLS-NEXT:   Offset: 0x40
17# SYMBOLS-NEXT:   Size: 4
18# SYMBOLS-NEXT:   Link: 2
19# SYMBOLS-NEXT:   Info: 0
20# SYMBOLS-NEXT:   AddressAlignment: 0
21# SYMBOLS-NEXT:   EntrySize: 0
22# SYMBOLS-NEXT:   SectionData (
23# SYMBOLS-NEXT:     0000: 01020102
24# SYMBOLS-NEXT:   )
25# SYMBOLS-NEXT: }
26
27--- !ELF
28FileHeader:
29  Class: ELFCLASS64
30  Data:  ELFDATA2LSB
31  Type:  ET_DYN
32Sections:
33  - Name: .llvm_addrsig
34    Type: SHT_LLVM_ADDRSIG
35    Symbols: [ foo, bar, 1, 2 ]
36Symbols:
37  - Name:    foo
38    Type:    STT_FUNC
39    Binding: STB_GLOBAL
40  - Name:    bar
41    Type:    STT_FUNC
42    Binding: STB_GLOBAL
43
44## Check we report an error if an unknown symbol is referenced in the
45## SHT_LLVM_ADDRSIG section description.
46
47# RUN: not yaml2obj --docnum=2 %s 2>&1 | FileCheck %s --check-prefix=SYMBOL-UNKNOWN
48
49# SYMBOL-UNKNOWN: error: unknown symbol referenced: 'foo' by YAML section '.llvm_addrsig'
50# SYMBOL-UNKNOWN: error: unknown symbol referenced: 'bar' by YAML section '.llvm_addrsig'
51
52--- !ELF
53FileHeader:
54  Class: ELFCLASS64
55  Data:  ELFDATA2LSB
56  Type:  ET_DYN
57Sections:
58  - Name: .llvm_addrsig
59    Type: SHT_LLVM_ADDRSIG
60    Symbols: [ foo, bar ]
61
62## Check we can specify any arbitrary symbol indices.
63
64# RUN: yaml2obj --docnum=3 %s -o %t3
65# RUN: llvm-readobj --sections --section-data %t3 | FileCheck %s --check-prefix=SYMBOL-INDEX
66
67# SYMBOL-INDEX:      Type: SHT_LLVM_ADDRSIG
68# SYMBOL-INDEX:      SectionData (
69# SYMBOL-INDEX-NEXT:   0000: 00FF01C4 E6888901 FFFFFFFF 0F
70# SYMBOL-INDEX-NEXT: )
71
72--- !ELF
73FileHeader:
74  Class: ELFCLASS64
75  Data:  ELFDATA2LSB
76  Type:  ET_DYN
77Sections:
78  - Name: .llvm_addrsig
79    Type: SHT_LLVM_ADDRSIG
80## 0xFFFFFFFF is a maximum allowed index value.
81    Symbols: [ 0, 255, 0x11223344, 0xFFFFFFFF ]
82
83## Check that the maximum symbol index size is 32 bits.
84
85# RUN: not yaml2obj --docnum=4 %s 2>&1 | FileCheck %s --check-prefix=SYMBOL-INDEX-OVERFLOW
86
87# SYMBOL-INDEX-OVERFLOW: error: unknown symbol referenced: '0x1122334455' by YAML section '.llvm_addrsig'
88
89--- !ELF
90FileHeader:
91  Class: ELFCLASS64
92  Data:  ELFDATA2LSB
93  Type:  ET_DYN
94Sections:
95  - Name: .llvm_addrsig
96    Type: SHT_LLVM_ADDRSIG
97    Symbols: [ 0x1122334455 ]
98
99## Check we can use the "Content" tag to specify any data for SHT_LLVM_ADDRSIG sections.
100
101# RUN: yaml2obj --docnum=5 %s -o %t5
102# RUN: llvm-readobj --sections --section-data %t5 | FileCheck %s --check-prefix=CONTENT
103
104# CONTENT:      Type: SHT_LLVM_ADDRSIG
105# CONTENT:      Size:
106# CONTENT-SAME: 5
107# CONTENT:      SectionData (
108# CONTENT-NEXT:   0000: 11223344 55
109# CONTENT-NEXT: )
110
111--- !ELF
112FileHeader:
113  Class: ELFCLASS64
114  Data:  ELFDATA2LSB
115  Type:  ET_DYN
116Sections:
117  - Name: .llvm_addrsig
118    Type: SHT_LLVM_ADDRSIG
119    Content: "1122334455"
120
121## Check we emit an empty section if neither "Content", "Size" nor "Symbols" were set.
122
123# RUN: yaml2obj --docnum=6 %s -o %t6
124# RUN: llvm-readelf --sections %t6 | FileCheck %s --check-prefix=NO-TAGS
125
126# NO-TAGS: [Nr] Name          Type         Address          Off    Size
127# NO-TAGS: [ 1] .llvm_addrsig LLVM_ADDRSIG 0000000000000000 000040 000000
128
129--- !ELF
130FileHeader:
131  Class: ELFCLASS64
132  Data:  ELFDATA2LSB
133  Type:  ET_DYN
134Sections:
135  - Name: .llvm_addrsig
136    Type: SHT_LLVM_ADDRSIG
137
138## "Content" and "Symbols" cannot be used together to describe the SHT_LLVM_ADDRSIG section.
139
140# RUN: not yaml2obj --docnum=7 %s 2>&1 | FileCheck %s --check-prefix=CONTENT-SYMBOLS
141
142# CONTENT-SYMBOLS: "Symbols" cannot be used with "Content" or "Size"
143
144--- !ELF
145FileHeader:
146  Class: ELFCLASS64
147  Data:  ELFDATA2LSB
148  Type:  ET_DYN
149Sections:
150  - Name: .llvm_addrsig
151    Type: SHT_LLVM_ADDRSIG
152    Content: ""
153    Symbols:
154
155## Check we can set an arbitrary sh_link value for SHT_LLVM_ADDRSIG sections.
156
157# RUN: yaml2obj --docnum=8 %s -o %t8
158# RUN: llvm-readobj --sections %t8 | FileCheck %s --check-prefix=LINK
159
160# LINK:      Name: .llvm_addrsig
161# LINK:      Link:
162# LINK-SAME:       123{{$}}
163
164--- !ELF
165FileHeader:
166  Class: ELFCLASS64
167  Data:  ELFDATA2LSB
168  Type:  ET_DYN
169Sections:
170  - Name: .llvm_addrsig
171    Type: SHT_LLVM_ADDRSIG
172    Link: 123
173    Content: ""
174
175## Check we can use only "Size" to create a SHT_LLVM_ADDRSIG section.
176
177# RUN: yaml2obj --docnum=9 %s -o %t9
178# RUN: llvm-readobj --sections --section-data %t9 | FileCheck %s --check-prefix=SIZE
179
180# SIZE:      Name: .llvm_addrsig
181# SIZE:      Size:
182# SIZE-SAME: 17
183# SIZE:      SectionData (
184# SIZE-NEXT:  0000: 00000000 00000000 00000000 00000000  |
185# SIZE-NEXT:  0010: 00                                   |
186# SIZE-NEXT: )
187
188--- !ELF
189FileHeader:
190  Class: ELFCLASS64
191  Data:  ELFDATA2LSB
192  Type:  ET_EXEC
193Sections:
194  - Name: .llvm_addrsig
195    Type: SHT_LLVM_ADDRSIG
196    Size: 0x11
197
198## Check we can use "Size" and "Content" together to create a SHT_LLVM_ADDRSIG section.
199
200# RUN: yaml2obj --docnum=10 %s -o %t10
201# RUN: llvm-readobj --sections --section-data %t10 | FileCheck %s --check-prefix=SIZE-CONTENT
202
203# SIZE-CONTENT:      Name: .llvm_addrsig_sizegr
204# SIZE-CONTENT:      Size:
205# SIZE-CONTENT-SAME: 5
206# SIZE-CONTENT:      SectionData (
207# SIZE-CONTENT-NEXT:  0000: 11223300 00 |
208# SIZE-CONTENT-NEXT: )
209
210# SIZE-CONTENT:      Name: .llvm_addrsig_sizeeq
211# SIZE-CONTENT:      Size:
212# SIZE-CONTENT-SAME: 3
213# SIZE-CONTENT:      SectionData (
214# SIZE-CONTENT-NEXT:  0000: 112233 |
215# SIZE-CONTENT-NEXT: )
216
217--- !ELF
218FileHeader:
219  Class: ELFCLASS64
220  Data:  ELFDATA2LSB
221  Type:  ET_EXEC
222Sections:
223  - Name: .llvm_addrsig_sizegr
224    Type: SHT_LLVM_ADDRSIG
225    Size: 0x5
226    Content: "112233"
227  - Name: .llvm_addrsig_sizeeq
228    Type: SHT_LLVM_ADDRSIG
229    Size: 0x3
230    Content: "112233"
231
232## Check that when "Size" and "Content" are used together, the size
233## must be greater than or equal to the content size.
234
235# RUN: not yaml2obj --docnum=11 %s 2>&1 | FileCheck %s --check-prefix=SIZE-CONTENT-ERR
236
237# SIZE-CONTENT-ERR: error: Section size must be greater than or equal to the content size
238
239--- !ELF
240FileHeader:
241  Class: ELFCLASS64
242  Data:  ELFDATA2LSB
243  Type:  ET_EXEC
244Sections:
245  - Name: .llvm_addrsig
246    Type: SHT_LLVM_ADDRSIG
247    Size: 0x1
248    Content: "1122"
249
250## Check we can't use "Size" and "Symbols" tags together.
251
252# RUN: not yaml2obj --docnum=12 %s 2>&1 | FileCheck %s --check-prefix=CONTENT-SYMBOLS
253
254--- !ELF
255FileHeader:
256  Class: ELFCLASS64
257  Data:  ELFDATA2LSB
258  Type:  ET_EXEC
259Sections:
260  - Name: .llvm_addrsig
261    Type: SHT_LLVM_ADDRSIG
262    Size: 0x1
263    Symbols: [ ]
264