1 ## In this test we test that dynamic symbols are dumped as expected.
3 ## Case 1: Dynamic symbol table found via the DT_SYMTAB dynamic tag.
4 # RUN: yaml2obj --docnum=1 %s -o %t1.so
5 # RUN: llvm-readobj --dyn-symbols %t1.so 2>&1 \
6 # RUN: | FileCheck %s --implicit-check-not="warning:" --check-prefix=DYNSYMS-LLVM
7 # RUN: llvm-readelf --dyn-symbols %t1.so 2>&1 \
8 # RUN: | FileCheck %s --implicit-check-not="warning:" --check-prefix=DYNSYMS-GNU
10 # DYNSYMS-LLVM: DynamicSymbols [
11 # DYNSYMS-LLVM-NEXT: Symbol {
12 # DYNSYMS-LLVM-NEXT: Name: (0)
13 # DYNSYMS-LLVM-NEXT: Value: 0x0
14 # DYNSYMS-LLVM-NEXT: Size: 0
15 # DYNSYMS-LLVM-NEXT: Binding: Local (0x0)
16 # DYNSYMS-LLVM-NEXT: Type: None (0x0)
17 # DYNSYMS-LLVM-NEXT: Other: 0
18 # DYNSYMS-LLVM-NEXT: Section: Undefined (0x0)
19 # DYNSYMS-LLVM-NEXT: }
20 # DYNSYMS-LLVM-NEXT: Symbol {
21 # DYNSYMS-LLVM-NEXT: Name: foo (5)
22 # DYNSYMS-LLVM-NEXT: Value: 0x0
23 # DYNSYMS-LLVM-NEXT: Size: 0
24 # DYNSYMS-LLVM-NEXT: Binding: Local (0x0)
25 # DYNSYMS-LLVM-NEXT: Type: None (0x0)
26 # DYNSYMS-LLVM-NEXT: Other: 0
27 # DYNSYMS-LLVM-NEXT: Section: Undefined (0x0)
28 # DYNSYMS-LLVM-NEXT: }
29 # DYNSYMS-LLVM-NEXT: Symbol {
30 # DYNSYMS-LLVM-NEXT: Name: bar (1)
31 # DYNSYMS-LLVM-NEXT: Value: 0x0
32 # DYNSYMS-LLVM-NEXT: Size: 0
33 # DYNSYMS-LLVM-NEXT: Binding: Local (0x0)
34 # DYNSYMS-LLVM-NEXT: Type: None (0x0)
35 # DYNSYMS-LLVM-NEXT: Other: 0
36 # DYNSYMS-LLVM-NEXT: Section: Undefined (0x0)
37 # DYNSYMS-LLVM-NEXT: }
38 # DYNSYMS-LLVM-NEXT: ]
40 # DYNSYMS-GNU: Symbol table '.dynsym' contains 3 entries:
41 # DYNSYMS-GNU-NEXT: Num: Value Size Type Bind Vis Ndx Name
42 # DYNSYMS-GNU-NEXT: 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND
43 # DYNSYMS-GNU-NEXT: 1: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND foo
44 # DYNSYMS-GNU-NEXT: 2: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND bar
71 ## Case 2: Check the output for aliases.
72 ## a) Check the two-letter alias --dt is equivalent to the --dyn-symbols
74 # RUN: llvm-readobj --dt %t1.so > %t.readobj-dt-alias
75 # RUN: llvm-readobj --dyn-symbols %t1.so > %t.readobj-dt-no-alias
76 # RUN: cmp %t.readobj-dt-alias %t.readobj-dt-no-alias
77 ## b) Check --dyn-syms equals --dyn-symbols, --dt for llvm-readobj.
78 # RUN: llvm-readobj --dyn-syms %t1.so > %t.readobj-dyn-syms
79 # RUN: cmp %t.readobj-dt-alias %t.readobj-dyn-syms
80 ## c) Check --dyn-syms equals --dyn-symbols for llvm-readelf.
81 # RUN: llvm-readelf --dyn-syms %t1.so > %t.readelf-dyn-syms
82 # RUN: llvm-readelf --dyn-symbols %t1.so > %t.readelf-dyn-symbols
83 # RUN: cmp %t.readelf-dyn-symbols %t.readelf-dyn-syms
85 ## Case 3.1: Check that we are able to dump the dynamic symbol table even when we have no program headers.
86 ## In this case we find the table by it's type (SHT_DYNSYM) and ignore the DT_SYMTAB value.
87 # RUN: yaml2obj --docnum=2 %s -o %t2.so
88 # RUN: llvm-readobj %t2.so --dyn-symbols 2>&1 | \
89 # RUN: FileCheck %s -DFILE=%t2.so --implicit-check-not=warning: --check-prefix=NOPHDRS-LLVM
90 # RUN: llvm-readelf %t2.so --dyn-symbols 2>&1 | \
91 # RUN: FileCheck %s -DFILE=%t2.so --implicit-check-not=warning: -DNAME=.dynsym --check-prefix=NOPHDRS-GNU
93 # NOPHDRS-LLVM: warning: '[[FILE]]': unable to parse DT_SYMTAB: virtual address is not in any segment: 0xffff1234
94 # NOPHDRS-LLVM: DynamicSymbols [
95 # NOPHDRS-LLVM-NEXT: Symbol {
96 # NOPHDRS-LLVM-NEXT: Name: (0)
97 # NOPHDRS-LLVM-NEXT: Value: 0x0
98 # NOPHDRS-LLVM-NEXT: Size: 0
99 # NOPHDRS-LLVM-NEXT: Binding: Local (0x0)
100 # NOPHDRS-LLVM-NEXT: Type: None (0x0)
101 # NOPHDRS-LLVM-NEXT: Other: 0
102 # NOPHDRS-LLVM-NEXT: Section: Undefined (0x0)
103 # NOPHDRS-LLVM-NEXT: }
104 # NOPHDRS-LLVM-NEXT: Symbol {
105 # NOPHDRS-LLVM-NEXT: Name: foo (1)
106 # NOPHDRS-LLVM-NEXT: Value: 0x0
107 # NOPHDRS-LLVM-NEXT: Size: 0
108 # NOPHDRS-LLVM-NEXT: Binding: Local (0x0)
109 # NOPHDRS-LLVM-NEXT: Type: None (0x0)
110 # NOPHDRS-LLVM-NEXT: Other: 0
111 # NOPHDRS-LLVM-NEXT: Section: Undefined (0x0)
112 # NOPHDRS-LLVM-NEXT: }
113 # NOPHDRS-LLVM-NEXT: ]
115 # NOPHDRS-GNU: warning: '[[FILE]]': unable to parse DT_SYMTAB: virtual address is not in any segment: 0xffff1234
116 # NOPHDRS-NAMEWARN: warning: '[[FILE]]': unable to get the name of SHT_DYNSYM section with index 2: a section [index 2] has an invalid sh_name (0xffffffff) offset which goes past the end of the section name string table
117 # NOPHDRS-GNU: Symbol table '[[NAME]]' contains 2 entries:
118 # NOPHDRS-GNU-NEXT: Num: Value Size Type Bind Vis Ndx Name
119 # NOPHDRS-GNU-NEXT: 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND
120 # NOPHDRS-GNU-NEXT: 1: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND foo
137 ShName: [[DYNSYMNAME=<none>]]
141 ## Case 3.2: the same as 3.1, but the sh_name field of the SHT_DYNSYM section is invalid.
142 ## Check we are still able to dump symbols.
143 # RUN: yaml2obj --docnum=2 -DDYNSYMNAME=0xffffffff %s -o %t2.broken.name
144 # RUN: llvm-readobj %t2.broken.name --dyn-symbols 2>&1 | \
145 # RUN: FileCheck %s -DFILE=%t2.broken.name --check-prefix=NOPHDRS-LLVM --implicit-check-not=warning:
146 # RUN: llvm-readelf %t2.broken.name --dyn-symbols 2>&1 | \
147 # RUN: FileCheck %s -DFILE=%t2.broken.name -DNAME="<?>" \
148 # RUN: --check-prefixes=NOPHDRS-GNU,NOPHDRS-NAMEWARN --implicit-check-not=warning:
150 ## Case 4: Check we report a warning when there is no SHT_DYNSYM section and we can't map the DT_SYMTAB value
151 ## to an address because of the absence of a corresponding PT_LOAD program header.
152 # RUN: yaml2obj --docnum=3 %s -o %t3.so
153 # RUN: llvm-readobj %t3.so --dyn-symbols 2>&1 | FileCheck %s -DFILE=%t3.so --check-prefixes=NOSHT-DYNSYM,NOSHT-DYNSYM-LLVM
154 # RUN: llvm-readelf %t3.so --dyn-symbols 2>&1 | FileCheck %s -DFILE=%t3.so --check-prefix=NOSHT-DYNSYM
156 # NOSHT-DYNSYM: warning: '[[FILE]]': unable to parse DT_SYMTAB: virtual address is not in any segment: 0x0
157 # NOSHT-DYNSYM-LLVM: DynamicSymbols [
158 # NOSHT-DYNSYM-LLVM-NEXT: ]
178 ## Case 5: Check that when we can't map the value of the DT_SYMTAB tag to an address, we report a warning and
179 ## use the information in the section header table to locate the dynamic symbol table.
180 # RUN: yaml2obj --docnum=4 %s -o %t4.so
181 # RUN: llvm-readobj %t4.so --dyn-symbols 2>&1 | FileCheck -DFILE=%t4.so %s --check-prefixes=BROKEN-DTSYMTAB,BROKEN-DTSYMTAB-LLVM
182 # RUN: llvm-readelf %t4.so --dyn-symbols 2>&1 | FileCheck -DFILE=%t4.so %s --check-prefixes=BROKEN-DTSYMTAB,BROKEN-DTSYMTAB-GNU
184 # BROKEN-DTSYMTAB: warning: '[[FILE]]': unable to parse DT_SYMTAB: virtual address is not in any segment: 0xffff1234
185 # BROKEN-DTSYMTAB-LLVM: Name: foo
186 # BROKEN-DTSYMTAB-GNU: 1: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND foo
209 ## Case 6: Check that if we can get the location of the dynamic symbol table using both the DT_SYMTAB value
210 ## and the section headers table then we prefer the former and report a warning.
211 # RUN: yaml2obj --docnum=5 %s -o %t5.so
212 # RUN: llvm-readobj %t5.so --dyn-symbols 2>&1 | FileCheck -DFILE=%t5.so %s --check-prefixes=PREFER-DTSYMTAB,PREFER-DTSYMTAB-LLVM
213 # RUN: llvm-readelf %t5.so --dyn-symbols 2>&1 | FileCheck -DFILE=%t5.so %s --check-prefixes=PREFER-DTSYMTAB,PREFER-DTSYMTAB-GNU
215 # PREFER-DTSYMTAB: warning: '[[FILE]]': SHT_DYNSYM section header and DT_SYMTAB disagree about the location of the dynamic symbol table
216 # PREFER-DTSYMTAB-LLVM: Name: o
217 # PREFER-DTSYMTAB-GNU: 1: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND o
236 ## The Content describes 2 symbols: zero symbol and symbol with st_name == 3.
237 Content: "000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000"
246 ## Case 7: Check how we dump versioned symbols. Use both -V and --dyn-symbols
247 ## to check that printed version is consistent.
248 ## A default version is one that is contained in the version table (SHT_GNU_versym)
249 ## and only available for defined symbols. We use the "@@" prefix to print it.
251 ## Check how we dump undefined symbols.
253 # RUN: yaml2obj %s --docnum=6 -o %t6
254 # RUN: llvm-readobj -V --dyn-symbols %t6 | FileCheck %s --check-prefix=VERSIONED-UND-LLVM
255 # RUN: llvm-readelf -V --dyn-symbols %t6 | FileCheck %s --check-prefix=VERSIONED-UND-GNU
257 # VERSIONED-UND-LLVM: DynamicSymbols [
258 # VERSIONED-UND-LLVM-NEXT: Symbol {
259 # VERSIONED-UND-LLVM-NEXT: Name: (0)
260 # VERSIONED-UND-LLVM-NEXT: Value: 0x0
261 # VERSIONED-UND-LLVM-NEXT: Size: 0
262 # VERSIONED-UND-LLVM-NEXT: Binding: Local (0x0)
263 # VERSIONED-UND-LLVM-NEXT: Type: None (0x0)
264 # VERSIONED-UND-LLVM-NEXT: Other: 0
265 # VERSIONED-UND-LLVM-NEXT: Section: Undefined (0x0)
266 # VERSIONED-UND-LLVM-NEXT: }
267 # VERSIONED-UND-LLVM-NEXT: Symbol {
268 # VERSIONED-UND-LLVM-NEXT: Name: localversym (28)
269 # VERSIONED-UND-LLVM-NEXT: Value: 0x0
270 # VERSIONED-UND-LLVM-NEXT: Size: 0
271 # VERSIONED-UND-LLVM-NEXT: Binding: Local (0x0)
272 # VERSIONED-UND-LLVM-NEXT: Type: None (0x0)
273 # VERSIONED-UND-LLVM-NEXT: Other: 0
274 # VERSIONED-UND-LLVM-NEXT: Section: Undefined (0x0)
275 # VERSIONED-UND-LLVM-NEXT: }
276 # VERSIONED-UND-LLVM-NEXT: Symbol {
277 # VERSIONED-UND-LLVM-NEXT: Name: globalversym (40)
278 # VERSIONED-UND-LLVM-NEXT: Value: 0x0
279 # VERSIONED-UND-LLVM-NEXT: Size: 0
280 # VERSIONED-UND-LLVM-NEXT: Binding: Local (0x0)
281 # VERSIONED-UND-LLVM-NEXT: Type: None (0x0)
282 # VERSIONED-UND-LLVM-NEXT: Other: 0
283 # VERSIONED-UND-LLVM-NEXT: Section: Undefined (0x0)
284 # VERSIONED-UND-LLVM-NEXT: }
285 # VERSIONED-UND-LLVM-NEXT: Symbol {
286 # VERSIONED-UND-LLVM-NEXT: Name: aaa@v2 (65)
287 # VERSIONED-UND-LLVM-NEXT: Value: 0x0
288 # VERSIONED-UND-LLVM-NEXT: Size: 0
289 # VERSIONED-UND-LLVM-NEXT: Binding: Local (0x0)
290 # VERSIONED-UND-LLVM-NEXT: Type: None (0x0)
291 # VERSIONED-UND-LLVM-NEXT: Other: 0
292 # VERSIONED-UND-LLVM-NEXT: Section: Undefined (0x0)
293 # VERSIONED-UND-LLVM-NEXT: }
294 # VERSIONED-UND-LLVM-NEXT: Symbol {
295 # VERSIONED-UND-LLVM-NEXT: Name: bbb@v3hidden (61)
296 # VERSIONED-UND-LLVM-NEXT: Value: 0x0
297 # VERSIONED-UND-LLVM-NEXT: Size: 0
298 # VERSIONED-UND-LLVM-NEXT: Binding: Local (0x0)
299 # VERSIONED-UND-LLVM-NEXT: Type: None (0x0)
300 # VERSIONED-UND-LLVM-NEXT: Other: 0
301 # VERSIONED-UND-LLVM-NEXT: Section: Undefined (0x0)
302 # VERSIONED-UND-LLVM-NEXT: }
303 # VERSIONED-UND-LLVM-NEXT: Symbol {
304 # VERSIONED-UND-LLVM-NEXT: Name: ccc@v4 (57)
305 # VERSIONED-UND-LLVM-NEXT: Value: 0x0
306 # VERSIONED-UND-LLVM-NEXT: Size: 0
307 # VERSIONED-UND-LLVM-NEXT: Binding: Local (0x0)
308 # VERSIONED-UND-LLVM-NEXT: Type: None (0x0)
309 # VERSIONED-UND-LLVM-NEXT: Other: 0
310 # VERSIONED-UND-LLVM-NEXT: Section: Undefined (0x0)
311 # VERSIONED-UND-LLVM-NEXT: }
312 # VERSIONED-UND-LLVM-NEXT: Symbol {
313 # VERSIONED-UND-LLVM-NEXT: Name: ddd@v5hidden (53)
314 # VERSIONED-UND-LLVM-NEXT: Value: 0x0
315 # VERSIONED-UND-LLVM-NEXT: Size: 0
316 # VERSIONED-UND-LLVM-NEXT: Binding: Local (0x0)
317 # VERSIONED-UND-LLVM-NEXT: Type: None (0x0)
318 # VERSIONED-UND-LLVM-NEXT: Other: 0
319 # VERSIONED-UND-LLVM-NEXT: Section: Undefined (0x0)
320 # VERSIONED-UND-LLVM-NEXT: }
321 # VERSIONED-UND-LLVM-NEXT: ]
322 # VERSIONED-UND-LLVM: VersionSymbols [
323 # VERSIONED-UND-LLVM: Name: localversym
324 # VERSIONED-UND-LLVM: Name: globalversym
325 # VERSIONED-UND-LLVM: Name: aaa@v2
326 # VERSIONED-UND-LLVM: Name: bbb@v3hidden
327 # VERSIONED-UND-LLVM: Name: ccc@v4
328 # VERSIONED-UND-LLVM: Name: ddd@v5hidden
330 # VERSIONED-UND-GNU: Num: Value Size Type Bind Vis Ndx Name
331 # VERSIONED-UND-GNU: 1: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND localversym
332 # VERSIONED-UND-GNU-NEXT: 2: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND globalversym
333 # VERSIONED-UND-GNU-NEXT: 3: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND aaa@v2
334 # VERSIONED-UND-GNU-NEXT: 4: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND bbb@v3hidden
335 # VERSIONED-UND-GNU-NEXT: 5: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND ccc@v4
336 # VERSIONED-UND-GNU-NEXT: 6: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND ddd@v5hidden
337 # VERSIONED-UND-GNU: 000: 0 (*local*) 0 (*local*) 1 (*global*) 2 (v2)
338 # VERSIONED-UND-GNU: 004: 3h(v3hidden) 4 (v4) 5h(v5hidden)
352 ## 0x8000 is a special VERSYM_HIDDEN bit.
353 ## Here we have: VER_NDX_LOCAL (0), VER_NDX_GLOBAL (1), two versions
354 ## from the SHT_GNU_verdef section (2, 0x8003) and two versions
355 ## from the SHT_GNU_verneed section (4, 0x8005).
356 Entries: [ 0, 0, 1, 2, 0x8003, 4, 0x8005 ]
357 - Name: .gnu.version_d
368 - Name: .gnu.version_r
369 Type: SHT_GNU_verneed
388 Index: [[INDEX=<none>]]
390 Index: [[INDEX=<none>]]
392 Index: [[INDEX=<none>]]
394 Type: [[TYPE=STT_NOTYPE]]
395 Index: [[INDEX_BBB=<none>]]
397 Type: [[TYPE=STT_NOTYPE]]
398 Index: [[INDEX=<none>]]
400 Index: [[INDEX=<none>]]
402 ## In this case all dynamic symbols are defined. Check that we print the
403 ## "@@" prefix for default versions as expected.
405 # RUN: yaml2obj %s --docnum=6 -DINDEX=1 -DINDEX_BBB=1 -o %t6.def
406 # RUN: llvm-readobj -V --dyn-symbols %t6.def | FileCheck %s --check-prefix=VERSIONED-DEF-LLVM
407 # RUN: llvm-readelf -V --dyn-symbols %t6.def | FileCheck %s --check-prefix=VERSIONED-DEF-GNU
409 # VERSIONED-DEF-LLVM: DynamicSymbols [
410 # VERSIONED-DEF-LLVM: Symbol {
411 # VERSIONED-DEF-LLVM: Name: localversym (28)
412 # VERSIONED-DEF-LLVM: Section: .gnu.version (0x1)
413 # VERSIONED-DEF-LLVM-NEXT: }
414 # VERSIONED-DEF-LLVM-NEXT: Symbol {
415 # VERSIONED-DEF-LLVM-NEXT: Name: globalversym (40)
416 # VERSIONED-DEF-LLVM: Section: .gnu.version (0x1)
417 # VERSIONED-DEF-LLVM-NEXT: }
418 # VERSIONED-DEF-LLVM-NEXT: Symbol {
419 # VERSIONED-DEF-LLVM-NEXT: Name: aaa@@v2 (65)
420 # VERSIONED-DEF-LLVM: Section: .gnu.version (0x1)
421 # VERSIONED-DEF-LLVM-NEXT: }
422 # VERSIONED-DEF-LLVM-NEXT: Symbol {
423 # VERSIONED-DEF-LLVM-NEXT: Name: bbb@v3hidden (61)
424 # VERSIONED-DEF-LLVM: Section: .gnu.version (0x1)
425 # VERSIONED-DEF-LLVM-NEXT: }
426 # VERSIONED-DEF-LLVM-NEXT: Symbol {
427 # VERSIONED-DEF-LLVM-NEXT: Name: ccc@v4 (57)
428 # VERSIONED-DEF-LLVM: Section: .gnu.version (0x1)
429 # VERSIONED-DEF-LLVM-NEXT: }
430 # VERSIONED-DEF-LLVM-NEXT: Symbol {
431 # VERSIONED-DEF-LLVM-NEXT: Name: ddd@v5hidden (53)
432 # VERSIONED-DEF-LLVM: Section: .gnu.version (0x1)
433 # VERSIONED-DEF-LLVM-NEXT: }
434 # VERSIONED-DEF-LLVM: VersionSymbols [
435 # VERSIONED-DEF-LLVM: Name: localversym
436 # VERSIONED-DEF-LLVM: Name: globalversym
437 # VERSIONED-DEF-LLVM: Name: aaa@@v2
438 # VERSIONED-DEF-LLVM: Name: bbb@v3hidden
439 # VERSIONED-DEF-LLVM: Name: ccc@v4
440 # VERSIONED-DEF-LLVM: Name: ddd@v5hidden
442 # VERSIONED-DEF-GNU: Num: {{.*}} Vis Ndx Name
443 # VERSIONED-DEF-GNU: 1: {{.*}} DEFAULT 1 localversym
444 # VERSIONED-DEF-GNU-NEXT: 2: {{.*}} DEFAULT 1 globalversym
445 # VERSIONED-DEF-GNU-NEXT: 3: {{.*}} DEFAULT 1 aaa@@v2
446 # VERSIONED-DEF-GNU-NEXT: 4: {{.*}} DEFAULT 1 bbb@v3hidden
447 # VERSIONED-DEF-GNU-NEXT: 5: {{.*}} DEFAULT 1 ccc@v4
448 # VERSIONED-DEF-GNU-NEXT: 6: {{.*}} DEFAULT 1 ddd@v5hidden
450 ## Check the behavior for unnamed versioned section symbols.
451 # RUN: yaml2obj %s -DTYPE=STT_SECTION -DNAME="''" -DINDEX_BBB=SHN_ABS --docnum=6 -o %t6.sec.sym
452 # RUN: llvm-readobj -V --dyn-symbols %t6.sec.sym 2>&1 | \
453 # RUN: FileCheck %s -DFILE=%t6.sec.sym --check-prefix=VERSIONED-SEC-SYM-LLVM
454 # RUN: llvm-readelf -V --dyn-symbols %t6.sec.sym 2>&1 | \
455 # RUN: FileCheck %s -DFILE=%t6.sec.sym --check-prefix=VERSIONED-SEC-SYM-GNU
457 # VERSIONED-SEC-SYM-LLVM: DynamicSymbols [
458 # VERSIONED-SEC-SYM-LLVM: Name: localversym (28)
459 # VERSIONED-SEC-SYM-LLVM: Name: globalversym (40)
460 # VERSIONED-SEC-SYM-LLVM: Name: aaa@v2 (57)
461 # VERSIONED-SEC-SYM-LLVM: warning: '[[FILE]]': unable to get section index for symbol with st_shndx = 0xfff1 (SHN_ABS)
462 # VERSIONED-SEC-SYM-LLVM: Name: <?> (0)
463 # VERSIONED-SEC-SYM-LLVM: warning: '[[FILE]]': unable to get section index for symbol with st_shndx = 0x0 (SHN_UNDEF)
464 # VERSIONED-SEC-SYM-LLVM: Name: <?> (0)
465 # VERSIONED-SEC-SYM-LLVM: Name: ddd@v5hidden (53)
466 # VERSIONED-SEC-SYM-LLVM: VersionSymbols [
467 # VERSIONED-SEC-SYM-LLVM: Name: localversym
468 # VERSIONED-SEC-SYM-LLVM: Name: globalversym
469 # VERSIONED-SEC-SYM-LLVM: Name: aaa@v2
470 # VERSIONED-SEC-SYM-LLVM: Name: <?>
471 # VERSIONED-SEC-SYM-LLVM: Name: <?>
472 # VERSIONED-SEC-SYM-LLVM: Name: ddd@v5hidden
474 # VERSIONED-SEC-SYM-GNU: Symbol table '.dynsym' contains 7 entries:
475 # VERSIONED-SEC-SYM-GNU: Num: {{.*}} Ndx Name
476 # VERSIONED-SEC-SYM-GNU: 1: {{.*}} UND localversym
477 # VERSIONED-SEC-SYM-GNU-NEXT: 2: {{.*}} UND globalversym
478 # VERSIONED-SEC-SYM-GNU-NEXT: 3: {{.*}} UND aaa@v2
479 # VERSIONED-SEC-SYM-GNU-NEXT: warning: '[[FILE]]': unable to get section index for symbol with st_shndx = 0xfff1 (SHN_ABS)
480 # VERSIONED-SEC-SYM-GNU-NEXT: 4: {{.*}} ABS <?>
481 # VERSIONED-SEC-SYM-GNU-NEXT: warning: '[[FILE]]': unable to get section index for symbol with st_shndx = 0x0 (SHN_UNDEF)
482 # VERSIONED-SEC-SYM-GNU-NEXT: 5: {{.*}} UND <?>
483 # VERSIONED-SEC-SYM-GNU-NEXT: 6: {{.*}} UND ddd@v5hidden
485 ## Check we print a proper warning when an unnamed versioned section symbol has st_shndx = SHN_XINDEX, but there
486 ## is no SHT_SYMTAB_SHNDX section in the object.
487 # RUN: yaml2obj %s -DTYPE=STT_SECTION -DNAME="''" -DINDEX_BBB=SHN_XINDEX --docnum=6 -o %t6.sec.xindex.sym
488 # RUN: llvm-readobj -V --dyn-symbols %t6.sec.xindex.sym 2>&1 | \
489 # RUN: FileCheck %s -DFILE=%t6.sec.xindex.sym --check-prefix=VERSIONED-SEC-SYM-XINDEX-LLVM
490 # RUN: llvm-readelf -V --dyn-symbols %t6.sec.xindex.sym 2>&1 | \
491 # RUN: FileCheck %s -DFILE=%t6.sec.xindex.sym --check-prefix=VERSIONED-SEC-SYM-XINDEX-GNU
493 # VERSIONED-SEC-SYM-XINDEX-LLVM: Name: aaa@v2 (57)
494 # VERSIONED-SEC-SYM-XINDEX-LLVM: warning: '[[FILE]]': found an extended symbol index (4), but unable to locate the extended symbol index table
495 # VERSIONED-SEC-SYM-XINDEX-LLVM-NEXT: Symbol {
496 # VERSIONED-SEC-SYM-XINDEX-LLVM-NEXT: Name: <?> (0)
498 # VERSIONED-SEC-SYM-XINDEX-GNU: 3: {{.*}} UND aaa@v2
499 # VERSIONED-SEC-SYM-XINDEX-GNU-NEXT: warning: '[[FILE]]': found an extended symbol index (4), but unable to locate the extended symbol index table
500 # VERSIONED-SEC-SYM-XINDEX-GNU-NEXT: 4: {{.*}} RSV[0xffff] <?>
502 ## Case 8: Check what we print when:
503 ## a) The dynamic symbol table does not exist.
504 # RUN: yaml2obj %s --docnum=7 -o %t7
505 # RUN: llvm-readobj --dyn-symbols %t7 | FileCheck %s --check-prefix=NO-DYNSYM-LLVM
506 # RUN: llvm-readelf --dyn-symbols %t7 | count 0
507 ## b) The dynamic symbol table has a size of 0.
508 # RUN: yaml2obj %s --docnum=8 -o %t8
509 # RUN: llvm-readobj --dyn-symbols %t8 | FileCheck %s --check-prefix=NO-DYNSYM-LLVM
510 # RUN: llvm-readelf --dyn-symbols %t8 | count 0
511 ## c) The dynamic symbol table only contains the null symbol.
512 # RUN: yaml2obj %s --docnum=9 -o %t9
513 # RUN: llvm-readobj --dyn-symbols %t9 | FileCheck %s --check-prefix=DYNSYM-EMPTY-LLVM
514 # RUN: llvm-readelf --dyn-symbols %t9 | FileCheck %s --check-prefix=DYNSYM-EMPTY-GNU
516 # NO-DYNSYM-LLVM: DynamicSymbols [
517 # NO-DYNSYM-LLVM-NEXT: ]
519 # DYNSYM-EMPTY-LLVM: DynamicSymbols [
520 # DYNSYM-EMPTY-LLVM-NEXT: Symbol {
521 # DYNSYM-EMPTY-LLVM-NEXT: Name: (0)
522 # DYNSYM-EMPTY-LLVM-NEXT: Value: 0x0
523 # DYNSYM-EMPTY-LLVM-NEXT: Size: 0
524 # DYNSYM-EMPTY-LLVM-NEXT: Binding: Local (0x0)
525 # DYNSYM-EMPTY-LLVM-NEXT: Type: None (0x0)
526 # DYNSYM-EMPTY-LLVM-NEXT: Other: 0
527 # DYNSYM-EMPTY-LLVM-NEXT: Section: Undefined (0x0)
528 # DYNSYM-EMPTY-LLVM-NEXT: }
529 # DYNSYM-EMPTY-LLVM-NEXT: ]
531 # DYNSYM-EMPTY-GNU: Symbol table '.dynsym' contains 1 entries:
532 # DYNSYM-EMPTY-GNU-NEXT: Num: Value Size Type Bind Vis Ndx Name
533 # DYNSYM-EMPTY-GNU-NEXT: 0: 00000000 0 NOTYPE LOCAL DEFAULT UND
558 ## Case 9: Check what we print when:
559 ## a) The size of the dynamic symbol table is not a multiple of its entry size.
560 # RUN: yaml2obj %s --docnum=10 -o %t10
561 # RUN: llvm-readobj --dyn-symbols %t10 2>&1 | FileCheck %s -DFILE=%t10 --check-prefix=DYNSYM-SIZE-INVALID1
562 # RUN: llvm-readelf --dyn-symbols %t10 2>&1 | FileCheck %s -DFILE=%t10 --check-prefix=DYNSYM-SIZE-INVALID1
564 # DYNSYM-SIZE-INVALID1: warning: '[[FILE]]': SHT_DYNSYM section with index 1 has invalid size (0x1) or entry size (0x10)
566 ## b) The same, but the DT_SYMTAB tag is present. In this case the dynamic tag has priority over the
567 ## information about a location and an entity size of the dynamic symbol table from the section header.
568 ## The code uses sizeof(Elf_Sym) for an entity size, so it can't be incorrect and
569 ## the message printed is a bit shorter.
570 # RUN: yaml2obj %s --docnum=11 -o %t11
571 # RUN: llvm-readobj --dyn-symbols %t11 2>&1 | FileCheck %s -DFILE=%t11 --check-prefix=DYNSYM-SIZE-INVALID2
572 # RUN: llvm-readelf --dyn-symbols %t11 2>&1 | FileCheck %s -DFILE=%t11 --check-prefix=DYNSYM-SIZE-INVALID2
574 # DYNSYM-SIZE-INVALID2: warning: '[[FILE]]': SHT_DYNSYM section with index 2 has invalid size (0x1){{$}}
576 ## c) In the case when the DT_SYMENT tag is present, we report when it's value does not match the
577 # value of the symbol size for the platform.
578 # RUN: yaml2obj %s -D BITS=32 --docnum=12 -o %t12
579 # RUN: llvm-readobj --dyn-symbols %t12 2>&1 | \
580 # RUN: FileCheck %s -DFILE=%t12 --implicit-check-not=warning: --check-prefix=DYNSYM-SIZE-INVALID3
581 # RUN: llvm-readelf --dyn-symbols %t12 2>&1 | \
582 # RUN: FileCheck %s -DFILE=%t12 --implicit-check-not=warning: --check-prefix=DYNSYM-SIZE-INVALID3
583 # RUN: yaml2obj %s -D BITS=64 --docnum=12 -o %t13
584 # RUN: llvm-readobj --dyn-symbols %t13 2>&1 | \
585 # RUN: FileCheck %s -DFILE=%t13 --implicit-check-not=warning: --check-prefix=DYNSYM-SIZE-INVALID4
586 # RUN: llvm-readelf --dyn-symbols %t13 2>&1 | \
587 # RUN: FileCheck %s -DFILE=%t13 --implicit-check-not=warning: --check-prefix=DYNSYM-SIZE-INVALID4
589 # DYNSYM-SIZE-INVALID3: warning: '[[FILE]]': DT_SYMENT value of 0x123 is not the size of a symbol (0x10){{$}}
590 # DYNSYM-SIZE-INVALID4: warning: '[[FILE]]': DT_SYMENT value of 0x123 is not the size of a symbol (0x18){{$}}
627 Class: ELFCLASS[[BITS]]
641 ## Case 10: Check we report a warning when the DT_STRSZ value is broken so that the dynamic string
642 ## table goes past the end of the file. Document we stop dumping symbols and report an error.
644 # RUN: yaml2obj %s --docnum=13 -o %t14
645 # RUN: llvm-readobj --dyn-symbols %t14 2>&1 | \
646 # RUN: FileCheck %s -DFILE=%t14 --check-prefix=DYNSTR-INVALID-LLVM
647 # RUN: llvm-readelf --dyn-symbols %t14 2>&1 | \
648 # RUN: FileCheck %s -DFILE=%t14 --check-prefix=DYNSTR-INVALID-GNU
650 # DYNSTR-INVALID-LLVM: warning: '[[FILE]]': the dynamic string table at 0x78 goes past the end of the file (0x2a8) with DT_STRSZ = 0xffffffff
651 # DYNSTR-INVALID-LLVM: DynamicSymbols [
652 # DYNSTR-INVALID-LLVM-NEXT: Symbol {
653 # DYNSTR-INVALID-LLVM-NEXT: Name: (0)
654 # DYNSTR-INVALID-LLVM-NEXT: Value: 0x0
655 # DYNSTR-INVALID-LLVM-NEXT: Size: 0
656 # DYNSTR-INVALID-LLVM-NEXT: Binding: Local (0x0)
657 # DYNSTR-INVALID-LLVM-NEXT: Type: None (0x0)
658 # DYNSTR-INVALID-LLVM-NEXT: Other: 0
659 # DYNSTR-INVALID-LLVM-NEXT: Section: Undefined (0x0)
660 # DYNSTR-INVALID-LLVM-NEXT: }
661 # DYNSTR-INVALID-LLVM-NEXT: warning: '[[FILE]]': st_name (0xffffff00) is past the end of the string table of size 0x6
662 # DYNSTR-INVALID-LLVM-NEXT: Symbol {
663 # DYNSTR-INVALID-LLVM-NEXT: Name: <?> (4294967040)
664 # DYNSTR-INVALID-LLVM-NEXT: Value: 0x0
665 # DYNSTR-INVALID-LLVM-NEXT: Size: 0
666 # DYNSTR-INVALID-LLVM-NEXT: Binding: Local (0x0)
667 # DYNSTR-INVALID-LLVM-NEXT: Type: None (0x0)
668 # DYNSTR-INVALID-LLVM-NEXT: Other: 0
669 # DYNSTR-INVALID-LLVM-NEXT: Section: Undefined (0x0)
670 # DYNSTR-INVALID-LLVM-NEXT: }
671 # DYNSTR-INVALID-LLVM-NEXT: Symbol {
672 # DYNSTR-INVALID-LLVM-NEXT: Name: test (1)
673 # DYNSTR-INVALID-LLVM-NEXT: Value: 0x0
674 # DYNSTR-INVALID-LLVM-NEXT: Size: 0
675 # DYNSTR-INVALID-LLVM-NEXT: Binding: Local (0x0)
676 # DYNSTR-INVALID-LLVM-NEXT: Type: None (0x0)
677 # DYNSTR-INVALID-LLVM-NEXT: Other: 0
678 # DYNSTR-INVALID-LLVM-NEXT: Section: Undefined (0x0)
679 # DYNSTR-INVALID-LLVM-NEXT: }
680 # DYNSTR-INVALID-LLVM-NEXT: ]
682 # DYNSTR-INVALID-GNU: warning: '[[FILE]]': the dynamic string table at 0x78 goes past the end of the file (0x2a8) with DT_STRSZ = 0xffffffff
683 # DYNSTR-INVALID-GNU: Symbol table '.dynsym' contains 3 entries:
684 # DYNSTR-INVALID-GNU-NEXT: Num: Value Size Type Bind Vis Ndx Name
685 # DYNSTR-INVALID-GNU-NEXT: 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND
686 # DYNSTR-INVALID-GNU-NEXT: warning: '[[FILE]]': st_name (0xffffff00) is past the end of the string table of size 0x6
687 # DYNSTR-INVALID-GNU-NEXT: 1: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND <?>
688 # DYNSTR-INVALID-GNU-NEXT: 2: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND test
699 Content: '007465737400' ## '\0', 'test', '\0'
713 ## An arbitrary valid symbol to document we report an error before dumping it.
721 ## Case 11: check various warnings we report when fields of the SHT_DYNSYM section are broken.
723 ## a) check we report a warning when the entry size of the dynamic symbol table is zero.
724 # RUN: yaml2obj %s --docnum=14 -DENTSIZE=0x0 -o %t15.entsize
725 # RUN: llvm-readobj --dyn-symbols %t15.entsize 2>&1 | FileCheck %s -DFILE=%t15.entsize --check-prefix=DYNSYM-ZERO-ENTSIZE-LLVM
726 # RUN: llvm-readelf --dyn-symbols %t15.entsize 2>&1 | \
727 # RUN: FileCheck %s -DFILE=%t15.entsize --check-prefix=DYNSYM-ZERO-ENTSIZE-GNU --implicit-check-not="Symbol table"
729 # DYNSYM-ZERO-ENTSIZE-LLVM: DynamicSymbols [
730 # DYNSYM-ZERO-ENTSIZE-LLVM-NEXT: warning: '[[FILE]]': SHT_DYNSYM section with index 1 has invalid size (0x20) or entry size (0x0)
731 # DYNSYM-ZERO-ENTSIZE-LLVM-NEXT: ]
733 # DYNSYM-ZERO-ENTSIZE-GNU: warning: '[[FILE]]': SHT_DYNSYM section with index 1 has invalid size (0x20) or entry size (0x0)
743 EntSize: [[ENTSIZE=<none>]]
744 Link: [[LINK=<none>]]
745 ShOffset: [[OFFSET=<none>]]
746 ShSize: [[SIZE=<none>]]
750 ## b) check we report a warning when the sh_offset field of the SHT_DYNSYM section is
751 ## invalid (sh_offset + sh_size is greater than the file size). Check we don't dump
752 ## dynamic symbols in this case.
753 # RUN: yaml2obj --docnum=14 %s -DOFFSET=0xffffffff -o %t15.offset
754 # RUN: llvm-readobj %t15.offset --dyn-symbols 2>&1 | FileCheck %s -DFILE=%t15.offset \
755 # RUN: --check-prefixes=OFFSET-BROKEN,OFFSET-BROKEN-LLVM
756 # RUN: llvm-readelf %t15.offset --dyn-symbols 2>&1 | FileCheck %s -DFILE=%t15.offset \
757 # RUN: --implicit-check-not="Symbol table" --check-prefix=OFFSET-BROKEN
759 # OFFSET-BROKEN: warning: '[[FILE]]': unable to read dynamic symbols from SHT_DYNSYM section with index 1: offset (0xffffffff) + size (0x20) is greater than the file size (0x148)
761 # OFFSET-BROKEN-LLVM: DynamicSymbols [
762 # OFFSET-BROKEN-LLVM-NEXT: ]
764 ## c) check we report a warning when the sh_size field of the SHT_DYNSYM section is
765 ## invalid (sh_offset + sh_size is greater than the file size). Check we don't dump
766 ## dynamic symbols in this case.
767 # RUN: yaml2obj --docnum=14 %s -DSIZE=0xffffffff -o %t15.size
768 # RUN: llvm-readobj %t15.size --dyn-symbols 2>&1 | FileCheck %s -DFILE=%t15.size \
769 # RUN: --check-prefixes=SIZE-BROKEN,SIZE-BROKEN-LLVM
770 # RUN: llvm-readelf %t15.size --dyn-symbols 2>&1 | FileCheck %s -DFILE=%t15.size \
771 # RUN: --implicit-check-not="Symbol table" --check-prefix=SIZE-BROKEN
773 # SIZE-BROKEN: warning: '[[FILE]]': unable to read dynamic symbols from SHT_DYNSYM section with index 1: offset (0x34) + size (0xffffffff) is greater than the file size (0x148)
775 # SIZE-BROKEN-LLVM: DynamicSymbols [
776 # SIZE-BROKEN-LLVM-NEXT: ]
778 ## d) check we report a warning when the sh_link field of the SHT_DYNSYM section
779 ## is not a valid section index or is not an index of a valid string table.
780 # RUN: yaml2obj --docnum=14 %s -DLINK=0xffffffff -o %t16.link
781 # RUN: llvm-readobj %t16.link --dyn-symbols 2>&1 | FileCheck %s -DFILE=%t16.link \
782 # RUN: --check-prefixes=LINK-BROKEN1,LINK-BROKEN-LLVM --implicit-check-not=warning:
783 # RUN: llvm-readelf %t16.link --dyn-symbols 2>&1 | FileCheck %s -DFILE=%t16.link \
784 # RUN: --check-prefixes=LINK-BROKEN1,LINK-BROKEN-GNU --implicit-check-not=warning:
786 ## Also test that we are able to dump section headers even if the .dynsym section's sh_link field is broken.
787 # RUN: llvm-readobj %t16.link --section-headers --dyn-symbols 2>&1 | FileCheck %s -DFILE=%t16.link \
788 # RUN: --check-prefixes=LINK-BROKEN1,LINK-SEC-HDRS-LLVM,LINK-BROKEN-LLVM --implicit-check-not=warning:
789 # RUN: llvm-readelf %t16.link --section-headers --dyn-symbols 2>&1 | FileCheck %s -DFILE=%t16.link \
790 # RUN: --check-prefixes=LINK-BROKEN1,LINK-SEC-HDRS-GNU,LINK-BROKEN-GNU
792 # RUN: yaml2obj --docnum=14 %s -DLINK=0x0 -o %t16.link.0
793 # RUN: llvm-readobj %t16.link.0 --dyn-symbols 2>&1 | FileCheck %s -DFILE=%t16.link.0 \
794 # RUN: --check-prefixes=LINK-BROKEN2,LINK-BROKEN-LLVM --implicit-check-not=warning:
795 # RUN: llvm-readelf %t16.link.0 --dyn-symbols 2>&1 | FileCheck %s -DFILE=%t16.link.0 \
796 # RUN: --check-prefixes=LINK-BROKEN2,LINK-BROKEN-GNU --implicit-check-not=warning:
798 ## Also test that we are able to dump section headers even if the .dynsym section's sh_link field is broken.
799 # RUN: llvm-readobj %t16.link.0 --section-headers --dyn-symbols 2>&1 | FileCheck %s -DFILE=%t16.link.0 \
800 # RUN: --check-prefixes=LINK-BROKEN2,LINK-SEC-HDRS-LLVM,LINK-BROKEN-LLVM --implicit-check-not=warning:
801 # RUN: llvm-readelf %t16.link.0 --section-headers --dyn-symbols 2>&1 | FileCheck %s -DFILE=%t16.link.0 \
802 # RUN: --check-prefixes=LINK-BROKEN2,LINK-SEC-HDRS-GNU,LINK-BROKEN-GNU --implicit-check-not=warning:
804 # LINK-BROKEN1: warning: '[[FILE]]': unable to get the string table for the SHT_DYNSYM section with index 1: invalid section index: 4294967295
805 # LINK-BROKEN2: warning: '[[FILE]]': unable to get the string table for the SHT_DYNSYM section with index 1: invalid sh_type for string table section [index 0]: expected SHT_STRTAB, but got SHT_NULL
807 # LINK-SEC-HDRS-LLVM: Sections [
808 # LINK-SEC-HDRS-GNU: There are 5 section headers, starting at offset 0x80:
810 # LINK-BROKEN-LLVM: DynamicSymbols [
811 # LINK-BROKEN-LLVM-NEXT: warning: '[[FILE]]': st_name (0x0) is past the end of the string table of size 0x0
812 # LINK-BROKEN-LLVM-NEXT: Symbol {
813 # LINK-BROKEN-LLVM-NEXT: Name: <?> (0)
814 # LINK-BROKEN-LLVM-NEXT: Value: 0x0
815 # LINK-BROKEN-LLVM-NEXT: Size: 0
816 # LINK-BROKEN-LLVM-NEXT: Binding: Local (0x0)
817 # LINK-BROKEN-LLVM-NEXT: Type: None (0x0)
818 # LINK-BROKEN-LLVM-NEXT: Other: 0
819 # LINK-BROKEN-LLVM-NEXT: Section: Undefined (0x0)
820 # LINK-BROKEN-LLVM-NEXT: }
821 # LINK-BROKEN-LLVM-NEXT: warning: '[[FILE]]': st_name (0x1) is past the end of the string table of size 0x0
822 # LINK-BROKEN-LLVM-NEXT: Symbol {
823 # LINK-BROKEN-LLVM-NEXT: Name: <?> (1)
824 # LINK-BROKEN-LLVM-NEXT: Value: 0x0
825 # LINK-BROKEN-LLVM-NEXT: Size: 0
826 # LINK-BROKEN-LLVM-NEXT: Binding: Local (0x0)
827 # LINK-BROKEN-LLVM-NEXT: Type: None (0x0)
828 # LINK-BROKEN-LLVM-NEXT: Other: 0
829 # LINK-BROKEN-LLVM-NEXT: Section: Undefined (0x0)
830 # LINK-BROKEN-LLVM-NEXT: }
831 # LINK-BROKEN-LLVM-NEXT: ]
833 # LINK-BROKEN-GNU: Symbol table '.dynsym' contains 2 entries:
834 # LINK-BROKEN-GNU-NEXT: Num: Value Size Type Bind Vis Ndx Name
835 # LINK-BROKEN-GNU-NEXT: warning: '[[FILE]]': st_name (0x0) is past the end of the string table of size 0x0
836 # LINK-BROKEN-GNU-NEXT: 0: 00000000 0 NOTYPE LOCAL DEFAULT UND <?>
837 # LINK-BROKEN-GNU-NEXT: warning: '[[FILE]]': st_name (0x1) is past the end of the string table of size 0x0
838 # LINK-BROKEN-GNU-NEXT: 1: 00000000 0 NOTYPE LOCAL DEFAULT UND <?>