From 5871bf30ac2fba2f9e76cf18cbcfd059fc4224d0 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Thu, 23 Jul 2015 13:41:25 +0000 Subject: [PATCH] Use the getSymbol with an explicit symbol table. NFC. llvm-svn: 243014 --- lld/lib/ReaderWriter/ELF/ELFFile.cpp | 11 +++++++---- lld/lib/ReaderWriter/ELF/ELFFile.h | 5 ++--- lld/lib/ReaderWriter/ELF/Mips/MipsELFFile.cpp | 23 ++++++++++++++--------- lld/lib/ReaderWriter/ELF/Mips/MipsELFFile.h | 6 +++--- 4 files changed, 26 insertions(+), 19 deletions(-) diff --git a/lld/lib/ReaderWriter/ELF/ELFFile.cpp b/lld/lib/ReaderWriter/ELF/ELFFile.cpp index 6475a11..84bdf66 100644 --- a/lld/lib/ReaderWriter/ELF/ELFFile.cpp +++ b/lld/lib/ReaderWriter/ELF/ELFFile.cpp @@ -149,7 +149,7 @@ std::error_code ELFFile::createAtomizableSections() { auto sHdr = *sHdrOrErr; auto ri = _objFile->rel_begin(§ion); auto re = _objFile->rel_end(§ion); - _relocationReferences[sHdr] = make_range(ri, re); + _relocationReferences[sHdr] = §ion; totalRelocs += std::distance(ri, re); } else { auto sectionName = _objFile->getSectionName(§ion); @@ -501,10 +501,10 @@ std::error_code ELFFile::handleSectionGroup( return ec; sectionNames.push_back(*sectionName); } - const Elf_Sym *symbol = _objFile->getSymbol(section->sh_info); ErrorOr symtab = _objFile->getSection(section->sh_link); if (std::error_code ec = symtab.getError()) return ec; + const Elf_Sym *symbol = _objFile->getSymbol(*symtab, section->sh_info); ErrorOr strtab_sec = _objFile->getSection((*symtab)->sh_link); if (std::error_code ec = strtab_sec.getError()) @@ -616,7 +616,8 @@ template void ELFFile::createRelocationReferences(const Elf_Sym *symbol, ArrayRef symContent, ArrayRef secContent, - range rels) { + const Elf_Shdr *relSec) { + auto rels = _objFile->rels(relSec); bool isMips64EL = _objFile->isMips64EL(); const auto symValue = getSymbolValue(symbol); for (const auto &rel : rels) { @@ -662,10 +663,12 @@ 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(ri->targetSymbolIndex()); + const Elf_Sym *symbol = + _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 3543ca0..999ed68 100644 --- a/lld/lib/ReaderWriter/ELF/ELFFile.h +++ b/lld/lib/ReaderWriter/ELF/ELFFile.h @@ -141,7 +141,7 @@ protected: virtual void createRelocationReferences(const Elf_Sym *symbol, ArrayRef symContent, ArrayRef secContent, - range rels); + const Elf_Shdr *relSec); /// \brief After all the Atoms and References are created, update each /// Reference's target with the Atom pointer it refers to. @@ -328,8 +328,7 @@ protected: std::unordered_map> _relocationAddendReferences; MergedSectionMapT _mergedSectionMap; - std::unordered_map> - _relocationReferences; + std::unordered_map _relocationReferences; std::vector *> _references; llvm::DenseMap _symbolToAtomMapping; llvm::DenseMap *, const Elf_Sym *> diff --git a/lld/lib/ReaderWriter/ELF/Mips/MipsELFFile.cpp b/lld/lib/ReaderWriter/ELF/Mips/MipsELFFile.cpp index 85c6496..fef4d82 100644 --- a/lld/lib/ReaderWriter/ELF/Mips/MipsELFFile.cpp +++ b/lld/lib/ReaderWriter/ELF/Mips/MipsELFFile.cpp @@ -236,9 +236,12 @@ void MipsELFFile::createRelocationReferences( } template -void MipsELFFile::createRelocationReferences( - const Elf_Sym *symbol, ArrayRef symContent, - ArrayRef secContent, range rels) { +void MipsELFFile::createRelocationReferences(const Elf_Sym *symbol, + ArrayRef symContent, + ArrayRef secContent, + const Elf_Shdr *relSec) { + const Elf_Shdr *symtab = *this->_objFile->getSection(relSec->sh_link); + auto rels = this->_objFile->rels(relSec); const auto value = this->getSymbolValue(symbol); for (const Elf_Rel *rit = rels.begin(), *eit = rels.end(); rit != eit; ++rit) { @@ -250,7 +253,7 @@ void MipsELFFile::createRelocationReferences( this->_references.push_back(r); auto addend = readAddend(*rit, secContent); - auto pairRelType = getPairRelocation(*rit); + auto pairRelType = getPairRelocation(symtab, *rit); if (pairRelType != llvm::ELF::R_MIPS_NONE) { addend <<= 16; auto mit = findMatchingRelocation(pairRelType, rit, eit); @@ -279,20 +282,21 @@ MipsELFFile::readAddend(const Elf_Rel &ri, } template -uint32_t MipsELFFile::getPairRelocation(const Elf_Rel &rel) const { +uint32_t MipsELFFile::getPairRelocation(const Elf_Shdr *symtab, + const Elf_Rel &rel) const { switch (getPrimaryType(rel)) { case llvm::ELF::R_MIPS_HI16: return llvm::ELF::R_MIPS_LO16; case llvm::ELF::R_MIPS_PCHI16: return llvm::ELF::R_MIPS_PCLO16; case llvm::ELF::R_MIPS_GOT16: - if (isLocalBinding(rel)) + if (isLocalBinding(symtab, rel)) return llvm::ELF::R_MIPS_LO16; break; case llvm::ELF::R_MICROMIPS_HI16: return llvm::ELF::R_MICROMIPS_LO16; case llvm::ELF::R_MICROMIPS_GOT16: - if (isLocalBinding(rel)) + if (isLocalBinding(symtab, rel)) return llvm::ELF::R_MICROMIPS_LO16; break; default: @@ -315,8 +319,9 @@ MipsELFFile::findMatchingRelocation(uint32_t pairRelType, } template -bool MipsELFFile::isLocalBinding(const Elf_Rel &rel) const { - return this->_objFile->getSymbol(rel.getSymbol(isMips64EL())) +bool MipsELFFile::isLocalBinding(const Elf_Shdr *symtab, + const Elf_Rel &rel) const { + return this->_objFile->getSymbol(symtab, rel.getSymbol(isMips64EL())) ->getBinding() == llvm::ELF::STB_LOCAL; } diff --git a/lld/lib/ReaderWriter/ELF/Mips/MipsELFFile.h b/lld/lib/ReaderWriter/ELF/Mips/MipsELFFile.h index 1865a47..934934b 100644 --- a/lld/lib/ReaderWriter/ELF/Mips/MipsELFFile.h +++ b/lld/lib/ReaderWriter/ELF/Mips/MipsELFFile.h @@ -93,7 +93,7 @@ private: void createRelocationReferences(const Elf_Sym *symbol, ArrayRef symContent, ArrayRef secContent, - range rels) override; + const Elf_Shdr *RelSec) override; const Elf_Shdr *findSectionByType(uint64_t type) const; const Elf_Shdr *findSectionByFlags(uint64_t flags) const; @@ -111,13 +111,13 @@ private: Reference::Addend readAddend(const Elf_Rel &ri, const ArrayRef content) const; - uint32_t getPairRelocation(const Elf_Rel &rel) const; + uint32_t getPairRelocation(const Elf_Shdr *Symtab, const Elf_Rel &rel) const; const Elf_Rel *findMatchingRelocation(uint32_t pairRelType, const Elf_Rel *rit, const Elf_Rel *eit) const; - bool isLocalBinding(const Elf_Rel &rel) const; + bool isLocalBinding(const Elf_Shdr *Symtab, const Elf_Rel &rel) const; }; } // elf -- 2.7.4