From da288955975c07d8f59ecb8ec3c15c2948d2f514 Mon Sep 17 00:00:00 2001 From: Shankar Easwaran Date: Thu, 28 Feb 2013 20:54:03 +0000 Subject: [PATCH] [ELF][Hexagon] add quickdata relocations llvm-svn: 176298 --- .../ELF/Hexagon/HexagonRelocationHandler.cpp | 30 +++++++++++++++++++ .../ELF/Hexagon/HexagonRelocationHandler.h | 21 ++++++++----- .../ELF/Hexagon/HexagonSectionChunks.h | 3 ++ .../ELF/Hexagon/HexagonTargetHandler.cpp | 6 ++-- .../ELF/Hexagon/HexagonTargetHandler.h | 8 ++--- .../ELF/Hexagon/HexagonTargetInfo.h | 1 + 6 files changed, 54 insertions(+), 15 deletions(-) diff --git a/lld/lib/ReaderWriter/ELF/Hexagon/HexagonRelocationHandler.cpp b/lld/lib/ReaderWriter/ELF/Hexagon/HexagonRelocationHandler.cpp index 97f63a2acc17..3792475217ec 100644 --- a/lld/lib/ReaderWriter/ELF/Hexagon/HexagonRelocationHandler.cpp +++ b/lld/lib/ReaderWriter/ELF/Hexagon/HexagonRelocationHandler.cpp @@ -107,6 +107,20 @@ int relocHex_N_X(uint8_t *location, uint64_t P, uint64_t S, uint64_t A) { return 0; } +// GP REL relocations +int relocHexGPRELN(uint8_t *location, uint64_t P, uint64_t S, uint64_t A, + uint64_t GP, int nShiftBits) { + int32_t result = (int64_t)((S + A - GP) >> nShiftBits); + int32_t range = 1L << 16; + if (result <= range) { + result = lld::scatterBits(result, FINDV4BITMASK(location)); + *reinterpret_cast(location) = + result | + (uint32_t) * reinterpret_cast(location); + return 0; + } + return 1; +} } // end anon namespace ErrorOr HexagonTargetRelocationHandler::applyRelocation( @@ -157,6 +171,22 @@ ErrorOr HexagonTargetRelocationHandler::applyRelocation( case R_HEX_B7_PCREL_X: relocHexBNPCRELX(location, relocVAddress, targetVAddress, ref.addend(), 6); break; + case R_HEX_GPREL16_0: + relocHexGPRELN(location, relocVAddress, targetVAddress, ref.addend(), + _targetLayout.getSDataSection()->virtualAddr(), 0); + break; + case R_HEX_GPREL16_1: + relocHexGPRELN(location, relocVAddress, targetVAddress, ref.addend(), + _targetLayout.getSDataSection()->virtualAddr(), 1); + break; + case R_HEX_GPREL16_2: + relocHexGPRELN(location, relocVAddress, targetVAddress, ref.addend(), + _targetLayout.getSDataSection()->virtualAddr(), 2); + break; + case R_HEX_GPREL16_3: + relocHexGPRELN(location, relocVAddress, targetVAddress, ref.addend(), + _targetLayout.getSDataSection()->virtualAddr(), 3); + break; case R_HEX_16_X: case R_HEX_12_X: case R_HEX_11_X: diff --git a/lld/lib/ReaderWriter/ELF/Hexagon/HexagonRelocationHandler.h b/lld/lib/ReaderWriter/ELF/Hexagon/HexagonRelocationHandler.h index d1757cfd1d07..2894e5b8e85c 100644 --- a/lld/lib/ReaderWriter/ELF/Hexagon/HexagonRelocationHandler.h +++ b/lld/lib/ReaderWriter/ELF/Hexagon/HexagonRelocationHandler.h @@ -9,6 +9,7 @@ #ifndef LLD_READER_WRITER_ELF_HEXAGON_RELOCATION_HANDLER_H #define LLD_READER_WRITER_ELF_HEXAGON_RELOCATION_HANDLER_H +#include "HexagonSectionChunks.h" #include "HexagonTargetHandler.h" #include "lld/ReaderWriter/RelocationHelperFunctions.h" @@ -17,19 +18,23 @@ namespace elf { typedef llvm::object::ELFType HexagonELFType; class HexagonTargetInfo; +class HexagonTargetHandler; +template class HexagonTargetLayout; -class HexagonTargetRelocationHandler LLVM_FINAL - : public TargetRelocationHandler { +class HexagonTargetRelocationHandler LLVM_FINAL : + public TargetRelocationHandler { public: - HexagonTargetRelocationHandler(const HexagonTargetInfo &ti) : _targetInfo(ti) - {} - - virtual ErrorOr applyRelocation(ELFWriter &, llvm::FileOutputBuffer &, - const AtomLayout &, - const Reference &)const; + HexagonTargetRelocationHandler( + const HexagonTargetInfo &ti, + const HexagonTargetLayout &layout) + : _targetInfo(ti), _targetLayout(layout) {} + virtual ErrorOr + applyRelocation(ELFWriter &, llvm::FileOutputBuffer &, const AtomLayout &, + const Reference &) const; private: const HexagonTargetInfo &_targetInfo; + const HexagonTargetLayout &_targetLayout; }; } // elf } // lld diff --git a/lld/lib/ReaderWriter/ELF/Hexagon/HexagonSectionChunks.h b/lld/lib/ReaderWriter/ELF/Hexagon/HexagonSectionChunks.h index 4bbe3b698e71..19911481c301 100644 --- a/lld/lib/ReaderWriter/ELF/Hexagon/HexagonSectionChunks.h +++ b/lld/lib/ReaderWriter/ELF/Hexagon/HexagonSectionChunks.h @@ -6,6 +6,8 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// +#ifndef LLD_READER_WRITER_ELF_HEXAGON_SECTION_CHUNKS_H +#define LLD_READER_WRITER_ELF_HEXAGON_SECTION_CHUNKS_H #include "HexagonTargetHandler.h" @@ -75,3 +77,4 @@ void SDataSection::doPreFlight() { } // elf } // lld +#endif // LLD_READER_WRITER_ELF_HEXAGON_SECTION_CHUNKS_H diff --git a/lld/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.cpp b/lld/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.cpp index c998a34b6ac8..d7ea9cb364fc 100644 --- a/lld/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.cpp +++ b/lld/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.cpp @@ -16,6 +16,6 @@ using namespace elf; using namespace llvm::ELF; HexagonTargetHandler::HexagonTargetHandler(HexagonTargetInfo &targetInfo) - : DefaultTargetHandler(targetInfo), _relocationHandler(targetInfo), - _targetLayout(targetInfo), _hexagonRuntimeFile(targetInfo) { -} + : DefaultTargetHandler(targetInfo), _targetLayout(targetInfo), + _relocationHandler(targetInfo, _targetLayout), + _hexagonRuntimeFile(targetInfo) {} diff --git a/lld/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.h b/lld/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.h index 03726df07b64..ff8278dea92b 100644 --- a/lld/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.h +++ b/lld/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.h @@ -156,11 +156,11 @@ public: header->e_flags(0x3); } - virtual TargetLayout &targetLayout() { + virtual HexagonTargetLayout &targetLayout() { return _targetLayout; } - virtual TargetAtomHandler &targetAtomHandler() { + virtual HexagonTargetAtomHandler &targetAtomHandler() { return _targetAtomHandler; } @@ -184,10 +184,10 @@ public: } private: - HexagonTargetRelocationHandler _relocationHandler; HexagonTargetLayout _targetLayout; + HexagonTargetRelocationHandler _relocationHandler; HexagonTargetAtomHandler _targetAtomHandler; - HexagonRuntimeFile _hexagonRuntimeFile; + HexagonRuntimeFile _hexagonRuntimeFile; }; } // end namespace elf } // end namespace lld diff --git a/lld/lib/ReaderWriter/ELF/Hexagon/HexagonTargetInfo.h b/lld/lib/ReaderWriter/ELF/Hexagon/HexagonTargetInfo.h index e5a84ff580a9..bf25b504f664 100644 --- a/lld/lib/ReaderWriter/ELF/Hexagon/HexagonTargetInfo.h +++ b/lld/lib/ReaderWriter/ELF/Hexagon/HexagonTargetInfo.h @@ -20,6 +20,7 @@ namespace lld { namespace elf { + class HexagonTargetInfo LLVM_FINAL : public ELFTargetInfo { public: HexagonTargetInfo(const LinkerOptions &lo) : ELFTargetInfo(lo) { -- 2.34.1