From 7b3dd1789c52a24b16804e1b1981adde6e5aa43e Mon Sep 17 00:00:00 2001 From: Simon Atanasyan Date: Wed, 28 May 2014 04:10:01 +0000 Subject: [PATCH] [Mips] Do not mix _gp and _gp_disp symbols in relocation handling. No functional changes. llvm-svn: 209709 --- .../ELF/Mips/MipsRelocationHandler.cpp | 9 ++++---- lld/lib/ReaderWriter/ELF/Mips/MipsTargetHandler.h | 27 ++++++++++++++-------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/lld/lib/ReaderWriter/ELF/Mips/MipsRelocationHandler.cpp b/lld/lib/ReaderWriter/ELF/Mips/MipsRelocationHandler.cpp index 73d47c7..ce92041 100644 --- a/lld/lib/ReaderWriter/ELF/Mips/MipsRelocationHandler.cpp +++ b/lld/lib/ReaderWriter/ELF/Mips/MipsRelocationHandler.cpp @@ -129,6 +129,9 @@ error_code MipsTargetRelocationHandler::applyRelocation( AtomLayout *gpAtom = _mipsTargetLayout.getGP(); uint64_t gpAddr = gpAtom ? gpAtom->_virtualAddr : 0; + AtomLayout *gpDispAtom = _mipsTargetLayout.getGPDisp(); + bool isGpDisp = gpDispAtom && ref.target() == gpDispAtom->_atom; + uint8_t *atomContent = buf.getBufferStart() + atom._fileOffset; uint8_t *location = atomContent + ref.offsetInAtom(); uint64_t targetVAddress = writer.addressOfAtom(ref.target()); @@ -144,12 +147,10 @@ error_code MipsTargetRelocationHandler::applyRelocation( reloc26loc(location, relocVAddress, targetVAddress, ref.addend()); break; case R_MIPS_HI16: - relocHi16(location, relocVAddress, targetVAddress, ref.addend(), - ref.target() == gpAtom->_atom); + relocHi16(location, relocVAddress, targetVAddress, ref.addend(), isGpDisp); break; case R_MIPS_LO16: - relocLo16(location, relocVAddress, targetVAddress, ref.addend(), - ref.target() == gpAtom->_atom); + relocLo16(location, relocVAddress, targetVAddress, ref.addend(), isGpDisp); break; case R_MIPS_GOT16: relocGOT(location, relocVAddress, targetVAddress, ref.addend(), gpAddr); diff --git a/lld/lib/ReaderWriter/ELF/Mips/MipsTargetHandler.h b/lld/lib/ReaderWriter/ELF/Mips/MipsTargetHandler.h index 1e8253a..b2eb496 100644 --- a/lld/lib/ReaderWriter/ELF/Mips/MipsTargetHandler.h +++ b/lld/lib/ReaderWriter/ELF/Mips/MipsTargetHandler.h @@ -26,8 +26,7 @@ public: MipsTargetLayout(const MipsLinkingContext &ctx) : TargetLayout(ctx), _gotSection(new (_alloc) MipsGOTSection(ctx)), - _pltSection(new (_alloc) MipsPLTSection(ctx)), - _cachedGP(false) {} + _pltSection(new (_alloc) MipsPLTSection(ctx)) {} const MipsGOTSection &getGOTSection() const { return *_gotSection; } const MipsPLTSection &getPLTSection() const { return *_pltSection; } @@ -47,22 +46,30 @@ public: /// \brief GP offset relative to .got section. uint64_t getGPOffset() const { return 0x7FF0; } - /// \brief Get the cached value of the GP atom. + /// \brief Get '_gp' symbol atom layout. AtomLayout *getGP() { - if (!_cachedGP) { - auto gpAtomIter = this->findAbsoluteAtom("_gp_disp"); - _gp = *(gpAtomIter); - _cachedGP = true; + if (!_gpAtom.hasValue()) { + auto atom = this->findAbsoluteAtom("_gp"); + _gpAtom = atom != this->absoluteAtoms().end() ? *atom : nullptr; } - return _gp; + return *_gpAtom; + } + + /// \brief Get '_gp_disp' symbol atom layout. + AtomLayout *getGPDisp() { + if (!_gpDispAtom.hasValue()) { + auto atom = this->findAbsoluteAtom("_gp_disp"); + _gpDispAtom = atom != this->absoluteAtoms().end() ? *atom : nullptr; + } + return *_gpDispAtom; } private: llvm::BumpPtrAllocator _alloc; MipsGOTSection *_gotSection; MipsPLTSection *_pltSection; - AtomLayout *_gp; - bool _cachedGP; + llvm::Optional _gpAtom; + llvm::Optional _gpDispAtom; }; /// \brief Mips Runtime file. -- 2.7.4