From: Rafael Espindola Date: Mon, 10 Aug 2015 20:25:04 +0000 (+0000) Subject: Delete getDotSymtabSec. X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=4d79d2fcbfe2eb8110a118bc88dc06660f169cb1;p=oota-llvm.git Delete getDotSymtabSec. Another step in avoiding iterating over all sections in the ELFFile constructor. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@244496 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/Object/ELF.h b/include/llvm/Object/ELF.h index ac0ab307060..f290e563abb 100644 --- a/include/llvm/Object/ELF.h +++ b/include/llvm/Object/ELF.h @@ -78,8 +78,6 @@ public: template const T *getEntry(const Elf_Shdr *Section, uint32_t Entry) const; - const Elf_Shdr *getDotSymtabSec() const { return dot_symtab_sec; } - ErrorOr getStringTable(const Elf_Shdr *Section) const; ErrorOr getStringTableForSymtab(const Elf_Shdr &Section) const; diff --git a/include/llvm/Object/ELFObjectFile.h b/include/llvm/Object/ELFObjectFile.h index ddedf04ee07..d345c96a404 100644 --- a/include/llvm/Object/ELFObjectFile.h +++ b/include/llvm/Object/ELFObjectFile.h @@ -193,6 +193,7 @@ protected: ELFFile EF; const Elf_Shdr *DotDynSymSec = nullptr; // Dynamic symbol table section. + const Elf_Shdr *DotSymtabSec = nullptr; // Symbol table section. void moveSymbolNext(DataRefImpl &Symb) const override; ErrorOr getSymbolName(DataRefImpl Symb) const override; @@ -477,7 +478,7 @@ uint32_t ELFObjectFile::getSymbolFlags(DataRefImpl Sym) const { Result |= SymbolRef::SF_Absolute; if (ESym->getType() == ELF::STT_FILE || ESym->getType() == ELF::STT_SECTION || - ESym == EF.symbol_begin(EF.getDotSymtabSec()) || + ESym == EF.symbol_begin(DotSymtabSec) || ESym == EF.symbol_begin(DotDynSymSec)) Result |= SymbolRef::SF_FormatSpecific; @@ -669,7 +670,7 @@ ELFObjectFile::getRelocationSymbol(DataRefImpl Rel) const { if (IsDyn) SymbolData = toDRI(DotDynSymSec, symbolIdx); else - SymbolData = toDRI(EF.getDotSymtabSec(), symbolIdx); + SymbolData = toDRI(DotSymtabSec, symbolIdx); return symbol_iterator(SymbolRef(SymbolData, this)); } @@ -746,19 +747,28 @@ ELFObjectFile::ELFObjectFile(MemoryBufferRef Object, std::error_code &EC) DotDynSymSec = &Sec; break; } + case ELF::SHT_SYMTAB: { + if (DotSymtabSec) { + // More than one .dynsym! + EC = object_error::parse_failed; + return; + } + DotSymtabSec = &Sec; + break; + } } } } template basic_symbol_iterator ELFObjectFile::symbol_begin_impl() const { - DataRefImpl Sym = toDRI(EF.getDotSymtabSec(), 0); + DataRefImpl Sym = toDRI(DotSymtabSec, 0); return basic_symbol_iterator(SymbolRef(Sym, this)); } template basic_symbol_iterator ELFObjectFile::symbol_end_impl() const { - const Elf_Shdr *SymTab = EF.getDotSymtabSec(); + const Elf_Shdr *SymTab = DotSymtabSec; if (!SymTab) return symbol_begin_impl(); DataRefImpl Sym = toDRI(SymTab, SymTab->sh_size / sizeof(Elf_Sym)); diff --git a/tools/llvm-readobj/ARMEHABIPrinter.h b/tools/llvm-readobj/ARMEHABIPrinter.h index 7b2c79136a5..85b2f2906ca 100644 --- a/tools/llvm-readobj/ARMEHABIPrinter.h +++ b/tools/llvm-readobj/ARMEHABIPrinter.h @@ -305,13 +305,14 @@ void OpcodeDecoder::Decode(const uint8_t *Opcodes, off_t Offset, size_t Length) template class PrinterContext { - StreamWriter &SW; - const object::ELFFile *ELF; - typedef typename object::ELFFile::Elf_Sym Elf_Sym; typedef typename object::ELFFile::Elf_Shdr Elf_Shdr; typedef typename object::ELFFile::Elf_Rel Elf_Rel; + StreamWriter &SW; + const object::ELFFile *ELF; + const Elf_Shdr *Symtab; + static const size_t IndexTableEntrySize; static uint64_t PREL31(uint32_t Address, uint32_t Place) { @@ -331,8 +332,9 @@ class PrinterContext { void PrintOpcodes(const uint8_t *Entry, size_t Length, off_t Offset) const; public: - PrinterContext(StreamWriter &Writer, const object::ELFFile *File) - : SW(Writer), ELF(File) {} + PrinterContext(StreamWriter &SW, const object::ELFFile *ELF, + const Elf_Shdr *Symtab) + : SW(SW), ELF(ELF), Symtab(Symtab) {} void PrintUnwindInformation() const; }; @@ -344,12 +346,11 @@ template ErrorOr PrinterContext::FunctionAtAddress(unsigned Section, uint64_t Address) const { - const Elf_Shdr *Symtab = ELF->getDotSymtabSec(); ErrorOr StrTableOrErr = ELF->getStringTableForSymtab(*Symtab); error(StrTableOrErr.getError()); StringRef StrTable = *StrTableOrErr; - for (const Elf_Sym &Sym : ELF->symbols(ELF->getDotSymtabSec())) + for (const Elf_Sym &Sym : ELF->symbols(Symtab)) if (Sym.st_shndx == Section && Sym.st_value == Address && Sym.getType() == ELF::STT_FUNC) return Sym.getName(StrTable); diff --git a/tools/llvm-readobj/ELFDumper.cpp b/tools/llvm-readobj/ELFDumper.cpp index 05fef7262ff..8fab52e79dd 100644 --- a/tools/llvm-readobj/ELFDumper.cpp +++ b/tools/llvm-readobj/ELFDumper.cpp @@ -134,6 +134,7 @@ private: StringRef SOName; const Elf_Hash *HashTable = nullptr; const Elf_Shdr *DotDynSymSec = nullptr; + const Elf_Shdr *DotSymtabSec = nullptr; const Elf_Shdr *dot_gnu_version_sec = nullptr; // .gnu.version const Elf_Shdr *dot_gnu_version_r_sec = nullptr; // .gnu.version_r @@ -383,7 +384,7 @@ getSectionNameIndex(const ELFO &Obj, const typename ELFO::Elf_Sym *Symbol, SectionName = "Reserved"; else { if (SectionIndex == SHN_XINDEX) - SectionIndex = Obj.getExtendedSymbolTableIndex(&*Symbol); + SectionIndex = Obj.getExtendedSymbolTableIndex(Symbol); ErrorOr Sec = Obj.getSection(SectionIndex); error(Sec.getError()); SectionName = errorOrDefault(Obj.getSectionName(*Sec)); @@ -891,6 +892,11 @@ ELFDumper::ELFDumper(const ELFFile *Obj, StreamWriter &Writer) reportError("Multilpe SHT_DYNSYM"); DotDynSymSec = &Sec; break; + case ELF::SHT_SYMTAB: + if (DotSymtabSec != nullptr) + reportError("Multilpe SHT_SYMTAB"); + DotSymtabSec = &Sec; + break; } } } @@ -997,7 +1003,7 @@ void ELFDumper::printSections() { if (opts::SectionSymbols) { ListScope D(W, "Symbols"); - const Elf_Shdr *Symtab = Obj->getDotSymtabSec(); + const Elf_Shdr *Symtab = DotSymtabSec; ErrorOr StrTableOrErr = Obj->getStringTableForSymtab(*Symtab); error(StrTableOrErr.getError()); StringRef StrTable = *StrTableOrErr; @@ -1129,7 +1135,7 @@ template void ELFDumper::printSymbols() { ListScope Group(W, "Symbols"); - const Elf_Shdr *Symtab = Obj->getDotSymtabSec(); + const Elf_Shdr *Symtab = DotSymtabSec; ErrorOr StrTableOrErr = Obj->getStringTableForSymtab(*Symtab); error(StrTableOrErr.getError()); StringRef StrTable = *StrTableOrErr; @@ -1412,7 +1418,8 @@ namespace { template <> void ELFDumper>::printUnwindInfo() { const unsigned Machine = Obj->getHeader()->e_machine; if (Machine == EM_ARM) { - ARM::EHABI::PrinterContext> Ctx(W, Obj); + ARM::EHABI::PrinterContext> Ctx( + W, Obj, DotSymtabSec); return Ctx.PrintUnwindInformation(); } W.startLine() << "UnwindInfo not implemented.\n";