diff options
-rw-r--r-- | lld/ELF/InputFiles.cpp | 5 | ||||
-rw-r--r-- | lld/ELF/InputFiles.h | 2 | ||||
-rw-r--r-- | lld/lib/ReaderWriter/ELF/ELFFile.cpp | 25 | ||||
-rw-r--r-- | lld/lib/ReaderWriter/ELF/ELFFile.h | 1 |
4 files changed, 21 insertions, 12 deletions
diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp index a5f84320ca3..ef4333ff9d8 100644 --- a/lld/ELF/InputFiles.cpp +++ b/lld/ELF/InputFiles.cpp @@ -41,6 +41,10 @@ template <class ELFT> void elf2::ObjectFile<ELFT>::initializeChunks() { uint64_t Size = ELFObj->getNumSections(); Chunks.reserve(Size); for (const Elf_Shdr &Sec : ELFObj->sections()) { + if (Sec.sh_type == SHT_SYMTAB) { + Symtab = &Sec; + continue; + } if (Sec.sh_flags & SHF_ALLOC) { auto *C = new (Alloc) SectionChunk<ELFT>(this->getObj(), &Sec); Chunks.push_back(C); @@ -49,7 +53,6 @@ template <class ELFT> void elf2::ObjectFile<ELFT>::initializeChunks() { } template <class ELFT> void elf2::ObjectFile<ELFT>::initializeSymbols() { - const Elf_Shdr *Symtab = ELFObj->getDotSymtabSec(); ErrorOr<StringRef> StringTableOrErr = ELFObj->getStringTableForSymtab(*Symtab); error(StringTableOrErr.getError()); diff --git a/lld/ELF/InputFiles.h b/lld/ELF/InputFiles.h index 66a8c9d5b48..56313a084a3 100644 --- a/lld/ELF/InputFiles.h +++ b/lld/ELF/InputFiles.h @@ -100,6 +100,8 @@ private: // List of all chunks defined by this file. std::vector<SectionChunk<ELFT> *> Chunks; + + const Elf_Shdr *Symtab = nullptr; }; } // namespace elf2 diff --git a/lld/lib/ReaderWriter/ELF/ELFFile.cpp b/lld/lib/ReaderWriter/ELF/ELFFile.cpp index 472e70b7e86..b0b84b9261f 100644 --- a/lld/lib/ReaderWriter/ELF/ELFFile.cpp +++ b/lld/lib/ReaderWriter/ELF/ELFFile.cpp @@ -125,6 +125,11 @@ std::error_code ELFFile<ELFT>::createAtomizableSections() { // Record the number of relocs to guess at preallocating the buffer. uint64_t totalRelocs = 0; for (const Elf_Shdr §ion : _objFile->sections()) { + if (section.sh_type == llvm::ELF::SHT_SYMTAB) { + _symtab = §ion; + continue; + } + if (isIgnoredSection(§ion)) continue; @@ -208,22 +213,22 @@ template <class ELFT> std::error_code ELFFile<ELFT>::createSymbolsFromAtomizableSections() { // Increment over all the symbols collecting atoms and symbol names for // later use. - const Elf_Shdr *symtab = _objFile->getDotSymtabSec(); - if (!symtab) + if (!_symtab) return std::error_code(); - ErrorOr<StringRef> strTableOrErr = _objFile->getStringTableForSymtab(*symtab); + ErrorOr<StringRef> strTableOrErr = + _objFile->getStringTableForSymtab(*_symtab); if (std::error_code ec = strTableOrErr.getError()) return ec; StringRef strTable = *strTableOrErr; - auto SymI = _objFile->symbol_begin(symtab), - SymE = _objFile->symbol_end(symtab); + auto SymI = _objFile->symbol_begin(_symtab), + SymE = _objFile->symbol_end(_symtab); // Skip over dummy sym. ++SymI; for (; SymI != SymE; ++SymI) { - ErrorOr<const Elf_Shdr *> section = _objFile->getSection(&*SymI); + ErrorOr<const Elf_Shdr *> section = _objFile->getSection(SymI); if (std::error_code ec = section.getError()) return ec; @@ -309,11 +314,10 @@ template <class ELFT> std::error_code ELFFile<ELFT>::createAtoms() { ELFDefinedAtom<ELFT> *previousAtom = nullptr; ELFReference<ELFT> *anonFollowedBy = nullptr; - const Elf_Shdr *symtab = _objFile->getDotSymtabSec(); - if (!symtab) + if (!_symtab) continue; ErrorOr<StringRef> strTableOrErr = - _objFile->getStringTableForSymtab(*symtab); + _objFile->getStringTableForSymtab(*_symtab); if (std::error_code ec = strTableOrErr.getError()) return ec; StringRef strTable = *strTableOrErr; @@ -664,12 +668,11 @@ void ELFFile<ELFT>::updateReferenceForMergeStringAccess(ELFReference<ELFT> *ref, } template <class ELFT> void ELFFile<ELFT>::updateReferences() { - const Elf_Shdr *symtab = _objFile->getDotSymtabSec(); for (auto &ri : _references) { if (ri->kindNamespace() != Reference::KindNamespace::ELF) continue; const Elf_Sym *symbol = - _objFile->getSymbol(symtab, ri->targetSymbolIndex()); + _objFile->getSymbol(_symtab, ri->targetSymbolIndex()); ErrorOr<const Elf_Shdr *> shdr = _objFile->getSection(symbol); // If the atom is not in mergeable string section, the target atom is diff --git a/lld/lib/ReaderWriter/ELF/ELFFile.h b/lld/lib/ReaderWriter/ELF/ELFFile.h index 999ed686ec8..16c3edde98b 100644 --- a/lld/lib/ReaderWriter/ELF/ELFFile.h +++ b/lld/lib/ReaderWriter/ELF/ELFFile.h @@ -320,6 +320,7 @@ protected: llvm::BumpPtrAllocator _readerStorage; std::unique_ptr<llvm::object::ELFFile<ELFT> > _objFile; + const Elf_Shdr *_symtab = nullptr; /// \brief _relocationAddendReferences and _relocationReferences contain the /// list of relocations references. In ELF, if a section named, ".text" has |