From: Rafael Espindola Date: Mon, 10 Aug 2015 15:12:17 +0000 (+0000) Subject: Don't depend on getDotSymtabSec. It is going away. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d8340dae0cd2de03bd4668050e8f6fdea8201091;p=platform%2Fupstream%2Fllvm.git Don't depend on getDotSymtabSec. It is going away. llvm-svn: 244451 --- diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp index a5f8432..ef4333f 100644 --- a/lld/ELF/InputFiles.cpp +++ b/lld/ELF/InputFiles.cpp @@ -41,6 +41,10 @@ template void elf2::ObjectFile::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(this->getObj(), &Sec); Chunks.push_back(C); @@ -49,7 +53,6 @@ template void elf2::ObjectFile::initializeChunks() { } template void elf2::ObjectFile::initializeSymbols() { - const Elf_Shdr *Symtab = ELFObj->getDotSymtabSec(); ErrorOr StringTableOrErr = ELFObj->getStringTableForSymtab(*Symtab); error(StringTableOrErr.getError()); diff --git a/lld/ELF/InputFiles.h b/lld/ELF/InputFiles.h index 66a8c9d..56313a0 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 *> 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 472e70b..b0b84b9 100644 --- a/lld/lib/ReaderWriter/ELF/ELFFile.cpp +++ b/lld/lib/ReaderWriter/ELF/ELFFile.cpp @@ -125,6 +125,11 @@ std::error_code ELFFile::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 std::error_code ELFFile::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 strTableOrErr = _objFile->getStringTableForSymtab(*symtab); + ErrorOr 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 section = _objFile->getSection(&*SymI); + ErrorOr section = _objFile->getSection(SymI); if (std::error_code ec = section.getError()) return ec; @@ -309,11 +314,10 @@ template std::error_code ELFFile::createAtoms() { ELFDefinedAtom *previousAtom = nullptr; ELFReference *anonFollowedBy = nullptr; - const Elf_Shdr *symtab = _objFile->getDotSymtabSec(); - if (!symtab) + if (!_symtab) continue; ErrorOr 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::updateReferenceForMergeStringAccess(ELFReference *ref, } template void ELFFile::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 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 999ed68..16c3edd 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 > _objFile; + const Elf_Shdr *_symtab = nullptr; /// \brief _relocationAddendReferences and _relocationReferences contain the /// list of relocations references. In ELF, if a section named, ".text" has