llvm.org GIT mirror llvm / 4598154
[llvm-readobj/ELF] Print GNU Hash section Add a new command line switch, -gnu-hash-table, to print the content of that section. Differential Revision: http://reviews.llvm.org/D13696 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@250291 91177308-0d34-0410-b5e6-96231b3b80d8 Igor Kudrin 5 years ago
11 changed file(s) with 132 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
5252 typedef Elf_Vernaux_Impl Elf_Vernaux;
5353 typedef Elf_Versym_Impl Elf_Versym;
5454 typedef Elf_Hash_Impl Elf_Hash;
55 typedef Elf_GnuHash_Impl Elf_GnuHash;
5556 typedef iterator_range Elf_Dyn_Range;
5657 typedef iterator_range Elf_Shdr_Range;
5758 typedef iterator_range Elf_Sym_Range;
483483 }
484484 };
485485
486 // .gnu.hash section
487 template
488 struct Elf_GnuHash_Impl {
489 LLVM_ELF_IMPORT_TYPES_ELFT(ELFT)
490 Elf_Word nbuckets;
491 Elf_Word symndx;
492 Elf_Word maskwords;
493 Elf_Word shift2;
494
495 ArrayRef filter() const {
496 return ArrayRef(reinterpret_cast(&shift2 + 1),
497 maskwords);
498 }
499
500 ArrayRef buckets() const {
501 return ArrayRef(
502 reinterpret_cast(filter().end()), nbuckets);
503 }
504
505 ArrayRef values(unsigned DynamicSymCount) const {
506 return ArrayRef(buckets().end(), DynamicSymCount - symndx);
507 }
508 };
509
486510 // MIPS .reginfo section
487511 template
488512 struct Elf_Mips_RegInfo;
0 // Check dumping of the GNU Hash section
1 // The input was generated using the following:
2 // $ llvm-mc -filetype=obj -triple=i386-pc-linux -o example-i386.o example.s
3 // $ llvm-mc -filetype=obj -triple=x86_64-pc-linux -o example-x86_64.o example.s
4 // $ llvm-mc -filetype=obj -triple=powerpc-pc-linux -o example-ppc.o example.s
5 // $ llvm-mc -filetype=obj -triple=powerpc64-pc-linux -o example-ppc64.o example.s
6 // $ ld -shared -m elf_i386 -hash-style=gnu -o gnuhash.so.elf-i386 example-i386.o
7 // $ ld -shared -m elf_x86_64 -hash-style=gnu -o gnuhash.so.elf-x86_64 example-x86_64.o
8 // $ ld -shared -m elf32ppc -hash-style=gnu -o gnuhash.so.elf-ppc example-ppc.o
9 // $ ld -shared -m elf64ppc -hash-style=gnu -o gnuhash.so.elf-ppc64 example-ppc64.o
10 // $ cat example.s
11 // .globl foo
12 // foo:
13
14 RUN: llvm-readobj -gnu-hash-table %p/Inputs/gnuhash.so.elf-i386 | FileCheck %s -check-prefix I386
15 RUN: llvm-readobj -gnu-hash-table %p/Inputs/gnuhash.so.elf-x86_64 | FileCheck %s -check-prefix X86_64
16 RUN: llvm-readobj -gnu-hash-table %p/Inputs/gnuhash.so.elf-ppc | FileCheck %s -check-prefix PPC
17 RUN: llvm-readobj -gnu-hash-table %p/Inputs/gnuhash.so.elf-ppc64 | FileCheck %s -check-prefix PPC64
18
19 I386: Arch: i386
20 I386: GnuHashTable {
21 I386-NEXT: Num Buckets: 3
22 I386-NEXT: First Hashed Symbol Index: 1
23 I386-NEXT: Num Mask Words: 1
24 I386-NEXT: Shift Count: 5
25 I386-NEXT: Bloom Filter: [0x39004608]
26 I386-NEXT: Buckets: [1, 4, 0]
27 I386-NEXT: Values: [0xB887388, 0xECD54542, 0x7C92E3BB, 0x1C5871D9]
28 I386-NEXT: }
29
30 X86_64: Arch: x86_64
31 X86_64: GnuHashTable {
32 X86_64-NEXT: Num Buckets: 3
33 X86_64-NEXT: First Hashed Symbol Index: 1
34 X86_64-NEXT: Num Mask Words: 1
35 X86_64-NEXT: Shift Count: 6
36 X86_64-NEXT: Bloom Filter: [0x800000001204288]
37 X86_64-NEXT: Buckets: [1, 4, 0]
38 X86_64-NEXT: Values: [0xB887388, 0xECD54542, 0x7C92E3BB, 0x1C5871D9]
39 X86_64-NEXT: }
40
41 PPC: Arch: powerpc
42 PPC: GnuHashTable {
43 PPC-NEXT: Num Buckets: 3
44 PPC-NEXT: First Hashed Symbol Index: 1
45 PPC-NEXT: Num Mask Words: 1
46 PPC-NEXT: Shift Count: 5
47 PPC-NEXT: Bloom Filter: [0x3D00460A]
48 PPC-NEXT: Buckets: [1, 5, 0]
49 PPC-NEXT: Values: [0xEEBEC3A, 0xB887388, 0xECD54542, 0x7C92E3BB, 0x1C5871D9]
50 PPC-NEXT: }
51
52 PPC64: Arch: powerpc64
53 PPC64: GnuHashTable {
54 PPC64-NEXT: Num Buckets: 3
55 PPC64-NEXT: First Hashed Symbol Index: 1
56 PPC64-NEXT: Num Mask Words: 1
57 PPC64-NEXT: Shift Count: 6
58 PPC64-NEXT: Bloom Filter: [0x800000001204288]
59 PPC64-NEXT: Buckets: [1, 4, 0]
60 PPC64-NEXT: Values: [0xB887388, 0xECD54542, 0x7C92E3BB, 0x1C5871D9]
61 PPC64-NEXT: }
62
5555 void printNeededLibraries() override;
5656 void printProgramHeaders() override;
5757 void printHashTable() override;
58 void printGnuHashTable() override;
5859 void printLoadName() override;
5960
6061 void printAttributes() override;
7576 typedef typename ELFO::Elf_Rela_Range Elf_Rela_Range;
7677 typedef typename ELFO::Elf_Phdr Elf_Phdr;
7778 typedef typename ELFO::Elf_Hash Elf_Hash;
79 typedef typename ELFO::Elf_GnuHash Elf_GnuHash;
7880 typedef typename ELFO::Elf_Ehdr Elf_Ehdr;
7981 typedef typename ELFO::Elf_Word Elf_Word;
8082 typedef typename ELFO::uintX_t uintX_t;
135137 const Elf_Sym *DynSymStart = nullptr;
136138 StringRef SOName;
137139 const Elf_Hash *HashTable = nullptr;
140 const Elf_GnuHash *GnuHashTable = nullptr;
138141 const Elf_Shdr *DotDynSymSec = nullptr;
139142 const Elf_Shdr *DotSymtabSec = nullptr;
140143 ArrayRef ShndxTable;
849852 HashTable =
850853 reinterpret_cast(toMappedAddr(Dyn.getPtr()));
851854 break;
855 case ELF::DT_GNU_HASH:
856 GnuHashTable =
857 reinterpret_cast(toMappedAddr(Dyn.getPtr()));
858 break;
852859 case ELF::DT_RELA:
853860 DynRelaRegion.Addr = toMappedAddr(Dyn.getPtr());
854861 break;
15321539 W.printList("Chains", HashTable->chains());
15331540 }
15341541
1542 template
1543 void ELFDumper::printGnuHashTable() {
1544 DictScope D(W, "GnuHashTable");
1545 if (!GnuHashTable)
1546 return;
1547 W.printNumber("Num Buckets", GnuHashTable->nbuckets);
1548 W.printNumber("First Hashed Symbol Index", GnuHashTable->symndx);
1549 W.printNumber("Num Mask Words", GnuHashTable->maskwords);
1550 W.printNumber("Shift Count", GnuHashTable->shift2);
1551 W.printHexList("Bloom Filter", GnuHashTable->filter());
1552 W.printList("Buckets", GnuHashTable->buckets());
1553 if (!DotDynSymSec)
1554 reportError("No dynamic symbol section");
1555 W.printHexList("Values",
1556 GnuHashTable->values(DotDynSymSec->getEntityCount()));
1557 }
1558
15351559 template void ELFDumper::printLoadName() {
15361560 outs() << "LoadName: " << SOName << '\n';
15371561 }
3838 virtual void printNeededLibraries() { }
3939 virtual void printProgramHeaders() { }
4040 virtual void printHashTable() { }
41 virtual void printGnuHashTable() { }
4142 virtual void printLoadName() {}
4243
4344 // Only implemented for ARM ELF at this time.
193193 OS << "]\n";
194194 }
195195
196 template
197 void printHexList(StringRef Label, const T &List) {
198 startLine() << Label << ": [";
199 bool Comma = false;
200 for (const auto &Item : List) {
201 if (Comma)
202 OS << ", ";
203 OS << hex(Item);
204 Comma = true;
205 }
206 OS << "]\n";
207 }
208
196209 template
197210 void printHex(StringRef Label, T Value) {
198211 startLine() << Label << ": " << hex(Value) << "\n";
130130 // -hash-table
131131 cl::opt HashTable("hash-table",
132132 cl::desc("Display ELF hash table"));
133
134 // -gnu-hash-table
135 cl::opt GnuHashTable("gnu-hash-table",
136 cl::desc("Display ELF .gnu.hash section"));
133137
134138 // -expand-relocs
135139 cl::opt ExpandRelocs("expand-relocs",
321325 Dumper->printProgramHeaders();
322326 if (opts::HashTable)
323327 Dumper->printHashTable();
328 if (opts::GnuHashTable)
329 Dumper->printGnuHashTable();
324330 if (Obj->getArch() == llvm::Triple::arm && Obj->isELF())
325331 if (opts::ARMAttributes)
326332 Dumper->printAttributes();