dyn-symbols-size-from-hash-table.test
11.4 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
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
## This test shows how llvm-readobj uses the hash table section to derive the
## size of a dynamic symbol table. This allows dumping of the dynamic symbol
## table in the event of an object without section headers.
## Case 1a) Table size is derived from hash table, with DT_SYMTAB before DT_HASH.
# RUN: yaml2obj --docnum=1 %s -o %t1a-64 -DBITS=64 \
# RUN: -DTAG1=DT_SYMTAB -DTAG2=DT_HASH -DVAL1=0x400 -DVAL2=0x600
# RUN: llvm-strip --strip-sections %t1a-64
# RUN: llvm-readobj --dyn-symbols %t1a-64 2>&1 | \
# RUN: FileCheck %s --check-prefixes=LLVM1,STRIP --implicit-check-not=warning:
# RUN: llvm-readelf --dyn-symbols %t1a-64 2>&1 | \
# RUN: FileCheck %s --check-prefixes=GNU1,GNU1-STRIP --implicit-check-not=warning:
# RUN: yaml2obj --docnum=1 %s -o %t1a-32 -DBITS=32 \
# RUN: -DTAG1=DT_SYMTAB -DTAG2=DT_HASH -DVAL1=0x400 -DVAL2=0x600
# RUN: llvm-strip --strip-sections %t1a-32
# RUN: llvm-readobj --dyn-symbols %t1a-32 2>&1 | \
# RUN: FileCheck %s --check-prefixes=LLVM1,STRIP --implicit-check-not=warning:
# RUN: llvm-readelf --dyn-symbols %t1a-32 2>&1 | \
# RUN: FileCheck %s --check-prefixes=GNU1,GNU1-STRIP --implicit-check-not=warning:
## 1b) Table size is derived from hash table, with DT_HASH before DT_SYMTAB.
## We don't bother testing 32 and 64-bit here. The above cases show that reading
## the nchain value is correct for all formats, and other tests show the basic
## printing behaviour.
# RUN: yaml2obj --docnum=1 %s -o %t1b-64 -DBITS=64 \
# RUN: -DTAG1=DT_HASH -DTAG2=DT_SYMTAB -DVAL1=0x600 -DVAL2=0x400
# RUN: llvm-strip --strip-sections %t1b-64
# RUN: llvm-readobj --dyn-symbols %t1b-64 2>&1 | \
# RUN: FileCheck %s --check-prefixes=LLVM1,STRIP --implicit-check-not=warning:
# RUN: llvm-readelf --dyn-symbols %t1b-64 2>&1 | \
# RUN: FileCheck %s --check-prefixes=GNU1,GNU1-STRIP --implicit-check-not=warning:
# LLVM1: DynamicSymbols [
# LLVM1-NEXT: Symbol {
# LLVM1-NEXT: Name: (0)
# LLVM1-NEXT: Value: 0x0
# LLVM1-NEXT: Size: 0
# LLVM1-NEXT: Binding: Local (0x0)
# LLVM1-NEXT: Type: None (0x0)
# LLVM1-NEXT: Other: 0
# LLVM1-NEXT: Section: Undefined (0x0)
# LLVM1-NEXT: }
# LLVM1-NEXT: Symbol {
# LLVM1-NEXT: Name: foo (5)
# LLVM1-NEXT: Value: 0x100
# LLVM1-NEXT: Size: 0
# LLVM1-NEXT: Binding: Local (0x0)
# LLVM1-NEXT: Type: Function (0x2)
# LLVM1-NEXT: Other: 0
# STRIP-NEXT: Section: <?> (0x1)
# NOSTRIP-NEXT: Section: .text (0x1)
# LLVM1-NEXT: }
# LLVM1-NEXT: Symbol {
# LLVM1-NEXT: Name: bar (1)
# LLVM1-NEXT: Value: 0x200
# LLVM1-NEXT: Size: 0
# LLVM1-NEXT: Binding: Local (0x0)
# LLVM1-NEXT: Type: Object (0x1)
# LLVM1-NEXT: Other: 0
# STRIP-NEXT: Section: <?> (0x2)
# NOSTRIP-NEXT: Section: .data (0x2)
# LLVM1-NEXT: }
# LLVM1-NEXT: ]
# GNU1-STRIP: Symbol table for image contains 3 entries:
# GNU1-NOSTRIP: Symbol table '.dynsym' contains 3 entries:
# GNU1-NEXT: Num: Value Size Type Bind Vis Ndx Name
# GNU1-NEXT: 0: {{0*}}00000000 0 NOTYPE LOCAL DEFAULT UND
# GNU1-NEXT: 1: {{0*}}00000100 0 FUNC LOCAL DEFAULT 1 foo
# GNU1-NEXT: 2: {{0*}}00000200 0 OBJECT LOCAL DEFAULT 2 bar
# GNU1-EMPTY:
--- !ELF
FileHeader:
Class: ELFCLASS[[BITS]]
Data: ELFDATA2LSB
Type: ET_DYN
Machine: EM_X86_64
Sections:
- Name: .text
Type: SHT_PROGBITS
- Name: .data
Type: SHT_PROGBITS
- Name: .dynsym
Type: SHT_DYNSYM
Flags: [ SHF_ALLOC ]
Address: 0x400
AddressAlign: 0x400
- Name: .hash
Type: SHT_HASH
Flags: [ SHF_ALLOC ]
Address: 0x600
AddressAlign: 0x200
Bucket: [ 1 ]
Chain: [ 1, 2, 3 ]
- Name: .dynstr
Type: SHT_STRTAB
Flags: [ SHF_ALLOC ]
Address: 0x800
AddressAlign: 0x200
- Name: .dynamic
Type: SHT_DYNAMIC
Flags: [ SHF_ALLOC ]
Address: 0xA00
AddressAlign: 0x200
Entries:
- Tag: DT_STRTAB
Value: 0x800
- Tag: DT_STRSZ
Value: 9
- Tag: [[TAG1]]
Value: [[VAL1]]
- Tag: [[TAG2]]
Value: [[VAL2]]
- Tag: DT_NULL
Value: 0
DynamicSymbols:
- Name: foo
Type: STT_FUNC
Section: .text
Value: 0x100
- Name: bar
Type: STT_OBJECT
Section: .data
Value: 0x200
ProgramHeaders:
- Type: PT_LOAD
VAddr: 0
Sections:
- Section: .text
- Section: .data
- Type: PT_LOAD
VAddr: 0x400
Sections:
- Section: .dynsym
- Section: .hash
- Section: .dynstr
- Section: .dynamic
- Type: PT_DYNAMIC
VAddr: 0xA00
Sections:
- Section: .dynamic
## Case 2: Table size from DT_HASH does not match size from section header.
# RUN: yaml2obj --docnum=2 %s -o %t2-smaller -DCHAIN="[1, 2]"
# RUN: llvm-readobj --dyn-symbols %t2-smaller 2>&1 | \
# RUN: FileCheck %s --check-prefixes=LLVM2,WARN \
# RUN: --implicit-check-not=warning: -DNCHAIN=2
# RUN: llvm-readelf --dyn-symbols %t2-smaller 2>&1 | \
# RUN: FileCheck %s --check-prefixes=GNU2,WARN \
# RUN: --implicit-check-not=warning: -DNCHAIN=2
# RUN: yaml2obj --docnum=2 %s -o %t2-larger -DCHAIN="[1, 2, 3, 4]"
# RUN: llvm-readobj --dyn-symbols %t2-larger 2>&1 | \
# RUN: FileCheck %s --check-prefixes=LLVM2,LLVM2-MORE,LLVM2-ALL,WARN \
# RUN: --implicit-check-not=warning: -DNCHAIN=4
# RUN: llvm-readelf --dyn-symbols %t2-larger 2>&1 | \
# RUN: FileCheck %s --check-prefixes=GNU2,GNU2-MORE,GNU2-ALL,WARN \
# RUN: --implicit-check-not=warning: -DNCHAIN=4
# WARN: warning: '{{.*}}2-{{.*}}': hash table nchain ([[NCHAIN]]) differs from symbol count derived from SHT_DYNSYM section header (3)
## Show we report a warning when the sh_entsize of the SHT_DYNSYM section is zero and therefore we are unable
## to derive the number of dynamic symbols from SHT_DYNSYM section header.
# RUN: yaml2obj --docnum=2 %s -o %t2-zero-entsize -DCHAIN="[1, 2, 3, 4]" -DENTSIZE=0
# RUN: llvm-readobj --dyn-symbols %t2-zero-entsize 2>&1 | \
# RUN: FileCheck %s -DFILE=%t2-zero-entsize --check-prefixes=LLVM2,LLVM2-MORE,LLVM2-ALL,WARN-ENTSIZE \
# RUN: --implicit-check-not=warning:
# RUN: llvm-readelf --dyn-symbols %t2-zero-entsize 2>&1 | \
# RUN: FileCheck %s -DFILE=%t2-zero-entsize --check-prefixes=GNU2,GNU2-MORE,GNU2-ALL,WARN-ENTSIZE \
# RUN: --implicit-check-not=warning: -DNCHAIN=4
## WARN-ENTSIZE: warning: '[[FILE]]': SHT_DYNSYM section has sh_entsize == 0
## Show there's no warning if the sizes match
# RUN: yaml2obj --docnum=2 %s -o %t2-same -DCHAIN="[1, 2, 3]"
# RUN: llvm-readobj --dyn-symbols %t2-same 2>&1 | \
# RUN: FileCheck %s --check-prefixes=LLVM2,LLVM2-MORE --implicit-check-not=warning:
# RUN: llvm-readelf --dyn-symbols %t2-same 2>&1 | \
# RUN: FileCheck %s --check-prefixes=GNU2,GNU2-MORE \
# RUN: --implicit-check-not=warning: -DNCHAIN=3
# LLVM2: DynamicSymbols [
# LLVM2-NEXT: Symbol {
# LLVM2-NEXT: Name: (0)
# LLVM2-NEXT: Value: 0x0
# LLVM2-NEXT: Size: 0
# LLVM2-NEXT: Binding: Local (0x0)
# LLVM2-NEXT: Type: None (0x0)
# LLVM2-NEXT: Other: 0
# LLVM2-NEXT: Section: Undefined (0x0)
# LLVM2-NEXT: }
# LLVM2-NEXT: Symbol {
# LLVM2-NEXT: Name: foo (9)
# LLVM2-NEXT: Value: 0x100
# LLVM2-NEXT: Size: 0
# LLVM2-NEXT: Binding: Local (0x0)
# LLVM2-NEXT: Type: Function (0x2)
# LLVM2-NEXT: Other: 0
# LLVM2-NEXT: Section: .text (0x1)
# LLVM2-NEXT: }
# LLVM2-MORE-NEXT: Symbol {
# LLVM2-MORE-NEXT: Name: bar (5)
# LLVM2-MORE-NEXT: Value: 0x200
# LLVM2-MORE-NEXT: Size: 0
# LLVM2-MORE-NEXT: Binding: Local (0x0)
# LLVM2-MORE-NEXT: Type: Object (0x1)
# LLVM2-MORE-NEXT: Other: 0
# LLVM2-MORE-NEXT: Section: .data (0x2)
# LLVM2-MORE-NEXT: }
# LLVM2-ALL-NEXT: Symbol {
# LLVM2-ALL-NEXT: Name: baz (1)
# LLVM2-ALL-NEXT: Value: 0x300
# LLVM2-ALL-NEXT: Size: 0
# LLVM2-ALL-NEXT: Binding: Local (0x0)
# LLVM2-ALL-NEXT: Type: Object (0x1)
# LLVM2-ALL-NEXT: Other: 0
# LLVM2-ALL-NEXT: Section: .data (0x2)
# LLVM2-ALL-NEXT: }
# LLVM2-NEXT: ]
# GNU2: Symbol table '.dynsym' contains [[NCHAIN]] entries:
# GNU2-NEXT: Num: Value Size Type Bind Vis Ndx Name
# GNU2-NEXT: 0: {{0*}}00000000 0 NOTYPE LOCAL DEFAULT UND
# GNU2-NEXT: 1: {{0*}}00000100 0 FUNC LOCAL DEFAULT 1 foo
# GNU2-MORE-NEXT: 2: {{0*}}00000200 0 OBJECT LOCAL DEFAULT 2 bar
# GNU2-ALL-NEXT: 3: {{0*}}00000300 0 OBJECT LOCAL DEFAULT 2 baz
# GNU2-EMPTY:
## In this YAML, we define 4 dynamic symbols (including the null symbol), but
## constrain the .dynsym section header to say there are only 3. This means that
## when a size of 4 is derived from the hash table, we still have a valid symbol
## to dump.
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_DYN
Machine: EM_X86_64
Sections:
- Name: .text
Type: SHT_PROGBITS
- Name: .data
Type: SHT_PROGBITS
- Name: .dynsym
Type: SHT_DYNSYM
Flags: [ SHF_ALLOC ]
ShSize: 0x48
Address: 0x400
AddressAlign: 0x400
## 0x18 is the standard entsize value.
EntSize: [[ENTSIZE=0x18]]
- Name: .hash
Type: SHT_HASH
Flags: [ SHF_ALLOC ]
Address: 0x600
AddressAlign: 0x200
Bucket: [ 1 ]
Chain: [[CHAIN]]
- Name: .dynstr
Type: SHT_STRTAB
Flags: [ SHF_ALLOC ]
Address: 0x800
AddressAlign: 0x200
- Name: .dynamic
Type: SHT_DYNAMIC
Flags: [ SHF_ALLOC ]
Address: 0xA00
AddressAlign: 0x200
Entries:
- Tag: DT_SYMTAB
Value: 0x400
- Tag: DT_HASH
Value: 0x600
- Tag: DT_STRTAB
Value: 0x800
- Tag: DT_STRSZ
Value: 13
- Tag: DT_NULL
Value: 0
DynamicSymbols:
- Name: foo
Type: STT_FUNC
Section: .text
Value: 0x100
- Name: bar
Type: STT_OBJECT
Section: .data
Value: 0x200
- Name: baz
Type: STT_OBJECT
Section: .data
Value: 0x300
ProgramHeaders:
- Type: PT_LOAD
VAddr: 0
Sections:
- Section: .text
- Section: .data
- Type: PT_LOAD
VAddr: 0x400
Sections:
- Section: .dynsym
- Section: .hash
- Section: .dynstr
- Section: .dynamic
- Type: PT_DYNAMIC
VAddr: 0xA00
Sections:
- Section: .dynamic
## Case 3: DT_HASH is missing.
## Show that no warning occurs if there are section headers.
# RUN: yaml2obj --docnum=1 %s -o %t3 -DTAG1=DT_SYMTAB -DVAL1=0x400 -DTAG2=DT_NULL -DVAL2=0 -DBITS=64
# RUN: llvm-readobj --dyn-symbols %t3 2>&1 | \
# RUN: FileCheck %s --check-prefixes=LLVM1,NOSTRIP --implicit-check-not=warning:
# RUN: llvm-readelf --dyn-symbols %t3 2>&1 | \
# RUN: FileCheck %s --check-prefixes=GNU1,GNU1-NOSTRIP --implicit-check-not=warning:
## Show that size is treated as zero, if no section headers are present.
# RUN: llvm-strip --strip-sections %t3
# RUN: llvm-readobj --dyn-symbols %t3 2>&1 | \
# RUN: FileCheck %s --check-prefix=LLVM3 --implicit-check-not=warning:
# RUN: llvm-readelf --dyn-symbols %t3 2>&1 | \
# RUN: FileCheck %s --implicit-check-not={{.}} --allow-empty
# LLVM3: DynamicSymbols [
# LLVM3: ]