From faa8bfdd1aa8bbaa02bd6e2adb8324180539af58 Mon Sep 17 00:00:00 2001 From: Simon Atanasyan Date: Sun, 31 May 2015 20:37:22 +0000 Subject: [PATCH] [Mips] Add a couple of MipsAbiInfoHandler functions to check linked code type No functional changes. llvm-svn: 238689 --- .../ReaderWriter/ELF/Mips/MipsAbiInfoHandler.cpp | 10 ++++++ lld/lib/ReaderWriter/ELF/Mips/MipsAbiInfoHandler.h | 2 ++ .../ReaderWriter/ELF/Mips/MipsRelocationPass.cpp | 39 ++++++++++++---------- 3 files changed, 34 insertions(+), 17 deletions(-) diff --git a/lld/lib/ReaderWriter/ELF/Mips/MipsAbiInfoHandler.cpp b/lld/lib/ReaderWriter/ELF/Mips/MipsAbiInfoHandler.cpp index 922f670..fa14ab3 100644 --- a/lld/lib/ReaderWriter/ELF/Mips/MipsAbiInfoHandler.cpp +++ b/lld/lib/ReaderWriter/ELF/Mips/MipsAbiInfoHandler.cpp @@ -424,6 +424,16 @@ static uint32_t selectFpAbiFlag(uint32_t oldFp, uint32_t newFp) { namespace lld { namespace elf { +template bool MipsAbiInfoHandler::isMicroMips() const { + assert(_abiFlags.hasValue()); + return _abiFlags->_ases & AFL_ASE_MICROMIPS; +} + +template bool MipsAbiInfoHandler::isMipsR6() const { + assert(_abiFlags.hasValue()); + return _abiFlags->_isa == Arch32r6 || _abiFlags->_isa == Arch64r6; +} + template uint32_t MipsAbiInfoHandler::getFlags() const { std::lock_guard lock(_mutex); uint32_t flags = 0; diff --git a/lld/lib/ReaderWriter/ELF/Mips/MipsAbiInfoHandler.h b/lld/lib/ReaderWriter/ELF/Mips/MipsAbiInfoHandler.h index 149d6bd..b755b71 100644 --- a/lld/lib/ReaderWriter/ELF/Mips/MipsAbiInfoHandler.h +++ b/lld/lib/ReaderWriter/ELF/Mips/MipsAbiInfoHandler.h @@ -44,6 +44,8 @@ public: MipsAbiInfoHandler() = default; bool hasMipsAbiSection() const { return _hasAbiSection; } + bool isMicroMips() const; + bool isMipsR6() const; uint32_t getFlags() const; llvm::Optional getRegistersMask() const; diff --git a/lld/lib/ReaderWriter/ELF/Mips/MipsRelocationPass.cpp b/lld/lib/ReaderWriter/ELF/Mips/MipsRelocationPass.cpp index 0b54a89..31dc15f 100644 --- a/lld/lib/ReaderWriter/ELF/Mips/MipsRelocationPass.cpp +++ b/lld/lib/ReaderWriter/ELF/Mips/MipsRelocationPass.cpp @@ -311,12 +311,6 @@ private: /// \brief Owner of all the Atoms created by this pass. RelocationPassFile _file; - /// \brief Linked files contain MIPS R6 code. - bool _isMipsR6 = false; - - /// \brief Linked files contain microMIPS code. - bool _isMicroMips = false; - /// \brief Map Atoms and addend to local GOT entries. typedef std::pair LocalGotMapKeyT; llvm::DenseMap _gotLocalMap; @@ -418,6 +412,11 @@ private: bool mightBeDynamic(const MipsELFDefinedAtom &atom, Reference::KindValue refKind) const; bool hasPLTEntry(const Atom *atom) const; + + /// \brief Linked files contain microMIPS code. + bool isMicroMips(); + /// \brief Linked files contain MIPS R6 code. + bool isMipsR6(); }; template @@ -430,14 +429,6 @@ RelocationPass::RelocationPass(MipsLinkingContext &ctx) template void RelocationPass::perform(std::unique_ptr &mf) { - auto &handler = - static_cast &>(this->_ctx.getTargetHandler()); - - uint32_t elfFlags = handler.getAbiInfoHandler().getFlags(); - _isMicroMips = elfFlags & EF_MIPS_MICROMIPS; - _isMipsR6 = (elfFlags & EF_MIPS_ARCH) == EF_MIPS_ARCH_32R6 || - (elfFlags & EF_MIPS_ARCH) == EF_MIPS_ARCH_64R6; - for (const auto &atom : mf->defined()) for (const auto &ref : *atom) collectReferenceInfo(*cast>(atom), @@ -709,6 +700,20 @@ bool RelocationPass::hasPLTEntry(const Atom *atom) const { return _pltRegMap.count(atom) || _pltMicroMap.count(atom); } +template bool RelocationPass::isMicroMips() { + TargetHandler &handler = this->_ctx.getTargetHandler(); + return static_cast &>(handler) + .getAbiInfoHandler() + .isMicroMips(); +} + +template bool RelocationPass::isMipsR6() { + TargetHandler &handler = this->_ctx.getTargetHandler(); + return static_cast &>(handler) + .getAbiInfoHandler() + .isMipsR6(); +} + template bool RelocationPass::requirePLTEntry(const Atom *a) const { if (!_hasStaticRelocations.count(a)) @@ -761,7 +766,7 @@ const LA25Atom *RelocationPass::getLA25Entry(const Atom *target, template const PLTAtom *RelocationPass::getPLTEntry(const Atom *a) { // If file contains microMIPS code try to reuse compressed PLT entry... - if (_isMicroMips) { + if (isMicroMips()) { auto microPLT = _pltMicroMap.find(a); if (microPLT != _pltMicroMap.end()) return microPLT->second; @@ -773,7 +778,7 @@ const PLTAtom *RelocationPass::getPLTEntry(const Atom *a) { return regPLT->second; // ... and finally prefer to create new compressed PLT entry. - return _isMicroMips ? getPLTMicroEntry(a) : getPLTRegEntry(a); + return isMicroMips() ? getPLTMicroEntry(a) : getPLTRegEntry(a); } template @@ -1010,7 +1015,7 @@ const PLTAtom *RelocationPass::getPLTRegEntry(const Atom *a) { if (plt != _pltRegMap.end()) return plt->second; - PLTAAtom *pa = _isMipsR6 + PLTAAtom *pa = isMipsR6() ? new (_file._alloc) PLTR6Atom(getGOTPLTEntry(a), _file) : new (_file._alloc) PLTAAtom(getGOTPLTEntry(a), _file); _pltRegMap[a] = pa; -- 2.7.4