diff options
-rw-r--r-- | lld/lib/ReaderWriter/ELF/ELFFile.cpp | 11 | ||||
-rw-r--r-- | lld/lib/ReaderWriter/ELF/ELFFile.h | 5 | ||||
-rw-r--r-- | lld/lib/ReaderWriter/ELF/Mips/MipsELFFile.cpp | 23 | ||||
-rw-r--r-- | 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 6475a11a204..84bdf66f773 100644 --- a/lld/lib/ReaderWriter/ELF/ELFFile.cpp +++ b/lld/lib/ReaderWriter/ELF/ELFFile.cpp @@ -149,7 +149,7 @@ std::error_code ELFFile<ELFT>::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<ELFT>::handleSectionGroup( return ec; sectionNames.push_back(*sectionName); } - const Elf_Sym *symbol = _objFile->getSymbol(section->sh_info); ErrorOr<const Elf_Shdr *> 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<const Elf_Shdr *> strtab_sec = _objFile->getSection((*symtab)->sh_link); if (std::error_code ec = strtab_sec.getError()) @@ -616,7 +616,8 @@ template <class ELFT> void ELFFile<ELFT>::createRelocationReferences(const Elf_Sym *symbol, ArrayRef<uint8_t> symContent, ArrayRef<uint8_t> secContent, - range<const Elf_Rel *> 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<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(ri->targetSymbolIndex()); + const Elf_Sym *symbol = + _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 3543ca066a8..999ed686ec8 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<uint8_t> symContent, ArrayRef<uint8_t> secContent, - range<const Elf_Rel *> 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<const Elf_Shdr *, range<const Elf_Rela *>> _relocationAddendReferences; MergedSectionMapT _mergedSectionMap; - std::unordered_map<const Elf_Shdr *, range<const Elf_Rel *>> - _relocationReferences; + std::unordered_map<const Elf_Shdr *, const Elf_Shdr *> _relocationReferences; std::vector<ELFReference<ELFT> *> _references; llvm::DenseMap<const Elf_Sym *, Atom *> _symbolToAtomMapping; llvm::DenseMap<const ELFReference<ELFT> *, const Elf_Sym *> diff --git a/lld/lib/ReaderWriter/ELF/Mips/MipsELFFile.cpp b/lld/lib/ReaderWriter/ELF/Mips/MipsELFFile.cpp index 85c64962718..fef4d82d66c 100644 --- a/lld/lib/ReaderWriter/ELF/Mips/MipsELFFile.cpp +++ b/lld/lib/ReaderWriter/ELF/Mips/MipsELFFile.cpp @@ -236,9 +236,12 @@ void MipsELFFile<ELFT>::createRelocationReferences( } template <class ELFT> -void MipsELFFile<ELFT>::createRelocationReferences( - const Elf_Sym *symbol, ArrayRef<uint8_t> symContent, - ArrayRef<uint8_t> secContent, range<const Elf_Rel *> rels) { +void MipsELFFile<ELFT>::createRelocationReferences(const Elf_Sym *symbol, + ArrayRef<uint8_t> symContent, + ArrayRef<uint8_t> 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<ELFT>::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<ELFT>::readAddend(const Elf_Rel &ri, } template <class ELFT> -uint32_t MipsELFFile<ELFT>::getPairRelocation(const Elf_Rel &rel) const { +uint32_t MipsELFFile<ELFT>::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<ELFT>::findMatchingRelocation(uint32_t pairRelType, } template <class ELFT> -bool MipsELFFile<ELFT>::isLocalBinding(const Elf_Rel &rel) const { - return this->_objFile->getSymbol(rel.getSymbol(isMips64EL<ELFT>())) +bool MipsELFFile<ELFT>::isLocalBinding(const Elf_Shdr *symtab, + const Elf_Rel &rel) const { + return this->_objFile->getSymbol(symtab, rel.getSymbol(isMips64EL<ELFT>())) ->getBinding() == llvm::ELF::STB_LOCAL; } diff --git a/lld/lib/ReaderWriter/ELF/Mips/MipsELFFile.h b/lld/lib/ReaderWriter/ELF/Mips/MipsELFFile.h index 1865a47a15f..934934b539c 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<uint8_t> symContent, ArrayRef<uint8_t> secContent, - range<const Elf_Rel *> 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<uint8_t> 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 |