summaryrefslogtreecommitdiffstats
path: root/lld/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.cpp
diff options
context:
space:
mode:
authorNick Kledzik <kledzik@apple.com>2013-12-19 21:58:00 +0000
committerNick Kledzik <kledzik@apple.com>2013-12-19 21:58:00 +0000
commite555277780fc1bfd3c1fccf6b6ab905cc89c993a (patch)
tree88b653613f4cbd836edb0d36dfb28187e917a729 /lld/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.cpp
parent61a57138c281ecc7ed40e9c9068b3fb5ee8c4b11 (diff)
downloadbcm5719-llvm-e555277780fc1bfd3c1fccf6b6ab905cc89c993a.tar.gz
bcm5719-llvm-e555277780fc1bfd3c1fccf6b6ab905cc89c993a.zip
[lld] Introduce registry and Reference kind tuple
The main changes are in: include/lld/Core/Reference.h include/lld/ReaderWriter/Reader.h Everything else is details to support the main change. 1) Registration based Readers Previously, lld had a tangled interdependency with all the Readers. It would have been impossible to make a streamlined linker (say for a JIT) which just supported one file format and one architecture (no yaml, no archives, etc). The old model also required a LinkingContext to read an object file, which would have made .o inspection tools awkward. The new model is that there is a global Registry object. You programmatically register the Readers you want with the registry object. Whenever you need to read/parse a file, you ask the registry to do it, and the registry tries each registered reader. For ease of use with the existing lld code base, there is one Registry object inside the LinkingContext object. 2) Changing kind value to be a tuple Beside Readers, the registry also keeps track of the mapping for Reference Kind values to and from strings. Along with that, this patch also fixes an ambiguity with the previous Reference::Kind values. The problem was that we wanted to reuse existing relocation type values as Reference::Kind values. But then how can the YAML write know how to convert a value to a string? The fix is to change the 32-bit Reference::Kind into a tuple with an 8-bit namespace (e.g. ELF, COFFF, etc), an 8-bit architecture (e.g. x86_64, PowerPC, etc), and a 16-bit value. This tuple system allows conversion to and from strings with no ambiguities. llvm-svn: 197727
Diffstat (limited to 'lld/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.cpp')
-rw-r--r--lld/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.cpp129
1 files changed, 119 insertions, 10 deletions
diff --git a/lld/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.cpp b/lld/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.cpp
index 87f67e52da5..cfa17b00f94 100644
--- a/lld/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.cpp
+++ b/lld/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.cpp
@@ -108,7 +108,8 @@ public:
class ELFPassFile : public SimpleFile {
public:
- ELFPassFile(const ELFLinkingContext &eti) : SimpleFile(eti, "ELFPassFile") {
+ ELFPassFile(const ELFLinkingContext &eti)
+ : SimpleFile("ELFPassFile") {
setOrdinal(eti.getNextOrdinalAndIncrement());
}
@@ -119,7 +120,10 @@ public:
template <class Derived> class GOTPLTPass : public Pass {
/// \brief Handle a specific reference.
void handleReference(const DefinedAtom &atom, const Reference &ref) {
- switch (ref.kind()) {
+ if (ref.kindNamespace() != Reference::KindNamespace::ELF)
+ return;
+ assert(ref.kindArch() == Reference::KindArch::Hexagon);
+ switch (ref.kindValue()) {
case R_HEX_PLT_B22_PCREL:
case R_HEX_B22_PCREL:
static_cast<Derived *>(this)->handlePLT32(ref);
@@ -226,8 +230,8 @@ public:
if (_PLT0)
return _PLT0;
_PLT0 = new (_file._alloc) HexagonPLT0Atom(_file);
- _PLT0->addReference(R_HEX_B32_PCREL_X, 0, _got0, 0);
- _PLT0->addReference(R_HEX_6_PCREL_X, 4, _got0, 4);
+ _PLT0->addReferenceELF_Hexagon(R_HEX_B32_PCREL_X, 0, _got0, 0);
+ _PLT0->addReferenceELF_Hexagon(R_HEX_6_PCREL_X, 4, _got0, 4);
DEBUG_WITH_TYPE("PLT", llvm::dbgs() << "[ PLT0/GOT0 ] "
<< "Adding plt0/got0 \n");
return _PLT0;
@@ -238,13 +242,13 @@ public:
if (plt != _pltMap.end())
return plt->second;
auto ga = new (_file._alloc) HexagonGOTPLTAtom(_file);
- ga->addReference(R_HEX_JMP_SLOT, 0, a, 0);
+ ga->addReferenceELF_Hexagon(R_HEX_JMP_SLOT, 0, a, 0);
auto pa = new (_file._alloc) HexagonPLTAtom(_file, ".plt");
- pa->addReference(R_HEX_B32_PCREL_X, 0, ga, 0);
- pa->addReference(R_HEX_6_PCREL_X, 4, ga, 4);
+ pa->addReferenceELF_Hexagon(R_HEX_B32_PCREL_X, 0, ga, 0);
+ pa->addReferenceELF_Hexagon(R_HEX_6_PCREL_X, 4, ga, 4);
// Point the got entry to the PLT0 atom initially
- ga->addReference(R_HEX_32, 0, getPLT0(), 0);
+ ga->addReferenceELF_Hexagon(R_HEX_32, 0, getPLT0(), 0);
#ifndef NDEBUG
ga->_name = "__got_";
ga->_name += a->name();
@@ -266,7 +270,7 @@ public:
if (got != _gotMap.end())
return got->second;
auto ga = new (_file._alloc) HexagonGOTAtom(_file);
- ga->addReference(R_HEX_GLOB_DAT, 0, a, 0);
+ ga->addReferenceELF_Hexagon(R_HEX_GLOB_DAT, 0, a, 0);
#ifndef NDEBUG
ga->_name = "__got_";
@@ -287,7 +291,9 @@ public:
error_code handlePLT32(const Reference &ref) {
// Turn this into a PC32 to the PLT entry.
- const_cast<Reference &>(ref).setKind(R_HEX_B22_PCREL);
+ assert(ref.kindNamespace() == Reference::KindNamespace::ELF);
+ assert(ref.kindArch() == Reference::KindArch::Hexagon);
+ const_cast<Reference &>(ref).setKindValue(R_HEX_B22_PCREL);
const_cast<Reference &>(ref).setTarget(getPLTEntry(ref.target()));
return error_code::success();
}
@@ -299,3 +305,106 @@ void elf::HexagonLinkingContext::addPasses(PassManager &pm) {
pm.add(std::unique_ptr<Pass>(new DynamicGOTPLTPass(*this)));
ELFLinkingContext::addPasses(pm);
}
+
+void HexagonTargetHandler::registerRelocationNames(Registry &registry) {
+ registry.addKindTable(Reference::KindNamespace::ELF,
+ Reference::KindArch::Hexagon,
+ kindStrings);
+}
+
+const Registry::KindStrings HexagonTargetHandler::kindStrings[] = {
+ LLD_KIND_STRING_ENTRY(R_HEX_NONE),
+ LLD_KIND_STRING_ENTRY(R_HEX_B22_PCREL),
+ LLD_KIND_STRING_ENTRY(R_HEX_B15_PCREL),
+ LLD_KIND_STRING_ENTRY(R_HEX_B7_PCREL),
+ LLD_KIND_STRING_ENTRY(R_HEX_LO16),
+ LLD_KIND_STRING_ENTRY(R_HEX_HI16),
+ LLD_KIND_STRING_ENTRY(R_HEX_32),
+ LLD_KIND_STRING_ENTRY(R_HEX_16),
+ LLD_KIND_STRING_ENTRY(R_HEX_8),
+ LLD_KIND_STRING_ENTRY(R_HEX_GPREL16_0),
+ LLD_KIND_STRING_ENTRY(R_HEX_GPREL16_1),
+ LLD_KIND_STRING_ENTRY(R_HEX_GPREL16_2),
+ LLD_KIND_STRING_ENTRY(R_HEX_GPREL16_3),
+ LLD_KIND_STRING_ENTRY(R_HEX_HL16),
+ LLD_KIND_STRING_ENTRY(R_HEX_B13_PCREL),
+ LLD_KIND_STRING_ENTRY(R_HEX_B9_PCREL),
+ LLD_KIND_STRING_ENTRY(R_HEX_B32_PCREL_X),
+ LLD_KIND_STRING_ENTRY(R_HEX_32_6_X),
+ LLD_KIND_STRING_ENTRY(R_HEX_B22_PCREL_X),
+ LLD_KIND_STRING_ENTRY(R_HEX_B15_PCREL_X),
+ LLD_KIND_STRING_ENTRY(R_HEX_B13_PCREL_X),
+ LLD_KIND_STRING_ENTRY(R_HEX_B9_PCREL_X),
+ LLD_KIND_STRING_ENTRY(R_HEX_B7_PCREL_X),
+ LLD_KIND_STRING_ENTRY(R_HEX_16_X),
+ LLD_KIND_STRING_ENTRY(R_HEX_12_X),
+ LLD_KIND_STRING_ENTRY(R_HEX_11_X),
+ LLD_KIND_STRING_ENTRY(R_HEX_10_X),
+ LLD_KIND_STRING_ENTRY(R_HEX_9_X),
+ LLD_KIND_STRING_ENTRY(R_HEX_8_X),
+ LLD_KIND_STRING_ENTRY(R_HEX_7_X),
+ LLD_KIND_STRING_ENTRY(R_HEX_6_X),
+ LLD_KIND_STRING_ENTRY(R_HEX_32_PCREL),
+ LLD_KIND_STRING_ENTRY(R_HEX_COPY),
+ LLD_KIND_STRING_ENTRY(R_HEX_GLOB_DAT),
+ LLD_KIND_STRING_ENTRY(R_HEX_JMP_SLOT),
+ LLD_KIND_STRING_ENTRY(R_HEX_RELATIVE),
+ LLD_KIND_STRING_ENTRY(R_HEX_PLT_B22_PCREL),
+ LLD_KIND_STRING_ENTRY(R_HEX_GOTREL_LO16),
+ LLD_KIND_STRING_ENTRY(R_HEX_GOTREL_HI16),
+ LLD_KIND_STRING_ENTRY(R_HEX_GOTREL_32),
+ LLD_KIND_STRING_ENTRY(R_HEX_GOT_LO16),
+ LLD_KIND_STRING_ENTRY(R_HEX_GOT_HI16),
+ LLD_KIND_STRING_ENTRY(R_HEX_GOT_32),
+ LLD_KIND_STRING_ENTRY(R_HEX_GOT_16),
+ LLD_KIND_STRING_ENTRY(R_HEX_DTPMOD_32),
+ LLD_KIND_STRING_ENTRY(R_HEX_DTPREL_LO16),
+ LLD_KIND_STRING_ENTRY(R_HEX_DTPREL_HI16),
+ LLD_KIND_STRING_ENTRY(R_HEX_DTPREL_32),
+ LLD_KIND_STRING_ENTRY(R_HEX_DTPREL_16),
+ LLD_KIND_STRING_ENTRY(R_HEX_GD_PLT_B22_PCREL),
+ LLD_KIND_STRING_ENTRY(R_HEX_GD_GOT_LO16),
+ LLD_KIND_STRING_ENTRY(R_HEX_GD_GOT_HI16),
+ LLD_KIND_STRING_ENTRY(R_HEX_GD_GOT_32),
+ LLD_KIND_STRING_ENTRY(R_HEX_GD_GOT_16),
+ LLD_KIND_STRING_ENTRY(R_HEX_IE_LO16),
+ LLD_KIND_STRING_ENTRY(R_HEX_IE_HI16),
+ LLD_KIND_STRING_ENTRY(R_HEX_IE_32),
+ LLD_KIND_STRING_ENTRY(R_HEX_IE_GOT_LO16),
+ LLD_KIND_STRING_ENTRY(R_HEX_IE_GOT_HI16),
+ LLD_KIND_STRING_ENTRY(R_HEX_IE_GOT_32),
+ LLD_KIND_STRING_ENTRY(R_HEX_IE_GOT_16),
+ LLD_KIND_STRING_ENTRY(R_HEX_TPREL_LO16),
+ LLD_KIND_STRING_ENTRY(R_HEX_TPREL_HI16),
+ LLD_KIND_STRING_ENTRY(R_HEX_TPREL_32),
+ LLD_KIND_STRING_ENTRY(R_HEX_TPREL_16),
+ LLD_KIND_STRING_ENTRY(R_HEX_6_PCREL_X),
+ LLD_KIND_STRING_ENTRY(R_HEX_GOTREL_32_6_X),
+ LLD_KIND_STRING_ENTRY(R_HEX_GOTREL_16_X),
+ LLD_KIND_STRING_ENTRY(R_HEX_GOTREL_11_X),
+ LLD_KIND_STRING_ENTRY(R_HEX_GOT_32_6_X),
+ LLD_KIND_STRING_ENTRY(R_HEX_GOT_16_X),
+ LLD_KIND_STRING_ENTRY(R_HEX_GOT_11_X),
+ LLD_KIND_STRING_ENTRY(R_HEX_DTPREL_32_6_X),
+ LLD_KIND_STRING_ENTRY(R_HEX_DTPREL_16_X),
+ LLD_KIND_STRING_ENTRY(R_HEX_DTPREL_11_X),
+ LLD_KIND_STRING_ENTRY(R_HEX_GD_GOT_32_6_X),
+ LLD_KIND_STRING_ENTRY(R_HEX_GD_GOT_16_X),
+ LLD_KIND_STRING_ENTRY(R_HEX_GD_GOT_11_X),
+ LLD_KIND_STRING_ENTRY(R_HEX_IE_32_6_X),
+ LLD_KIND_STRING_ENTRY(R_HEX_IE_32_6_X),
+ LLD_KIND_STRING_ENTRY(R_HEX_IE_16_X),
+ LLD_KIND_STRING_ENTRY(R_HEX_IE_GOT_32_6_X),
+ LLD_KIND_STRING_ENTRY(R_HEX_IE_GOT_16_X),
+ LLD_KIND_STRING_ENTRY(R_HEX_IE_GOT_11_X),
+ LLD_KIND_STRING_ENTRY(R_HEX_IE_32_6_X),
+ LLD_KIND_STRING_ENTRY(R_HEX_IE_16_X),
+ LLD_KIND_STRING_ENTRY(R_HEX_IE_GOT_32_6_X),
+ LLD_KIND_STRING_ENTRY(R_HEX_IE_GOT_16_X),
+ LLD_KIND_STRING_ENTRY(R_HEX_IE_GOT_11_X),
+ LLD_KIND_STRING_ENTRY(R_HEX_TPREL_32_6_X),
+ LLD_KIND_STRING_ENTRY(R_HEX_TPREL_16_X),
+ LLD_KIND_STRING_ENTRY(R_HEX_TPREL_11_X),
+ LLD_KIND_STRING_END
+};
+
OpenPOWER on IntegriCloud