llvm.org GIT mirror llvm / 9b4a520
[llvm-readobj] Add GNU style dumper for .gnu.version section Summary: Currently, `llvm-readobj` do not support GNU style dumper for symbol versioning sections. In this patch, I would like to implement dumper for `.gnu.version` section Reviewers: jhenderson, rupprecht, grimar Reviewed By: jhenderson, rupprecht Subscribers: llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D59877 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@357578 91177308-0d34-0410-b5e6-96231b3b80d8 Xing GUO 1 year, 6 months ago
4 changed file(s) with 144 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
0 # RUN: yaml2obj %s -o %t
1 # RUN: llvm-readelf -V %t | FileCheck %s --check-prefix=HIDDEN
2
3 # HIDDEN: Version symbols section '.gnu.version' contains 2 entries:
4 # HIDDEN-NEXT: Addr: 0000000000200210 Offset: 0x000240 Link: 6 (.dynsym)
5 # HIDDEN-NEXT: 000: 0 (*local*) 3h(hiddensym)
6
7 --- !ELF
8 FileHeader:
9 Class: ELFCLASS64
10 Data: ELFDATA2LSB
11 Type: ET_EXEC
12 Machine: EM_X86_64
13 Entry: 0x0000000000201000
14 Sections:
15 - Name: .gnu.version
16 Type: SHT_GNU_versym
17 Flags: [ SHF_ALLOC ]
18 Address: 0x0000000000200210
19 Link: .dynsym
20 AddressAlign: 0x0000000000000002
21 EntSize: 0x0000000000000002
22 Entries: [ 0, 0x8003 ]
23 - Name: .gnu.version_r
24 Type: SHT_GNU_verneed
25 Flags: [ SHF_ALLOC ]
26 Address: 0x0000000000200250
27 Link: .dynstr
28 AddressAlign: 0x0000000000000004
29 Info: 0x0000000000000001
30 Dependencies:
31 - Version: 1
32 File: somefile
33 Entries:
34 - Name: hiddensym
35 Hash: 1234
36 Flags: 0
37 Other: 3
38 DynamicSymbols:
39 Global:
40 - Name: h
41 ...
0 # RUN: yaml2obj %s -o %t
1 # RUN: llvm-readelf -V %t | FileCheck %s --check-prefix=INVALID
2
3 # INVALID: Version symbols section '.gnu.version' contains 2 entries:
4 # INVALID-NEXT: Addr: 0000000000200210 Offset: 0x000240 Link: 6 (.dynsym)
5 # INVALID-NEXT: 000: 0 (*local*) 3 (*invalid*)
6
7 --- !ELF
8 FileHeader:
9 Class: ELFCLASS64
10 Data: ELFDATA2LSB
11 Type: ET_EXEC
12 Machine: EM_X86_64
13 Entry: 0x0000000000201000
14 Sections:
15 - Name: .gnu.version
16 Type: SHT_GNU_versym
17 Flags: [ SHF_ALLOC ]
18 Address: 0x0000000000200210
19 Link: .dynsym
20 AddressAlign: 0x0000000000000002
21 EntSize: 0x0000000000000002
22 Entries: [ 0, 3 ]
23 - Name: .gnu.version_r
24 Type: SHT_GNU_verneed
25 Flags: [ SHF_ALLOC ]
26 Address: 0x0000000000200250
27 Link: .dynstr
28 AddressAlign: 0x0000000000000004
29 Info: 0x0000000000000001
30 Dependencies:
31 - Version: 1
32 File: somefile
33 Entries:
34 - Name: '' # invalid name
35 Hash: 1937
36 Flags: 233
37 Other: 3
38 DynamicSymbols:
39 Global:
40 - Name: f
41 ...
7676 GNU-VERDEF: 0x000000006ffffffc VERDEF 0x25c
7777 GNU-VERDEF: 0x000000006ffffffd VERDEFNUM 3
7878
79 GNU-VERDEF: Dumper for .gnu.version is not implemented
79 GNU-VERDEF: Version symbols section '.gnu.version' contains 8 entries:
80 GNU-VERDEF-NEXT: Addr: 000000000000024c Offset: 0x00024c Link: 1 (.dynsym)
81 GNU-VERDEF-NEXT: 000: 0 (*local*) 1 (*global*) 1 (*global*) 3 (VERSION2)
82 GNU-VERDEF-NEXT: 004: 1 (*global*) 2 (VERSION1) 2 (VERSION1) 3 (VERSION2)
83
8084 GNU-VERDEF: Dumper for .gnu.version_d is not implemented
8185
8286 RUN: llvm-readobj -V %p/Inputs/verneed.elf-x86-64 | FileCheck %s --check-prefix=LLVM-VERNEED
113117 LLVM-VERNEED-NEXT: }
114118 LLVM-VERNEED-NEXT: }
115119
116 GNU-VERNEED: Dumper for .gnu.version is not implemented
120 GNU-VERNEED: Version symbols section '.gnu.version' contains 4 entries:
121 GNU-VERNEED-NEXT: Addr: 0000000000010228 Offset: 0x000228 Link: 1 (.dynsym)
122 GNU-VERNEED-NEXT: 000: 0 (*local*) 2 (v3) 3 (v2) 4 (v1)
123
117124 GNU-VERNEED: Dumper for .gnu.version_r is not implemented
118125
33543354 return;
33553355
33563356 StringRef SecName = unwrapOrError(Obj->getSectionName(Sec));
3357 OS << "Dumper for " << SecName << " is not implemented\n";
3357 uint64_t Entries = Sec->sh_size / sizeof(Elf_Versym);
3358
3359 OS << "Version symbols section '" << SecName << "' "
3360 << "contains " << Entries << " entries:\n";
3361
3362 const Elf_Shdr *SymTab = unwrapOrError(Obj->getSection(Sec->sh_link));
3363 StringRef SymTabName = unwrapOrError(Obj->getSectionName(SymTab));
3364 OS << " Addr: " << format_hex_no_prefix(Sec->sh_addr, 16)
3365 << " Offset: " << format_hex(Sec->sh_offset, 8)
3366 << " Link: " << Sec->sh_link << " (" << SymTabName << ")\n";
3367
3368 const uint8_t *VersymBuf =
3369 reinterpret_cast(Obj->base() + Sec->sh_offset);
3370 const ELFDumper *Dumper = this->dumper();
3371 StringRef StrTable = Dumper->getDynamicStringTable();
3372
3373 // readelf prints 4 entries per line.
3374 for (uint64_t VersymRow = 0; VersymRow < Entries; VersymRow += 4) {
3375 OS << " " << format_hex_no_prefix(VersymRow, 3) << ":";
3376
3377 for (uint64_t VersymIndex = 0;
3378 (VersymIndex < 4) && (VersymIndex + VersymRow) < Entries;
3379 ++VersymIndex) {
3380 const Elf_Versym *Versym =
3381 reinterpret_cast(VersymBuf);
3382 switch (Versym->vs_index) {
3383 case 0:
3384 OS << " 0 (*local*) ";
3385 break;
3386 case 1:
3387 OS << " 1 (*global*) ";
3388 break;
3389 default:
3390 OS << format("%4x%c", Versym->vs_index & VERSYM_VERSION,
3391 Versym->vs_index & VERSYM_HIDDEN ? 'h' : ' ');
3392
3393 bool IsDefault = true;
3394 std::string VersionName = Dumper->getSymbolVersionByIndex(
3395 StrTable, Versym->vs_index, IsDefault);
3396
3397 if (!VersionName.empty())
3398 VersionName = "(" + VersionName + ")";
3399 else
3400 VersionName = "(*invalid*)";
3401 OS << left_justify(VersionName, 13);
3402 }
3403 VersymBuf += sizeof(Elf_Versym);
3404 }
3405 OS << '\n';
3406 }
3407 OS << '\n';
33583408 }
33593409
33603410 template