[lld] r173912 - [ELF] Remove ReferenceKinds.
Michael J. Spencer
bigcheesegs at gmail.com
Tue Jan 29 23:46:55 PST 2013
Author: mspencer
Date: Wed Jan 30 01:46:54 2013
New Revision: 173912
URL: http://llvm.org/viewvc/llvm-project?rev=173912&view=rev
Log:
[ELF] Remove ReferenceKinds.
Removed:
lld/trunk/lib/ReaderWriter/ELF/HexagonReference.cpp
lld/trunk/lib/ReaderWriter/ELF/PPCReference.cpp
lld/trunk/lib/ReaderWriter/ELF/ReferenceKinds.cpp
lld/trunk/lib/ReaderWriter/ELF/ReferenceKinds.h
lld/trunk/lib/ReaderWriter/ELF/X86Reference.cpp
lld/trunk/lib/ReaderWriter/ELF/X86_64Reference.cpp
Modified:
lld/trunk/lib/ReaderWriter/ELF/CMakeLists.txt
lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.cpp
lld/trunk/lib/ReaderWriter/ELF/PPC/PPCTargetHandler.cpp
lld/trunk/lib/ReaderWriter/ELF/Writer.cpp
lld/trunk/lib/ReaderWriter/ELF/Writer.h
lld/trunk/lib/ReaderWriter/ELF/X86/X86TargetHandler.cpp
Modified: lld/trunk/lib/ReaderWriter/ELF/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/CMakeLists.txt?rev=173912&r1=173911&r2=173912&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/CMakeLists.txt (original)
+++ lld/trunk/lib/ReaderWriter/ELF/CMakeLists.txt Wed Jan 30 01:46:54 2013
@@ -1,12 +1,7 @@
add_lld_library(lldELF
ELFTargetInfo.cpp
- HexagonReference.cpp
- PPCReference.cpp
Reader.cpp
- ReferenceKinds.cpp
Writer.cpp
- X86Reference.cpp
- X86_64Reference.cpp
)
target_link_libraries(lldELF
Modified: lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.cpp?rev=173912&r1=173911&r2=173912&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.cpp Wed Jan 30 01:46:54 2013
@@ -23,9 +23,9 @@ int relocB22PCREL(uint8_t *location, uin
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 0;
}
- return HexagonKindHandler::Overflow;
+ return 1;
}
/// \brief Word32_B15: 0x00df20fe : (S + A - P) >> 2 : Verify
@@ -35,9 +35,9 @@ int relocB15PCREL(uint8_t *location, uin
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 0;
}
- return HexagonKindHandler::Overflow;
+ return 1;
}
/// \brief Word32_LO: 0x00c03fff : (S + A) : Truncate
@@ -46,7 +46,7 @@ int relocLO16(uint8_t *location, uint64_
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;
+ return 0;
}
/// \brief Word32_LO: 0x00c03fff : (S + A) >> 16 : Truncate
@@ -55,7 +55,7 @@ int relocHI16(uint8_t *location, uint64_
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;
+ return 0;
}
/// \brief Word32: 0xffffffff : (S + A) : Truncate
@@ -63,7 +63,7 @@ int reloc32(uint8_t *location, uint64_t
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;
+ return 0;
}
} // end anon namespace
Removed: lld/trunk/lib/ReaderWriter/ELF/HexagonReference.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/HexagonReference.cpp?rev=173911&view=auto
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/HexagonReference.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/HexagonReference.cpp (removed)
@@ -1,170 +0,0 @@
-//===- lib/ReaderWriter/ELF/HexagonReference.cpp ----------------------------===//
-//
-// The LLVM Linker
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-
-#include "ReferenceKinds.h"
-
-#include "llvm/ADT/StringRef.h"
-#include "llvm/ADT/StringSwitch.h"
-#include "llvm/Support/Endian.h"
-#include "llvm/Support/ErrorHandling.h"
-#include "llvm/Support/ELF.h"
-
-namespace lld {
-namespace elf {
-
-//===----------------------------------------------------------------------===//
-// HexagonKindHandler
-// TODO: more to do here
-//===----------------------------------------------------------------------===//
-
-HexagonKindHandler::~HexagonKindHandler() {
-}
-
-/// \brief The following relocation routines are derived from the
-/// Hexagon ABI specification, Section 11.6: Relocation
-/// 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 hexagon {
-int relocNONE(uint8_t *location, uint64_t P, uint64_t S, uint64_t A) {
- return HexagonKindHandler::NoError;
-}
-
-/// \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;
-}
-} // namespace hexagon
-
-HexagonKindHandler::HexagonKindHandler(){
- _fixupHandler[llvm::ELF::R_HEX_B22_PCREL] = hexagon::relocB22PCREL;
- _fixupHandler[llvm::ELF::R_HEX_B15_PCREL] = hexagon::relocB15PCREL;
- _fixupHandler[llvm::ELF::R_HEX_LO16] = hexagon::relocLO16;
- _fixupHandler[llvm::ELF::R_HEX_HI16] = hexagon::relocHI16;
- _fixupHandler[llvm::ELF::R_HEX_32] = hexagon::reloc32;
-}
-
-Reference::Kind HexagonKindHandler::stringToKind(StringRef str) {
- return llvm::StringSwitch<Reference::Kind>(str)
- .Case("none", none)
- .Case("R_HEX_B22_PCREL", llvm::ELF::R_HEX_B22_PCREL)
- .Case("R_HEX_B15_PCREL", llvm::ELF::R_HEX_B15_PCREL)
- .Case("R_HEX_LO16", llvm::ELF::R_HEX_LO16)
- .Case("R_HEX_HI16", llvm::ELF::R_HEX_HI16)
- .Case("R_HEX_32", llvm::ELF::R_HEX_32)
- .Default(invalid);
-}
-
-StringRef HexagonKindHandler::kindToString(Reference::Kind kind) {
- switch (static_cast<int32_t>(kind)) {
- case llvm::ELF::R_HEX_B22_PCREL:
- return "R_HEX_B22_PCREL";
- case llvm::ELF::R_HEX_B15_PCREL:
- return "R_HEX_B15_PCREL";
- case llvm::ELF::R_HEX_LO16:
- return "R_HEX_LO16";
- case llvm::ELF::R_HEX_HI16:
- return "R_HEX_HI16";
- case llvm::ELF::R_HEX_32:
- return "R_HEX_32";
- default:
- return "none";
- }
-}
-
-bool HexagonKindHandler::isCallSite(Kind kind) {
- llvm_unreachable("Unimplemented: HexagonKindHandler::isCallSite");
- return false;
-}
-
-bool HexagonKindHandler::isPointer(Kind kind) {
- llvm_unreachable("Unimplemented: HexagonKindHandler::isPointer");
- return false;
-}
-
-bool HexagonKindHandler::isLazyImmediate(Kind kind) {
- llvm_unreachable("Unimplemented: HexagonKindHandler::isLazyImmediate");
- return false;
-}
-
-bool HexagonKindHandler::isLazyTarget(Kind kind) {
- llvm_unreachable("Unimplemented: HexagonKindHandler::isLazyTarget");
- return false;
-}
-
-void HexagonKindHandler::applyFixup(int32_t reloc, uint64_t addend,
- uint8_t *location, uint64_t fixupAddress,
- uint64_t targetAddress) {
- int error;
- if (_fixupHandler[reloc])
- {
- error = (_fixupHandler[reloc])(location,
- fixupAddress, targetAddress, addend);
-
- switch ((RelocationError)error) {
- case NoError:
- return;
- case Overflow:
- llvm::report_fatal_error("applyFixup relocation overflow");
- return;
- }
- }
-}
-
-
-} // namespace elf
-} // namespace lld
Modified: lld/trunk/lib/ReaderWriter/ELF/PPC/PPCTargetHandler.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/PPC/PPCTargetHandler.cpp?rev=173912&r1=173911&r2=173912&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/PPC/PPCTargetHandler.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/PPC/PPCTargetHandler.cpp Wed Jan 30 01:46:54 2013
@@ -29,9 +29,9 @@ int relocB24PCREL(uint8_t *location, uin
result &= ~-(0x1000000);
*reinterpret_cast<llvm::support::ubig32_t *>(location) = result |
(uint32_t)*reinterpret_cast<llvm::support::ubig32_t *>(location);
- return PPCKindHandler::NoError;
+ return 0;
}
- return PPCKindHandler::Overflow;
+ return 1;
}
} // end anon namespace
Removed: lld/trunk/lib/ReaderWriter/ELF/PPCReference.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/PPCReference.cpp?rev=173911&view=auto
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/PPCReference.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/PPCReference.cpp (removed)
@@ -1,115 +0,0 @@
-//===- lib/ReaderWriter/ELF/PPCReference.cpp ----------------------------===//
-//
-// The LLVM Linker
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-
-#include "ReferenceKinds.h"
-
-#include "llvm/ADT/StringRef.h"
-#include "llvm/ADT/StringSwitch.h"
-#include "llvm/Support/Endian.h"
-#include "llvm/Support/ErrorHandling.h"
-#include "llvm/Support/ELF.h"
-
-namespace lld {
-namespace elf {
-
-//===----------------------------------------------------------------------===//
-// PPCKindHandler
-// TODO: more to do here
-//===----------------------------------------------------------------------===//
-
-PPCKindHandler::~PPCKindHandler() {
-}
-
-/// \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 ppc {
-int relocNONE(uint8_t *location, uint64_t P, uint64_t S, uint64_t A) {
- return PPCKindHandler::NoError;
-}
-
-/// \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;
-}
-} // namespace ppc
-
-PPCKindHandler::PPCKindHandler(llvm::support::endianness endian){
- _fixupHandler[llvm::ELF::R_PPC_REL24] = ppc::relocB24PCREL;
-}
-
-Reference::Kind PPCKindHandler::stringToKind(StringRef str) {
- return llvm::StringSwitch<Reference::Kind>(str)
- .Case("none", none)
- .Case("R_PPC_REL24", llvm::ELF::R_PPC_REL24)
- .Default(invalid);
-}
-
-StringRef PPCKindHandler::kindToString(Reference::Kind kind) {
- switch ((int32_t)kind) {
- case llvm::ELF::R_PPC_REL24:
- return "R_PPC_REL24";
- default:
- return "none";
- }
-}
-
-bool PPCKindHandler::isCallSite(Kind kind) {
- llvm_unreachable("Unimplemented: PPCKindHandler::isCallSite");
- return false;
-}
-
-bool PPCKindHandler::isPointer(Kind kind) {
- llvm_unreachable("Unimplemented: PPCKindHandler::isPointer");
- return false;
-}
-
-bool PPCKindHandler::isLazyImmediate(Kind kind) {
- llvm_unreachable("Unimplemented: PPCKindHandler::isLazyImmediate");
- return false;
-}
-
-bool PPCKindHandler::isLazyTarget(Kind kind) {
- llvm_unreachable("Unimplemented: PPCKindHandler::isLazyTarget");
- return false;
-}
-
-void PPCKindHandler::applyFixup(int32_t reloc, uint64_t addend,
- uint8_t *location, uint64_t fixupAddress,
- uint64_t targetAddress) {
- int error;
- if (_fixupHandler[reloc])
- {
- error = (_fixupHandler[reloc])(location,
- fixupAddress, targetAddress, addend);
-
- switch ((RelocationError)error) {
- case NoError:
- return;
- case Overflow:
- llvm::report_fatal_error("applyFixup relocation overflow");
- return;
- }
- }
-}
-
-} // namespace elf
-} // namespace lld
Removed: lld/trunk/lib/ReaderWriter/ELF/ReferenceKinds.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/ReferenceKinds.cpp?rev=173911&view=auto
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/ReferenceKinds.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/ReferenceKinds.cpp (removed)
@@ -1,42 +0,0 @@
-//===- lib/ReaderWriter/ELF/ReferenceKinds.cpp ----------------------------===//
-//
-// The LLVM Linker
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include "ReferenceKinds.h"
-
-#include "llvm/ADT/StringRef.h"
-#include "llvm/ADT/StringSwitch.h"
-#include "llvm/ADT/Triple.h"
-#include "llvm/Support/ELF.h"
-#include "llvm/Support/ErrorHandling.h"
-
-namespace lld {
-namespace elf {
-KindHandler::KindHandler() {}
-
-KindHandler::~KindHandler() {}
-
-std::unique_ptr<KindHandler>
-KindHandler::makeHandler(llvm::Triple::ArchType arch, bool isLittleEndian) {
- switch(arch) {
- case llvm::Triple::hexagon:
- return std::unique_ptr<KindHandler>(new HexagonKindHandler());
- case llvm::Triple::x86:
- return std::unique_ptr<KindHandler>(new X86KindHandler());
- case llvm::Triple::x86_64:
- return std::unique_ptr<KindHandler>(new X86_64KindHandler());
- case llvm::Triple::ppc:
- return std::unique_ptr<KindHandler>(
- new PPCKindHandler(isLittleEndian ? llvm::support::little
- : llvm::support::big));
- default:
- llvm_unreachable("arch not supported");
- }
-}
-} // namespace elf
-} // namespace lld
Removed: lld/trunk/lib/ReaderWriter/ELF/ReferenceKinds.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/ReferenceKinds.h?rev=173911&view=auto
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/ReferenceKinds.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/ReferenceKinds.h (removed)
@@ -1,181 +0,0 @@
-//===- lib/ReaderWriter/ELF/ReferenceKinds.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_REFERENCE_KINDS_H
-#define LLD_READER_WRITER_ELF_REFERENCE_KINDS_H
-
-#include "lld/Core/LLVM.h"
-#include "lld/Core/Reference.h"
-#include "lld/ReaderWriter/Writer.h"
-
-#include "llvm/ADT/DenseMap.h"
-#include "llvm/ADT/Triple.h"
-#include "llvm/Support/ELF.h"
-#include "llvm/Support/Endian.h"
-
-#include <functional>
-#include <map>
-#include <memory>
-
-namespace lld {
-namespace elf {
-/// \brief the abstract interface to Reference::Kind values for ELF files.
-///
-/// Particular Kind values (e.g. 3) has a different meaning for each
-/// architecture.
-///
-/// TODO: Needs to be updated for ELF, stubs for now.
-class KindHandler {
-public:
- typedef Reference::Kind Kind;
-
- static std::unique_ptr<KindHandler> makeHandler(llvm::Triple::ArchType arch,
- bool isLittleEndian);
- virtual ~KindHandler();
- virtual Kind stringToKind(StringRef str) = 0;
- virtual StringRef kindToString(Kind) = 0;
- virtual bool isCallSite(Kind) = 0;
- virtual bool isPointer(Kind) = 0;
- virtual bool isLazyImmediate(Kind) = 0;
- virtual bool isLazyTarget(Kind) = 0;
- virtual void applyFixup(int32_t reloc, uint64_t addend,
- uint8_t *location,
- uint64_t fixupAddress,
- uint64_t targetAddress) = 0;
-
-protected:
- KindHandler();
-};
-
-class HexagonKindHandler : public KindHandler {
-public:
- // Note: Reference::Kinds are a another representation of relocation types,
- // using negative values to represent architecture independent reference type.
- // The positive values are the same ones defined in ELF.h and that is what we
- // are using.
- enum Kinds {
- none = llvm::ELF::R_HEX_NONE,
- invalid = 255 // used to denote an error creating a Reference
- };
-
- enum RelocationError {
- NoError,
- Overflow
- };
-
- virtual ~HexagonKindHandler();
- HexagonKindHandler();
- virtual Kind stringToKind(StringRef str);
- virtual StringRef kindToString(Kind);
- virtual bool isCallSite(Kind);
- virtual bool isPointer(Kind);
- virtual bool isLazyImmediate(Kind);
- virtual bool isLazyTarget(Kind);
- virtual void applyFixup(int32_t reloc, uint64_t addend,
- uint8_t *location,
- uint64_t fixupAddress, uint64_t targetAddress);
-
-private:
- // A map is used here and in the other handlers but if performace overhead
- // becomes an issue this could be implemented as an array of function
- // pointers.
- llvm::DenseMap<int32_t,
- std::function<int (uint8_t *location, uint64_t fixupAddress,
- uint64_t targetAddress, uint64_t addend)> > _fixupHandler;
-};
-
-class X86KindHandler : public KindHandler {
-public:
- enum Kinds {
- invalid, // used to denote an error creating a Reference
- none,
- };
-
- enum RelocationError {
- NoError,
- };
-
- virtual ~X86KindHandler();
- X86KindHandler();
- virtual Kind stringToKind(StringRef str);
- virtual StringRef kindToString(Kind);
- virtual bool isCallSite(Kind);
- virtual bool isPointer(Kind);
- virtual bool isLazyImmediate(Kind);
- virtual bool isLazyTarget(Kind);
- virtual void applyFixup(int32_t reloc, uint64_t addend, uint8_t *location,
- uint64_t fixupAddress, uint64_t targetAddress);
-
-private:
- llvm::DenseMap<int32_t,
- std::function<int (uint8_t *location, uint64_t fixupAddress,
- uint64_t targetAddress, uint64_t addend)> > _fixupHandler;
-};
-
-class X86_64KindHandler : public KindHandler {
-public:
- enum Kinds {
- invalid, // used to denote an error creating a Reference
- none,
- };
-
- enum RelocationError {
- NoError,
- };
-
- virtual ~X86_64KindHandler();
- X86_64KindHandler();
- virtual Kind stringToKind(StringRef str);
- virtual StringRef kindToString(Kind);
- virtual bool isCallSite(Kind);
- virtual bool isPointer(Kind);
- virtual bool isLazyImmediate(Kind);
- virtual bool isLazyTarget(Kind);
- virtual void applyFixup(int32_t reloc, uint64_t addend, uint8_t *location,
- uint64_t fixupAddress, uint64_t targetAddress);
-
-private:
- llvm::DenseMap<int32_t,
- std::function<int (uint8_t *location, uint64_t fixupAddress,
- uint64_t targetAddress, uint64_t addend)> > _fixupHandler;
-};
-
-class PPCKindHandler : public KindHandler {
-public:
- enum Kinds {
- none = llvm::ELF::R_PPC_NONE,
- invalid = 255, // used to denote an error creating a Reference
- };
-
- enum RelocationError {
- NoError,
- Overflow
- };
-
- virtual ~PPCKindHandler();
- PPCKindHandler(llvm::support::endianness endian);
- virtual Kind stringToKind(StringRef str);
- virtual StringRef kindToString(Kind);
- virtual bool isCallSite(Kind);
- virtual bool isPointer(Kind);
- virtual bool isLazyImmediate(Kind);
- virtual bool isLazyTarget(Kind);
- virtual void applyFixup(int32_t reloc, uint64_t addend,
- uint8_t *location,
- uint64_t fixupAddress, uint64_t targetAddress);
-
-private:
- llvm::DenseMap<int32_t,
- std::function<int (uint8_t *location, uint64_t fixupAddress,
- uint64_t targetAddress, uint64_t addend)> > _fixupHandler;
-};
-} // end namespace elf
-} // end namespace lld
-
-#endif
Modified: lld/trunk/lib/ReaderWriter/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Writer.cpp?rev=173912&r1=173911&r2=173912&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Writer.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Writer.cpp Wed Jan 30 01:46:54 2013
@@ -50,15 +50,12 @@ private:
return _atomToAddressMap[atom];
}
- KindHandler *kindHandler() { return _referenceKindHandler.get(); }
-
void createDefaultSections();
const ELFTargetInfo &_targetInfo;
TargetHandler<ELFT> &_targetHandler;
typedef llvm::DenseMap<const Atom *, uint64_t> AtomToAddress;
- std::unique_ptr<KindHandler> _referenceKindHandler;
AtomToAddress _atomToAddressMap;
llvm::BumpPtrAllocator _chunkAllocate;
TargetLayout<ELFT> *_layout;
@@ -77,8 +74,6 @@ private:
template <class ELFT>
ExecutableWriter<ELFT>::ExecutableWriter(const ELFTargetInfo &ti)
: _targetInfo(ti), _targetHandler(ti.getTargetHandler<ELFT>()),
- _referenceKindHandler(KindHandler::makeHandler(ti.getTriple().getArch(),
- ti.isLittleEndian())),
_runtimeFile(ti) {
_layout = new TargetLayout<ELFT>(_targetInfo);
}
Modified: lld/trunk/lib/ReaderWriter/ELF/Writer.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Writer.h?rev=173912&r1=173911&r2=173912&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Writer.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Writer.h Wed Jan 30 01:46:54 2013
@@ -10,8 +10,6 @@
#ifndef LLD_READER_WRITER_ELF_WRITER_H
#define LLD_READER_WRITER_ELF_WRITER_H
-#include "ReferenceKinds.h"
-
#include "lld/Core/File.h"
#include "lld/Core/InputFiles.h"
#include "lld/ReaderWriter/Writer.h"
@@ -34,9 +32,6 @@ public:
/// \brief Get the virtual address of \p atom after layout.
virtual uint64_t addressOfAtom(const Atom *atom) = 0;
-
- /// \brief Return the processing function to apply Relocations
- virtual KindHandler *kindHandler() = 0;
};
} // end namespace elf
} // end namespace lld
Modified: lld/trunk/lib/ReaderWriter/ELF/X86/X86TargetHandler.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/X86/X86TargetHandler.cpp?rev=173912&r1=173911&r2=173912&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/X86/X86TargetHandler.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/X86/X86TargetHandler.cpp Wed Jan 30 01:46:54 2013
@@ -21,7 +21,7 @@ int reloc32(uint8_t *location, uint64_t
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;
+ return 0;
}
/// \brief R_386_PC32 - word32: S + A - P
@@ -29,7 +29,7 @@ int relocPC32(uint8_t *location, uint64_
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;
+ return 0;
}
} // end anon namespace
Removed: lld/trunk/lib/ReaderWriter/ELF/X86Reference.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/X86Reference.cpp?rev=173911&view=auto
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/X86Reference.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/X86Reference.cpp (removed)
@@ -1,111 +0,0 @@
-//===- lib/ReaderWriter/ELF/X86Reference.cpp ----------------------------===//
-//
-// The LLVM Linker
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-///
-/// \file
-/// The following relocation routines are derived from the
-/// SYSTEM V APPLICATION BINARY INTERFACE: Intel386 Architecture Processor
-/// Supplement (Fourth Edition)
-/// Symbols used:
-/// P: Place, address of the field being relocated, r_offset
-/// S: Value of the symbol whose index resides in the relocation entry.
-/// A: Addend used to compute the value, r_addend
-///
-//===----------------------------------------------------------------------===//
-
-#include "ReferenceKinds.h"
-
-#include "llvm/ADT/StringRef.h"
-#include "llvm/ADT/StringSwitch.h"
-#include "llvm/Support/ELF.h"
-#include "llvm/Support/Endian.h"
-#include "llvm/Support/ErrorHandling.h"
-
-namespace lld {
-namespace elf {
-X86KindHandler::~X86KindHandler() {
-}
-
-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
-
-X86KindHandler::X86KindHandler(){
- _fixupHandler[llvm::ELF::R_386_32] = reloc32;
- _fixupHandler[llvm::ELF::R_386_PC32] = relocPC32;
-}
-
-Reference::Kind X86KindHandler::stringToKind(StringRef str) {
- return llvm::StringSwitch<Reference::Kind>(str)
- .Case("none", none)
- .Case("R_386_32", llvm::ELF::R_386_32)
- .Case("R_386_PC32", llvm::ELF::R_386_PC32)
- .Default(invalid);
-}
-
-StringRef X86KindHandler::kindToString(Reference::Kind kind) {
- switch ((int32_t)kind) {
- case llvm::ELF::R_386_32:
- return "R_386_32";
- case llvm::ELF::R_386_PC32:
- return "R_386_PC32";
- default:
- return "none";
- }
-}
-
-bool X86KindHandler::isCallSite(Kind kind) {
- llvm_unreachable("Unimplemented: X86KindHandler::isCallSite");
- return false;
-}
-
-bool X86KindHandler::isPointer(Kind kind) {
- llvm_unreachable("Unimplemented: X86KindHandler::isPointer");
- return false;
-}
-
-bool X86KindHandler::isLazyImmediate(Kind kind) {
- llvm_unreachable("Unimplemented: X86KindHandler::isLazyImmediate");
- return false;
-}
-
-bool X86KindHandler::isLazyTarget(Kind kind) {
- llvm_unreachable("Unimplemented: X86KindHandler::isLazyTarget");
- return false;
-}
-
-void X86KindHandler::applyFixup(int32_t reloc, uint64_t addend,
- uint8_t *location, uint64_t fixupAddress,
- uint64_t targetAddress) {
- int error;
- if (_fixupHandler[reloc]) {
- error = (_fixupHandler[reloc])(location,
- fixupAddress, targetAddress, addend);
-
- switch ((RelocationError)error) {
- case NoError:
- return;
- }
- }
-}
-} // end namespace elf
-} // end namespace lld
Removed: lld/trunk/lib/ReaderWriter/ELF/X86_64Reference.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/X86_64Reference.cpp?rev=173911&view=auto
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/X86_64Reference.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/X86_64Reference.cpp (removed)
@@ -1,125 +0,0 @@
-//===- lib/ReaderWriter/ELF/X86_64Reference.cpp ---------------------------===//
-//
-// The LLVM Linker
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include "ReferenceKinds.h"
-
-#include "llvm/ADT/StringRef.h"
-#include "llvm/ADT/StringSwitch.h"
-
-#include "llvm/Support/ELF.h"
-#include "llvm/Support/Endian.h"
-#include "llvm/Support/ErrorHandling.h"
-#include "llvm/Support/raw_ostream.h"
-
-using namespace llvm::ELF;
-
-namespace {
-/// \brief R_X86_64_64 - word64: S + A
-int reloc64(uint8_t *location, uint64_t P, uint64_t S, uint64_t A) {
- uint64_t result = S + A;
- *reinterpret_cast<llvm::support::ulittle64_t *>(location) = result |
- (uint64_t)*reinterpret_cast<llvm::support::ulittle64_t *>(location);
- return 0;
-}
-
-/// \brief R_X86_64_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 0;
-}
-
-/// \brief R_X86_64_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);
- // TODO: Make sure that the result zero extends to the 64bit value.
- return 0;
-}
-
-/// \brief R_X86_64_32S - word32: S + A
-int reloc32S(uint8_t *location, uint64_t P, uint64_t S, uint64_t A) {
- int32_t result = (int32_t)(S + A);
- *reinterpret_cast<llvm::support::little32_t *>(location) = result |
- (int32_t)*reinterpret_cast<llvm::support::little32_t *>(location);
- // TODO: Make sure that the result sign extends to the 64bit value.
- return 0;
-}
-} // end anon namespace
-
-namespace lld {
-namespace elf {
-X86_64KindHandler::X86_64KindHandler(){
- _fixupHandler[R_X86_64_64] = reloc64;
- _fixupHandler[R_X86_64_PC32] = relocPC32;
- _fixupHandler[R_X86_64_32] = reloc32;
- _fixupHandler[R_X86_64_32S] = reloc32S;
-}
-
-X86_64KindHandler::~X86_64KindHandler() {
-}
-
-Reference::Kind X86_64KindHandler::stringToKind(StringRef str) {
- return llvm::StringSwitch<Reference::Kind>(str)
- .Case("none", none)
- .Case("R_X86_64_64", R_X86_64_64)
- .Case("R_X86_64_PC32", R_X86_64_PC32)
- .Case("R_X86_64_32S", R_X86_64_32S)
- .Default(invalid);
-}
-
-StringRef X86_64KindHandler::kindToString(Reference::Kind kind) {
- switch ((int32_t)kind) {
- case R_X86_64_64:
- return "R_X86_64_64";
- case R_X86_64_PC32:
- return "R_X86_64_PC32";
- case R_X86_64_32S:
- return "R_X86_64_32S";
- default:
- return "none";
- }
-}
-
-bool X86_64KindHandler::isCallSite(Kind kind) {
- llvm_unreachable("Unimplemented: X86KindHandler::isCallSite");
- return false;
-}
-
-bool X86_64KindHandler::isPointer(Kind kind) {
- llvm_unreachable("Unimplemented: X86KindHandler::isPointer");
- return false;
-}
-
-bool X86_64KindHandler::isLazyImmediate(Kind kind) {
- llvm_unreachable("Unimplemented: X86KindHandler::isLazyImmediate");
- return false;
-}
-
-bool X86_64KindHandler::isLazyTarget(Kind kind) {
- llvm_unreachable("Unimplemented: X86KindHandler::isLazyTarget");
- return false;
-}
-
-void X86_64KindHandler::applyFixup(int32_t reloc, uint64_t addend,
- uint8_t *location, uint64_t fixupAddress,
- uint64_t targetAddress) {
- if (reloc == llvm::ELF::R_X86_64_IRELATIVE)
- return;
- if (_fixupHandler[reloc])
- _fixupHandler[reloc](location, fixupAddress, targetAddress, addend);
- else {
- llvm::errs() << "Unknown relocation type: " << reloc << "\n";
- llvm_unreachable("Unknown relocation type.");
- }
-}
-} // end namespace elf
-} // end namespace lld
More information about the llvm-commits
mailing list