verdef-invalid.test
10.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
## Test how llvm-readobj/llvm-readelf tools handle invalid SHT_GNU_verdef sections.
## Check that we report a warning when sh_link references a non-existent section.
# RUN: yaml2obj %s --docnum=1 -o %t1
# RUN: llvm-readobj -V %t1 2>&1 | FileCheck %s --check-prefix=INVALID-LINK-LLVM --implicit-check-not="warning:" -DFILE=%t1
# RUN: llvm-readelf -V %t1 2>&1 | FileCheck %s --check-prefix=INVALID-LINK-GNU --implicit-check-not="warning:" -DFILE=%t1
# INVALID-LINK-LLVM: warning: '[[FILE]]': invalid section linked to SHT_GNU_verdef section with index 1: invalid section index: 255
# INVALID-LINK-GNU: Version definition section '.gnu.version_d' contains 0 entries:
# INVALID-LINK-GNU: warning: '[[FILE]]': invalid section linked to SHT_GNU_verdef section with index 1: invalid section index: 255
# INVALID-LINK-GNU-NEXT: Addr: 0000000000000000 Offset: 0x000040 Link: 255 (<corrupt>)
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_DYN
Machine: EM_X86_64
Sections:
- Name: .gnu.version_d
Type: SHT_GNU_verdef
Link: 0xFF
Info: 0x0
Entries: []
## Check that we report a warning when the sh_link field of a SHT_GNU_verdef section references a non-string table section.
# RUN: yaml2obj %s --docnum=2 -o %t2
# RUN: llvm-readobj -V %t2 2>&1 | FileCheck %s --check-prefix=INVALID-STRING-TABLE -DFILE=%t2
# RUN: llvm-readelf -V %t2 2>&1 | FileCheck %s --check-prefix=INVALID-STRING-TABLE -DFILE=%t2
# INVALID-STRING-TABLE: warning: '[[FILE]]': invalid string table linked to SHT_GNU_verdef section with index 1: invalid sh_type for string table section [index 0]: expected SHT_STRTAB, but got SHT_NULL
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_DYN
Machine: EM_X86_64
Sections:
- Name: .gnu.version_d
Type: SHT_GNU_verdef
Link: 0x0
Info: 0x0
Entries: []
## Check that we report a warning when we can't read the content of the SHT_GNU_verdef section.
# RUN: yaml2obj %s --docnum=3 -o %t3
# RUN: llvm-readobj -V %t3 2>&1 | FileCheck %s --check-prefix=INVALID-DATA -DFILE=%t3
# RUN: llvm-readelf -V %t3 2>&1 | FileCheck %s --check-prefix=INVALID-DATA -DFILE=%t3
# INVALID-DATA: warning: '[[FILE]]': cannot read content of SHT_GNU_verdef section with index 1: section [index 1] has a sh_offset (0xffffffff) + sh_size (0x0) that is greater than the file size (0x228)
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_DYN
Machine: EM_X86_64
Sections:
- Name: .gnu.version_d
Type: SHT_GNU_verdef
Link: .dynstr
Info: 0x0
Entries: []
ShOffset: 0xFFFFFFFF
DynamicSymbols:
- Name: foo
## Check that we report a warning when a SHT_GNU_verdef section contains a version definition
## that goes past the end of the section.
# RUN: yaml2obj %s --docnum=4 -o %t4
# RUN: llvm-readobj -V %t4 2>&1 | FileCheck %s --check-prefix=DEF-PAST-END -DFILE=%t4
# RUN: llvm-readelf -V %t4 2>&1 | FileCheck %s --check-prefix=DEF-PAST-END -DFILE=%t4
# DEF-PAST-END: warning: '[[FILE]]': invalid SHT_GNU_verdef section with index 1: version definition 1 goes past the end of the section
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_DYN
Machine: EM_X86_64
Sections:
- Name: .gnu.version_d
Type: SHT_GNU_verdef
Link: .dynstr
Info: 0x1
Entries:
- Version: 1
Flags: 0
VersionNdx: 0
Hash: 0
Names:
- FOO
ShSize: 1
DynamicSymbols:
- Name: foo
## Check that we report a warning when a SHT_GNU_verdef section contains a version definition
## that refers to an auxiliary entry that goes past the end of the section.
# RUN: yaml2obj %s --docnum=5 -o %t5
# RUN: llvm-readobj -V %t5 2>&1 | FileCheck %s --check-prefix=AUX-PAST-END -DFILE=%t5
# RUN: llvm-readelf -V %t5 2>&1 | FileCheck %s --check-prefix=AUX-PAST-END -DFILE=%t5
# AUX-PAST-END: warning: '[[FILE]]': invalid SHT_GNU_verdef section with index 1: version definition 1 refers to an auxiliary entry that goes past the end of the section
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_DYN
Machine: EM_X86_64
Sections:
- Name: .gnu.version_d
Type: SHT_GNU_verdef
Link: .dynstr
Info: 0x1
Entries:
- Version: 1
Flags: 0
VersionNdx: 0
Hash: 0
Names:
- FOO
ShSize: 21
DynamicSymbols:
- Name: foo
## Check that we can dump a SHT_GNU_verdef section properly even if it contains version names strings
## that overrun the linked string table.
# RUN: yaml2obj %s --docnum=6 -o %t6
# RUN: llvm-readobj -V %t6 2>&1 | FileCheck %s --check-prefix=PAST-STRTAB-END-LLVM --implicit-check-not="warning:" -DFILE=%t6
# RUN: llvm-readelf -V %t6 2>&1 | FileCheck %s --check-prefix=PAST-STRTAB-END-GNU --implicit-check-not="warning:" -DFILE=%t6
# PAST-STRTAB-END-LLVM: VersionDefinitions [
# PAST-STRTAB-END-LLVM-NEXT: Definition {
# PAST-STRTAB-END-LLVM-NEXT: Version: 1
# PAST-STRTAB-END-LLVM-NEXT: Flags [ (0x0)
# PAST-STRTAB-END-LLVM-NEXT: ]
# PAST-STRTAB-END-LLVM-NEXT: Index: 0
# PAST-STRTAB-END-LLVM-NEXT: Hash: 0
# PAST-STRTAB-END-LLVM-NEXT: Name: <invalid vda_name: 5>
# PAST-STRTAB-END-LLVM-NEXT: Predecessors: []
# PAST-STRTAB-END-LLVM-NEXT: }
# PAST-STRTAB-END-LLVM-NEXT: ]
# PAST-STRTAB-END-GNU: Version definition section '.gnu.version_d' contains 1 entries:
# PAST-STRTAB-END-GNU-NEXT: Addr: 0000000000000000 Offset: 0x000040 Link: 2 (.strtab)
# PAST-STRTAB-END-GNU-NEXT: 0x0000: Rev: 1 Flags: none Index: 0 Cnt: 1 Name: <invalid vda_name: 5>
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_DYN
Machine: EM_X86_64
Sections:
- Name: .gnu.version_d
Type: SHT_GNU_verdef
Link: .strtab
Info: 0x1
Entries:
- Version: 1
Flags: 0
VersionNdx: 0
Hash: 0
Names:
- FOO
- Name: .strtab
Type: SHT_STRTAB
DynamicSymbols:
- Name: BAR
## Check we report a warning when a version definition is not correctly aligned in memory.
# RUN: yaml2obj %s --docnum=7 -o %t7
# RUN: llvm-readobj -V %t7 2>&1 | FileCheck %s --check-prefix=MISALIGNED-DEF -DFILE=%t7
# RUN: llvm-readelf -V %t7 2>&1 | FileCheck %s --check-prefix=MISALIGNED-DEF -DFILE=%t7
# MISALIGNED-DEF: warning: '[[FILE]]': invalid SHT_GNU_verdef section with index 1: found a misaligned version definition entry at offset 0x0
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_DYN
Machine: EM_X86_64
Sections:
- Type: Fill
Size: 0x1
- Name: .gnu.version_d
Type: SHT_GNU_verdef
Link: .dynstr
Info: 0x1
Entries:
- Version: 1
Flags: 0
VersionNdx: 0
Hash: 0
Names:
- FOO
DynamicSymbols:
- Name: foo
## Check we report a warning when an auxiliary entry is not correctly aligned in memory.
# RUN: yaml2obj %s --docnum=8 -o %t8
# RUN: llvm-readobj -V %t8 2>&1 | FileCheck %s --check-prefix=MISALIGNED-AUX -DFILE=%t8
# RUN: llvm-readelf -V %t8 2>&1 | FileCheck %s --check-prefix=MISALIGNED-AUX -DFILE=%t8
# MISALIGNED-AUX: warning: '[[FILE]]': invalid SHT_GNU_verdef section with index 1: found a misaligned auxiliary entry at offset 0x13
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_DYN
Machine: EM_X86_64
Sections:
- Name: .gnu.version_d
Type: SHT_GNU_verdef
Flags: [ SHF_ALLOC ]
Link: .dynstr
Info: 0x1
## The byte offset to the auxiliary entry is 0x13, i.e. it is not correctly aligned in memory.
Content: "0100000000000100000000001300000000000000"
DynamicSymbols:
- Name: foo
Binding: STB_GLOBAL
## Check how we handle a version definition entry with an unsupported version.
# RUN: yaml2obj %s --docnum=9 -o %t9
# RUN: llvm-readobj -V %t9 2>&1 | FileCheck %s --check-prefix=UNSUPPORTED-VERSION -DFILE=%t9
# RUN: llvm-readelf -V %t9 2>&1 | FileCheck %s --check-prefix=UNSUPPORTED-VERSION -DFILE=%t9
# UNSUPPORTED-VERSION: warning: '[[FILE]]': unable to dump SHT_GNU_verdef section with index 1: version 65278 is not yet supported
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_DYN
Machine: EM_X86_64
Sections:
- Name: .gnu.version_d
Type: SHT_GNU_verdef
Link: .dynstr
Info: 0x1
Entries:
- Version: 0xfefe
Flags: 0
VersionNdx: 0
Hash: 0
Names: []
DynamicSymbols:
- Name: foo
## Check we report a warning when trying to print version symbols, but SHT_GNU_verdef
## is invalid due to any reason.
# RUN: yaml2obj %s --docnum=10 -o %t10
# RUN: llvm-readobj -V %t10 2>&1 | FileCheck %s --check-prefix=INVALID-VERDEF-LLVM -DFILE=%t10
# RUN: llvm-readelf -V %t10 2>&1 | FileCheck %s --check-prefix=INVALID-VERDEF-GNU -DFILE=%t10
# INVALID-VERDEF-LLVM: VersionSymbols [
# INVALID-VERDEF-LLVM-NEXT: Symbol {
# INVALID-VERDEF-LLVM-NEXT: Version: 0
# INVALID-VERDEF-LLVM-NEXT: Name:
# INVALID-VERDEF-LLVM-NEXT: }
# INVALID-VERDEF-LLVM-NEXT: Symbol {
# INVALID-VERDEF-LLVM-NEXT: Version: 2
# INVALID-VERDEF-LLVM-NEXT: warning: '[[FILE]]': invalid SHT_GNU_verdef section with index 2: version definition 1 goes past the end of the section
# INVALID-VERDEF-LLVM-NEXT: Name: foo@<corrupt>
# INVALID-VERDEF-GNU: Version symbols section '.gnu.version' contains 2 entries:
# INVALID-VERDEF-GNU-NEXT: Addr: 0000000000000000 Offset: 0x000040 Link: 3 (.dynsym)
# INVALID-VERDEF-GNU-NEXT: warning: '[[FILE]]': unable to get a version for entry 1 of SHT_GNU_versym section with index 1: invalid SHT_GNU_verdef section with index 2: version definition 1 goes past the end of the section
# INVALID-VERDEF-GNU-NEXT: 000: 0 (*local*) 2 (<corrupt>)
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_DYN
Machine: EM_X86_64
Sections:
- Name: .gnu.version
Type: SHT_GNU_versym
Flags: [ SHF_ALLOC ]
Link: .dynsym
AddressAlign: 0x0000000000000002
EntSize: 0x0000000000000002
Entries: [ 0, 2 ]
- Name: .gnu.version_d
Type: SHT_GNU_verdef
Flags: [ SHF_ALLOC ]
Link: .dynstr
AddressAlign: 0x4
Info: 0x1
Entries: []
DynamicSymbols:
- Name: foo
Binding: STB_GLOBAL