[lld] r173909 - [ELF] Add {Hexagon,PPC,X86}TargetHandler.
Michael J. Spencer
bigcheesegs at gmail.com
Tue Jan 29 23:36:45 PST 2013
Author: mspencer
Date: Wed Jan 30 01:36:45 2013
New Revision: 173909
URL: http://llvm.org/viewvc/llvm-project?rev=173909&view=rev
Log:
[ELF] Add {Hexagon,PPC,X86}TargetHandler.
Added:
lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.cpp
lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.h
lld/trunk/lib/ReaderWriter/ELF/PPC/PPCTargetHandler.cpp
lld/trunk/lib/ReaderWriter/ELF/PPC/PPCTargetHandler.h
lld/trunk/lib/ReaderWriter/ELF/X86/X86TargetHandler.cpp
lld/trunk/lib/ReaderWriter/ELF/X86/X86TargetHandler.h
Modified:
lld/trunk/lib/ReaderWriter/ELF/CMakeLists.txt
lld/trunk/lib/ReaderWriter/ELF/Hexagon/CMakeLists.txt
lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonTargetInfo.h
lld/trunk/lib/ReaderWriter/ELF/PPC/CMakeLists.txt
lld/trunk/lib/ReaderWriter/ELF/PPC/PPCTargetInfo.h
lld/trunk/lib/ReaderWriter/ELF/X86/CMakeLists.txt
lld/trunk/lib/ReaderWriter/ELF/X86/X86TargetInfo.h
lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64TargetHandler.h
lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64TargetInfo.h
Modified: lld/trunk/lib/ReaderWriter/ELF/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/CMakeLists.txt?rev=173909&r1=173908&r2=173909&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/CMakeLists.txt (original)
+++ lld/trunk/lib/ReaderWriter/ELF/CMakeLists.txt Wed Jan 30 01:36:45 2013
@@ -10,8 +10,11 @@ add_lld_library(lldELF
)
target_link_libraries(lldELF
+ lldHexagonELFTarget
+ lldPPCELFTarget
lldReaderWriter
lldX86_64ELFTarget
+ lldX86ELFTarget
)
include_directories(.)
Modified: lld/trunk/lib/ReaderWriter/ELF/Hexagon/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Hexagon/CMakeLists.txt?rev=173909&r1=173908&r2=173909&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Hexagon/CMakeLists.txt (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Hexagon/CMakeLists.txt Wed Jan 30 01:36:45 2013
@@ -1,5 +1,8 @@
add_lld_library(lldHexagonELFTarget
+ HexagonTargetHandler.cpp
HexagonTargetInfo.cpp
)
-target_link_libraries(lldHexagonELFTarget)
+target_link_libraries(lldHexagonELFTarget
+ lldCore
+ )
Added: lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.cpp?rev=173909&view=auto
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.cpp (added)
+++ lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.cpp Wed Jan 30 01:36:45 2013
@@ -0,0 +1,110 @@
+//===- lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.cpp --------------===//
+//
+// The LLVM Linker
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "HexagonTargetHandler.h"
+#include "HexagonTargetInfo.h"
+
+using namespace lld;
+using namespace elf;
+
+using namespace llvm::ELF;
+
+namespace {
+/// \brief Word32_B22: 0x01ff3ffe : (S + A - P) >> 2 : Verify
+int relocB22PCREL(uint8_t *location, uint64_t P, uint64_t S, uint64_t A) {
+ int32_t result = (uint32_t)(((S + A) - P)>>2);
+ if ((result < 0x200000) && (result > -0x200000)) {
+ result = ((result<<1) & 0x3ffe) | ((result<<3) & 0x01ff0000);
+ *reinterpret_cast<llvm::support::ulittle32_t *>(location) = result |
+ (uint32_t)*reinterpret_cast<llvm::support::ulittle32_t *>(location);
+ return HexagonKindHandler::NoError;
+ }
+ return HexagonKindHandler::Overflow;
+}
+
+/// \brief Word32_B15: 0x00df20fe : (S + A - P) >> 2 : Verify
+int relocB15PCREL(uint8_t *location, uint64_t P, uint64_t S, uint64_t A) {
+ int32_t result = (uint32_t)(((S + A) - P)>>2);
+ if ((result < 0x8000) && (result > -0x8000)) {
+ result = ((result<<1) & 0x20fe) | ((result<<7) & 0x00df0000);
+ *reinterpret_cast<llvm::support::ulittle32_t *>(location) = result |
+ (uint32_t)*reinterpret_cast<llvm::support::ulittle32_t *>(location);
+ return HexagonKindHandler::NoError;
+ }
+ return HexagonKindHandler::Overflow;
+}
+
+/// \brief Word32_LO: 0x00c03fff : (S + A) : Truncate
+int relocLO16(uint8_t *location, uint64_t P, uint64_t S, uint64_t A) {
+ uint32_t result = (uint32_t)(S + A);
+ result = ((result & 0x3fff) | ((result << 8) & 0x00c00000));
+ *reinterpret_cast<llvm::support::ulittle32_t *>(location) = result |
+ (uint32_t)*reinterpret_cast<llvm::support::ulittle32_t *>(location);
+ return HexagonKindHandler::NoError;
+}
+
+/// \brief Word32_LO: 0x00c03fff : (S + A) >> 16 : Truncate
+int relocHI16(uint8_t *location, uint64_t P, uint64_t S, uint64_t A) {
+ uint32_t result = (uint32_t)((S + A)>>16);
+ result = ((result & 0x3fff) | ((result << 8) & 0x00c00000));
+ *reinterpret_cast<llvm::support::ulittle32_t *>(location) = result |
+ (uint32_t)*reinterpret_cast<llvm::support::ulittle32_t *>(location);
+ return HexagonKindHandler::NoError;
+}
+
+/// \brief Word32: 0xffffffff : (S + A) : Truncate
+int reloc32(uint8_t *location, uint64_t P, uint64_t S, uint64_t A) {
+ uint32_t result = (uint32_t)(S + A);
+ *reinterpret_cast<llvm::support::ulittle32_t *>(location) = result |
+ (uint32_t)*reinterpret_cast<llvm::support::ulittle32_t *>(location);
+ return HexagonKindHandler::NoError;
+}
+} // end anon namespace
+
+ErrorOr<void> HexagonTargetRelocationHandler::applyRelocation(
+ ELFWriter &writer, llvm::FileOutputBuffer &buf, const AtomLayout &atom,
+ const Reference &ref) const {
+ uint8_t *atomContent = buf.getBufferStart() + atom._fileOffset;
+ uint8_t *location = atomContent + ref.offsetInAtom();
+ uint64_t targetVAddress = writer.addressOfAtom(ref.target());
+ uint64_t relocVAddress = atom._virtualAddr + ref.offsetInAtom();
+
+ switch (ref.kind()) {
+ case R_HEX_B22_PCREL:
+ relocB22PCREL(location, relocVAddress, targetVAddress, ref.addend());
+ break;
+ case R_HEX_B15_PCREL:
+ relocB15PCREL(location, relocVAddress, targetVAddress, ref.addend());
+ break;
+ case R_HEX_LO16:
+ relocLO16(location, relocVAddress, targetVAddress, ref.addend());
+ break;
+ case R_HEX_HI16:
+ relocHI16(location, relocVAddress, targetVAddress, ref.addend());
+ break;
+ case R_HEX_32:
+ reloc32(location, relocVAddress, targetVAddress, ref.addend());
+ break;
+ default: {
+ std::string str;
+ llvm::raw_string_ostream s(str);
+ auto name = _targetInfo.stringFromRelocKind(ref.kind());
+ s << "Unhandled relocation: "
+ << (name ? *name : "<unknown>" ) << " (" << ref.kind() << ")";
+ s.flush();
+ llvm_unreachable(str.c_str());
+ }
+ }
+
+ return error_code::success();
+}
+
+HexagonTargetHandler::HexagonTargetHandler(HexagonTargetInfo &targetInfo)
+ : DefaultTargetHandler(targetInfo), _relocationHandler(targetInfo) {
+}
Added: lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.h?rev=173909&view=auto
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.h (added)
+++ lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.h Wed Jan 30 01:36:45 2013
@@ -0,0 +1,48 @@
+//===- lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.h ----------------===//
+//
+// The LLVM Linker
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLD_READER_WRITER_ELF_HEXAGON_TARGET_HANDLER_H
+#define LLD_READER_WRITER_ELF_HEXAGON_TARGET_HANDLER_H
+
+#include "DefaultTargetHandler.h"
+
+namespace lld {
+namespace elf {
+typedef llvm::object::ELFType<llvm::support::little, 4, false> HexagonELFType;
+class HexagonTargetInfo;
+
+class HexagonTargetRelocationHandler LLVM_FINAL
+ : public TargetRelocationHandler<HexagonELFType> {
+public:
+ HexagonTargetRelocationHandler(const HexagonTargetInfo &ti) : _targetInfo(ti) {}
+
+ virtual ErrorOr<void> applyRelocation(ELFWriter &, llvm::FileOutputBuffer &,
+ const AtomLayout &,
+ const Reference &)const;
+
+private:
+ const HexagonTargetInfo &_targetInfo;
+};
+
+class HexagonTargetHandler LLVM_FINAL
+ : public DefaultTargetHandler<HexagonELFType> {
+public:
+ HexagonTargetHandler(HexagonTargetInfo &targetInfo);
+
+ virtual const HexagonTargetRelocationHandler &getRelocationHandler() const {
+ return _relocationHandler;
+ }
+
+private:
+ HexagonTargetRelocationHandler _relocationHandler;
+};
+} // end namespace elf
+} // end namespace lld
+
+#endif
Modified: lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonTargetInfo.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonTargetInfo.h?rev=173909&r1=173908&r2=173909&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonTargetInfo.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonTargetInfo.h Wed Jan 30 01:36:45 2013
@@ -1,4 +1,4 @@
-//===- lib/ReaderWriter/ELF/Hexagon/HexagonTargetInfo.h ------------------===//
+//===- lib/ReaderWriter/ELF/Hexagon/HexagonTargetInfo.h -------------------===//
//
// The LLVM Linker
//
@@ -10,21 +10,21 @@
#ifndef LLD_READER_WRITER_ELF_HEXAGON_TARGETINFO_H
#define LLD_READER_WRITER_ELF_HEXAGON_TARGETINFO_H
-#include "lld/ReaderWriter/ELFTargetInfo.h"
+#include "HexagonTargetHandler.h"
+
#include "lld/Core/LinkerOptions.h"
+#include "lld/ReaderWriter/ELFTargetInfo.h"
+
#include "llvm/Object/ELF.h"
#include "llvm/Support/ELF.h"
-#include "DefaultTargetHandler.h"
-
namespace lld {
namespace elf {
class HexagonTargetInfo LLVM_FINAL : public ELFTargetInfo {
public:
HexagonTargetInfo(const LinkerOptions &lo) : ELFTargetInfo(lo) {
_targetHandler = std::unique_ptr<TargetHandlerBase>(
- new DefaultTargetHandler<llvm::object::ELFType<llvm::support::little,
- 4, false> >(*this));
+ new HexagonTargetHandler(*this));
}
virtual uint64_t getPageSize() const { return 0x1000; }
Modified: lld/trunk/lib/ReaderWriter/ELF/PPC/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/PPC/CMakeLists.txt?rev=173909&r1=173908&r2=173909&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/PPC/CMakeLists.txt (original)
+++ lld/trunk/lib/ReaderWriter/ELF/PPC/CMakeLists.txt Wed Jan 30 01:36:45 2013
@@ -1,5 +1,8 @@
add_lld_library(lldPPCELFTarget
+ PPCTargetHandler.cpp
PPCTargetInfo.cpp
)
-target_link_libraries(lldPPCELFTarget)
+target_link_libraries(lldPPCELFTarget
+ lldCore
+ )
Added: lld/trunk/lib/ReaderWriter/ELF/PPC/PPCTargetHandler.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/PPC/PPCTargetHandler.cpp?rev=173909&view=auto
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/PPC/PPCTargetHandler.cpp (added)
+++ lld/trunk/lib/ReaderWriter/ELF/PPC/PPCTargetHandler.cpp Wed Jan 30 01:36:45 2013
@@ -0,0 +1,66 @@
+//===- lib/ReaderWriter/ELF/PPC/PPCTargetHandler.cpp ----------------------===//
+//
+// The LLVM Linker
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "PPCTargetHandler.h"
+#include "PPCTargetInfo.h"
+
+using namespace lld;
+using namespace elf;
+
+using namespace llvm::ELF;
+
+/// \brief The following relocation routines are derived from the
+/// SYSTEM V APPLICATION BINARY INTERFACE: PowerPC Processor Supplement
+/// Symbols used:
+/// A: Added used to compute the value, r_addend
+/// P: Place address of the field being relocated, r_offset
+/// S: Value of the symbol whose index resides in the relocation entry.
+namespace {
+/// \brief low24 (S + A - P) >> 2 : Verify
+int relocB24PCREL(uint8_t *location, uint64_t P, uint64_t S, uint64_t A) {
+ int32_t result = (uint32_t)(((S + A) - P));
+ if ((result < 0x1000000) && (result > -0x1000000)) {
+ result &= ~-(0x1000000);
+ *reinterpret_cast<llvm::support::ubig32_t *>(location) = result |
+ (uint32_t)*reinterpret_cast<llvm::support::ubig32_t *>(location);
+ return PPCKindHandler::NoError;
+ }
+ return PPCKindHandler::Overflow;
+}
+} // end anon namespace
+
+ErrorOr<void> PPCTargetRelocationHandler::applyRelocation(
+ ELFWriter &writer, llvm::FileOutputBuffer &buf, const AtomLayout &atom,
+ const Reference &ref) const {
+ uint8_t *atomContent = buf.getBufferStart() + atom._fileOffset;
+ uint8_t *location = atomContent + ref.offsetInAtom();
+ uint64_t targetVAddress = writer.addressOfAtom(ref.target());
+ uint64_t relocVAddress = atom._virtualAddr + ref.offsetInAtom();
+
+ switch (ref.kind()) {
+ case R_PPC_REL24:
+ relocB24PCREL(location, relocVAddress, targetVAddress, ref.addend());
+ break;
+ default: {
+ std::string str;
+ llvm::raw_string_ostream s(str);
+ auto name = _targetInfo.stringFromRelocKind(ref.kind());
+ s << "Unhandled relocation: "
+ << (name ? *name : "<unknown>" ) << " (" << ref.kind() << ")";
+ s.flush();
+ llvm_unreachable(str.c_str());
+ }
+ }
+
+ return error_code::success();
+}
+
+PPCTargetHandler::PPCTargetHandler(PPCTargetInfo &targetInfo)
+ : DefaultTargetHandler(targetInfo), _relocationHandler(targetInfo) {
+}
Added: lld/trunk/lib/ReaderWriter/ELF/PPC/PPCTargetHandler.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/PPC/PPCTargetHandler.h?rev=173909&view=auto
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/PPC/PPCTargetHandler.h (added)
+++ lld/trunk/lib/ReaderWriter/ELF/PPC/PPCTargetHandler.h Wed Jan 30 01:36:45 2013
@@ -0,0 +1,48 @@
+//===- lib/ReaderWriter/ELF/PPC/PPCTargetHandler.h ------------------------===//
+//
+// The LLVM Linker
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLD_READER_WRITER_ELF_PPC_TARGET_HANDLER_H
+#define LLD_READER_WRITER_ELF_PPC_TARGET_HANDLER_H
+
+#include "DefaultTargetHandler.h"
+
+namespace lld {
+namespace elf {
+typedef llvm::object::ELFType<llvm::support::big, 4, false> PPCELFType;
+class PPCTargetInfo;
+
+class PPCTargetRelocationHandler LLVM_FINAL
+ : public TargetRelocationHandler<PPCELFType> {
+public:
+ PPCTargetRelocationHandler(const PPCTargetInfo &ti) : _targetInfo(ti) {}
+
+ virtual ErrorOr<void> applyRelocation(ELFWriter &, llvm::FileOutputBuffer &,
+ const AtomLayout &,
+ const Reference &)const;
+
+private:
+ const PPCTargetInfo &_targetInfo;
+};
+
+class PPCTargetHandler LLVM_FINAL
+ : public DefaultTargetHandler<PPCELFType> {
+public:
+ PPCTargetHandler(PPCTargetInfo &targetInfo);
+
+ virtual const PPCTargetRelocationHandler &getRelocationHandler() const {
+ return _relocationHandler;
+ }
+
+private:
+ PPCTargetRelocationHandler _relocationHandler;
+};
+} // end namespace elf
+} // end namespace lld
+
+#endif
Modified: lld/trunk/lib/ReaderWriter/ELF/PPC/PPCTargetInfo.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/PPC/PPCTargetInfo.h?rev=173909&r1=173908&r2=173909&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/PPC/PPCTargetInfo.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/PPC/PPCTargetInfo.h Wed Jan 30 01:36:45 2013
@@ -10,21 +10,21 @@
#ifndef LLD_READER_WRITER_ELF_PPC_TARGETINFO_H
#define LLD_READER_WRITER_ELF_PPC_TARGETINFO_H
-#include "lld/ReaderWriter/ELFTargetInfo.h"
+#include "PPCTargetHandler.h"
+
#include "lld/Core/LinkerOptions.h"
+#include "lld/ReaderWriter/ELFTargetInfo.h"
+
#include "llvm/Object/ELF.h"
#include "llvm/Support/ELF.h"
-#include "DefaultTargetHandler.h"
-
namespace lld {
namespace elf {
class PPCTargetInfo LLVM_FINAL : public ELFTargetInfo {
public:
PPCTargetInfo(const LinkerOptions &lo) : ELFTargetInfo(lo) {
_targetHandler = std::unique_ptr<TargetHandlerBase>(
- new DefaultTargetHandler<
- llvm::object::ELFType<llvm::support::big, 4, false> >(*this));
+ new PPCTargetHandler(*this));
}
virtual bool isLittleEndian() const { return false; }
Modified: lld/trunk/lib/ReaderWriter/ELF/X86/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/X86/CMakeLists.txt?rev=173909&r1=173908&r2=173909&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/X86/CMakeLists.txt (original)
+++ lld/trunk/lib/ReaderWriter/ELF/X86/CMakeLists.txt Wed Jan 30 01:36:45 2013
@@ -1,5 +1,8 @@
add_lld_library(lldX86ELFTarget
X86TargetInfo.cpp
+ X86TargetHandler.cpp
)
-target_link_libraries(lldX86ELFTarget)
+target_link_libraries(lldX86ELFTarget
+ lldCore
+ )
Added: lld/trunk/lib/ReaderWriter/ELF/X86/X86TargetHandler.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/X86/X86TargetHandler.cpp?rev=173909&view=auto
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/X86/X86TargetHandler.cpp (added)
+++ lld/trunk/lib/ReaderWriter/ELF/X86/X86TargetHandler.cpp Wed Jan 30 01:36:45 2013
@@ -0,0 +1,67 @@
+//===- lib/ReaderWriter/ELF/X86/X86TargetHandler.cpp ----------------------===//
+//
+// The LLVM Linker
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "X86TargetHandler.h"
+#include "X86TargetInfo.h"
+
+using namespace lld;
+using namespace elf;
+
+using namespace llvm::ELF;
+
+namespace {
+/// \brief R_386_32 - word32: S + A
+int reloc32(uint8_t *location, uint64_t P, uint64_t S, uint64_t A) {
+ int32_t result = (uint32_t)(S + A);
+ *reinterpret_cast<llvm::support::ulittle32_t *>(location) = result |
+ (uint32_t)*reinterpret_cast<llvm::support::ulittle32_t *>(location);
+ return X86KindHandler::NoError;
+}
+
+/// \brief R_386_PC32 - word32: S + A - P
+int relocPC32(uint8_t *location, uint64_t P, uint64_t S, uint64_t A) {
+ uint32_t result = (uint32_t)((S + A) - P);
+ *reinterpret_cast<llvm::support::ulittle32_t *>(location) = result +
+ (uint32_t)*reinterpret_cast<llvm::support::ulittle32_t *>(location);
+ return X86KindHandler::NoError;
+}
+} // end anon namespace
+
+ErrorOr<void> X86TargetRelocationHandler::applyRelocation(
+ ELFWriter &writer, llvm::FileOutputBuffer &buf, const AtomLayout &atom,
+ const Reference &ref) const {
+ uint8_t *atomContent = buf.getBufferStart() + atom._fileOffset;
+ uint8_t *location = atomContent + ref.offsetInAtom();
+ uint64_t targetVAddress = writer.addressOfAtom(ref.target());
+ uint64_t relocVAddress = atom._virtualAddr + ref.offsetInAtom();
+
+ switch (ref.kind()) {
+ case R_386_32:
+ reloc32(location, relocVAddress, targetVAddress, ref.addend());
+ break;
+ case R_386_PC32:
+ relocPC32(location, relocVAddress, targetVAddress, ref.addend());
+ break;
+ default: {
+ std::string str;
+ llvm::raw_string_ostream s(str);
+ auto name = _targetInfo.stringFromRelocKind(ref.kind());
+ s << "Unhandled relocation: "
+ << (name ? *name : "<unknown>" ) << " (" << ref.kind() << ")";
+ s.flush();
+ llvm_unreachable(str.c_str());
+ }
+ }
+
+ return error_code::success();
+}
+
+X86TargetHandler::X86TargetHandler(X86TargetInfo &targetInfo)
+ : DefaultTargetHandler(targetInfo), _relocationHandler(targetInfo) {
+}
Added: lld/trunk/lib/ReaderWriter/ELF/X86/X86TargetHandler.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/X86/X86TargetHandler.h?rev=173909&view=auto
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/X86/X86TargetHandler.h (added)
+++ lld/trunk/lib/ReaderWriter/ELF/X86/X86TargetHandler.h Wed Jan 30 01:36:45 2013
@@ -0,0 +1,48 @@
+//===- lib/ReaderWriter/ELF/X86/X86TargetHandler.h ------------------------===//
+//
+// The LLVM Linker
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLD_READER_WRITER_ELF_X86_TARGET_HANDLER_H
+#define LLD_READER_WRITER_ELF_X86_TARGET_HANDLER_H
+
+#include "DefaultTargetHandler.h"
+
+namespace lld {
+namespace elf {
+typedef llvm::object::ELFType<llvm::support::little, 4, false> X86ELFType;
+class X86TargetInfo;
+
+class X86TargetRelocationHandler LLVM_FINAL
+ : public TargetRelocationHandler<X86ELFType> {
+public:
+ X86TargetRelocationHandler(const X86TargetInfo &ti) : _targetInfo(ti) {}
+
+ virtual ErrorOr<void> applyRelocation(ELFWriter &, llvm::FileOutputBuffer &,
+ const AtomLayout &,
+ const Reference &)const;
+
+private:
+ const X86TargetInfo &_targetInfo;
+};
+
+class X86TargetHandler LLVM_FINAL
+ : public DefaultTargetHandler<X86ELFType> {
+public:
+ X86TargetHandler(X86TargetInfo &targetInfo);
+
+ virtual const X86TargetRelocationHandler &getRelocationHandler() const {
+ return _relocationHandler;
+ }
+
+private:
+ X86TargetRelocationHandler _relocationHandler;
+};
+} // end namespace elf
+} // end namespace lld
+
+#endif
Modified: lld/trunk/lib/ReaderWriter/ELF/X86/X86TargetInfo.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/X86/X86TargetInfo.h?rev=173909&r1=173908&r2=173909&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/X86/X86TargetInfo.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/X86/X86TargetInfo.h Wed Jan 30 01:36:45 2013
@@ -10,7 +10,7 @@
#ifndef LLD_READER_WRITER_ELF_X86_TARGETINFO_H
#define LLD_READER_WRITER_ELF_X86_TARGETINFO_H
-#include "DefaultTargetHandler.h"
+#include "X86TargetHandler.h"
#include "lld/Core/LinkerOptions.h"
#include "lld/ReaderWriter/ELFTargetInfo.h"
@@ -24,8 +24,7 @@ class X86TargetInfo LLVM_FINAL : public
public:
X86TargetInfo(const LinkerOptions &lo) : ELFTargetInfo(lo) {
_targetHandler = std::unique_ptr<TargetHandlerBase>(
- new DefaultTargetHandler<llvm::object::ELFType<llvm::support::little,
- 4, false> >(*this));
+ new X86TargetHandler(*this));
}
virtual uint64_t getPageSize() const { return 0x1000; }
Modified: lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64TargetHandler.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64TargetHandler.h?rev=173909&r1=173908&r2=173909&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64TargetHandler.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64TargetHandler.h Wed Jan 30 01:36:45 2013
@@ -14,7 +14,7 @@
namespace lld {
namespace elf {
-typedef llvm::object::ELFType<llvm::support::little, 8, false> X86_64ELFType;
+typedef llvm::object::ELFType<llvm::support::little, 8, true> X86_64ELFType;
class X86_64TargetInfo;
class X86_64TargetRelocationHandler LLVM_FINAL
Modified: lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64TargetInfo.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64TargetInfo.h?rev=173909&r1=173908&r2=173909&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64TargetInfo.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64TargetInfo.h Wed Jan 30 01:36:45 2013
@@ -20,7 +20,6 @@
namespace lld {
namespace elf {
-typedef llvm::object::ELFType<llvm::support::little, 8, false> X86_64ELFType;
class X86_64TargetInfo LLVM_FINAL : public ELFTargetInfo {
public:
More information about the llvm-commits
mailing list