llvm.org GIT mirror llvm / 310e6c3
Don't look for a SHT_DYNSYM in the ELFFile's constructor. Yet another step in not having it scan every section. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@244353 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 5 years ago
3 changed file(s) with 30 addition(s) and 18 deletion(s). Raw diff Collapse all Expand all
6969 StringRef DotShstrtab; // Section header string table.
7070 StringRef DotStrtab; // Symbol header string table.
7171 const Elf_Shdr *dot_symtab_sec = nullptr; // Symbol table section.
72 const Elf_Shdr *DotDynSymSec = nullptr; // Dynamic symbol table section.
7372
7473 const Elf_Shdr *SymbolTableSectionHeaderIndex = nullptr;
7574
8079 const T *getEntry(const Elf_Shdr *Section, uint32_t Entry) const;
8180
8281 const Elf_Shdr *getDotSymtabSec() const { return dot_symtab_sec; }
83 const Elf_Shdr *getDotDynSymSec() const { return DotDynSymSec; }
8482
8583 ErrorOr getStringTable(const Elf_Shdr *Section) const;
8684 ErrorOr getStringTableForSymtab(const Elf_Shdr &Section) const;
383381 return;
384382 DotStrtab = *SymtabOrErr;
385383 } break;
386 case ELF::SHT_DYNSYM: {
387 if (DotDynSymSec) {
388 // More than one .dynsym!
389 EC = object_error::parse_failed;
390 return;
391 }
392 DotDynSymSec = &Sec;
393 break;
394 }
395384 }
396385 }
397386
191191 protected:
192192 ELFFile EF;
193193
194 const Elf_Shdr *DotDynSymSec = nullptr; // Dynamic symbol table section.
195
194196 void moveSymbolNext(DataRefImpl &Symb) const override;
195197 ErrorOr getSymbolName(DataRefImpl Symb) const override;
196198 ErrorOr getSymbolAddress(DataRefImpl Symb) const override;
474476
475477 if (ESym->getType() == ELF::STT_FILE || ESym->getType() == ELF::STT_SECTION ||
476478 ESym == EF.symbol_begin(EF.getDotSymtabSec()) ||
477 ESym == EF.symbol_begin(EF.getDotDynSymSec()))
479 ESym == EF.symbol_begin(DotDynSymSec))
478480 Result |= SymbolRef::SF_FormatSpecific;
479481
480482 if (EF.getHeader()->e_machine == ELF::EM_ARM) {
665667 bool IsDyn = Rel.d.b & 1;
666668 DataRefImpl SymbolData;
667669 if (IsDyn)
668 SymbolData = toDRI(EF.getDotDynSymSec(), symbolIdx);
670 SymbolData = toDRI(DotDynSymSec, symbolIdx);
669671 else
670672 SymbolData = toDRI(EF.getDotSymtabSec(), symbolIdx);
671673 return symbol_iterator(SymbolRef(SymbolData, this));
736738 : ELFObjectFileBase(
737739 getELFType(ELFT::TargetEndianness == support::little, ELFT::Is64Bits),
738740 Object),
739 EF(Data.getBuffer(), EC) {}
741 EF(Data.getBuffer(), EC) {
742 for (const Elf_Shdr &Sec : EF.sections()) {
743 switch (Sec.sh_type) {
744 case ELF::SHT_DYNSYM: {
745 if (DotDynSymSec) {
746 // More than one .dynsym!
747 EC = object_error::parse_failed;
748 return;
749 }
750 DotDynSymSec = &Sec;
751 break;
752 }
753 }
754 }
755 }
740756
741757 template
742758 basic_symbol_iterator ELFObjectFile::symbol_begin_impl() const {
755771
756772 template
757773 elf_symbol_iterator ELFObjectFile::dynamic_symbol_begin() const {
758 DataRefImpl Sym = toDRI(EF.getDotDynSymSec(), 0);
774 DataRefImpl Sym = toDRI(DotDynSymSec, 0);
759775 return symbol_iterator(SymbolRef(Sym, this));
760776 }
761777
762778 template
763779 elf_symbol_iterator ELFObjectFile::dynamic_symbol_end() const {
764 const Elf_Shdr *SymTab = EF.getDotDynSymSec();
780 const Elf_Shdr *SymTab = DotDynSymSec;
765781 DataRefImpl Sym = toDRI(SymTab, SymTab->sh_size / sizeof(Elf_Sym));
766782 return basic_symbol_iterator(SymbolRef(Sym, this));
767783 }
132132 const Elf_Sym *DynSymStart = nullptr;
133133 StringRef SOName;
134134 const Elf_Hash *HashTable = nullptr;
135 const Elf_Shdr *DotDynSymSec = nullptr;
135136
136137 const Elf_Shdr *dot_gnu_version_sec = nullptr; // .gnu.version
137138 const Elf_Shdr *dot_gnu_version_r_sec = nullptr; // .gnu.version_r
163164 public:
164165 std::string getFullSymbolName(const Elf_Sym *Symbol, StringRef StrTable,
165166 bool IsDynamic);
167 const Elf_Shdr *getDotDynSymSec() const { return DotDynSymSec; }
166168 };
167169
168170 template T errorOrDefault(ErrorOr Val, T Default = T()) {
883885 reportError("Multilpe SHT_GNU_verneed");
884886 dot_gnu_version_r_sec = &Sec;
885887 break;
888 case ELF::SHT_DYNSYM:
889 if (DotDynSymSec != nullptr)
890 reportError("Multilpe SHT_DYNSYM");
891 DotDynSymSec = &Sec;
892 break;
886893 }
887894 }
888895 }
11331140 void ELFDumper::printDynamicSymbols() {
11341141 ListScope Group(W, "DynamicSymbols");
11351142
1136 const Elf_Shdr *Symtab = Obj->getDotDynSymSec();
1143 const Elf_Shdr *Symtab = DotDynSymSec;
11371144 ErrorOr StrTableOrErr = Obj->getStringTableForSymtab(*Symtab);
11381145 error(StrTableOrErr.getError());
11391146 StringRef StrTable = *StrTableOrErr;
16421649 return;
16431650 }
16441651
1645 const Elf_Shdr *DynSymSec = Obj->getDotDynSymSec();
1652 const Elf_Shdr *DynSymSec = Dumper->getDotDynSymSec();
16461653 ErrorOr StrTable = Obj->getStringTableForSymtab(*DynSymSec);
16471654 error(StrTable.getError());
16481655 const Elf_Sym *DynSymBegin = Obj->symbol_begin(DynSymSec);