summaryrefslogtreecommitdiffstats
path: root/lld/lib/ReaderWriter/ELF/Mips/MipsLinkingContext.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/Mips/MipsLinkingContext.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/Mips/MipsLinkingContext.cpp')
-rw-r--r--lld/lib/ReaderWriter/ELF/Mips/MipsLinkingContext.cpp51
1 files changed, 7 insertions, 44 deletions
diff --git a/lld/lib/ReaderWriter/ELF/Mips/MipsLinkingContext.cpp b/lld/lib/ReaderWriter/ELF/Mips/MipsLinkingContext.cpp
index 24718a3e3d4..6d7b6a16251 100644
--- a/lld/lib/ReaderWriter/ELF/Mips/MipsLinkingContext.cpp
+++ b/lld/lib/ReaderWriter/ELF/Mips/MipsLinkingContext.cpp
@@ -55,7 +55,7 @@ public:
class MipsGOTPassFile : public SimpleFile {
public:
MipsGOTPassFile(const ELFLinkingContext &ctx)
- : SimpleFile(ctx, "MipsGOTPassFile") {
+ : SimpleFile("MipsGOTPassFile") {
setOrdinal(ctx.getNextOrdinalAndIncrement());
}
@@ -113,7 +113,10 @@ private:
/// \brief Handle a specific reference.
void handleReference(const DefinedAtom &atom, const Reference &ref) {
- switch (ref.kind()) {
+ if (ref.kindNamespace() != lld::Reference::KindNamespace::ELF)
+ return;
+ assert(ref.kindArch() == Reference::KindArch::Mips);
+ switch (ref.kindValue()) {
case R_MIPS_GOT16:
case R_MIPS_CALL16:
handleGOT(ref);
@@ -139,9 +142,9 @@ private:
_localGotVector.push_back(ga);
else {
if (da)
- ga->addReference(R_MIPS_32, 0, a, 0);
+ ga->addReferenceELF_Mips(R_MIPS_32, 0, a, 0);
else
- ga->addReference(R_MIPS_NONE, 0, a, 0);
+ ga->addReferenceELF_Mips(R_MIPS_NONE, 0, a, 0);
_globalGotVector.push_back(ga);
}
@@ -177,46 +180,6 @@ bool MipsLinkingContext::isLittleEndian() const {
return Mips32ElELFType::TargetEndianness == llvm::support::little;
}
-#undef LLD_CASE
-#define LLD_CASE(name) .Case(#name, llvm::ELF::name)
-
-ErrorOr<Reference::Kind>
-MipsLinkingContext::relocKindFromString(StringRef str) const {
- int32_t ret = llvm::StringSwitch<int32_t>(str)
- LLD_CASE(R_MIPS_NONE)
- LLD_CASE(R_MIPS_32)
- LLD_CASE(R_MIPS_HI16)
- LLD_CASE(R_MIPS_LO16)
- LLD_CASE(R_MIPS_GOT16)
- LLD_CASE(R_MIPS_CALL16)
- LLD_CASE(R_MIPS_JALR)
- .Default(-1);
-
- if (ret == -1)
- return make_error_code(YamlReaderError::illegal_value);
- return ret;
-}
-
-#undef LLD_CASE
-#define LLD_CASE(name) \
- case llvm::ELF::name: \
- return std::string(#name);
-
-ErrorOr<std::string>
-MipsLinkingContext::stringFromRelocKind(Reference::Kind kind) const {
- switch (kind) {
- LLD_CASE(R_MIPS_NONE)
- LLD_CASE(R_MIPS_32)
- LLD_CASE(R_MIPS_HI16)
- LLD_CASE(R_MIPS_LO16)
- LLD_CASE(R_MIPS_GOT16)
- LLD_CASE(R_MIPS_CALL16)
- LLD_CASE(R_MIPS_JALR)
- }
-
- return make_error_code(YamlReaderError::illegal_value);
-}
-
void MipsLinkingContext::addPasses(PassManager &pm) {
switch (getOutputELFType()) {
case llvm::ELF::ET_DYN:
OpenPOWER on IntegriCloud