diff --git a/llvm/lib/Target/Sparc/MCTargetDesc/SparcAsmBackend.cpp b/llvm/lib/Target/Sparc/MCTargetDesc/SparcAsmBackend.cpp --- a/llvm/lib/Target/Sparc/MCTargetDesc/SparcAsmBackend.cpp +++ b/llvm/lib/Target/Sparc/MCTargetDesc/SparcAsmBackend.cpp @@ -8,6 +8,7 @@ #include "MCTargetDesc/SparcFixupKinds.h" #include "MCTargetDesc/SparcMCTargetDesc.h" +#include "llvm/ADT/StringSwitch.h" #include "llvm/MC/MCAsmBackend.h" #include "llvm/MC/MCELFObjectWriter.h" #include "llvm/MC/MCExpr.h" @@ -24,6 +25,8 @@ switch (Kind) { default: llvm_unreachable("Unknown fixup kind!"); + case FK_NONE: + return 0; case FK_Data_1: case FK_Data_2: case FK_Data_4: @@ -131,6 +134,23 @@ return Sparc::NumTargetFixupKinds; } + Optional getFixupKind(StringRef Name) const override { + unsigned Type; + Type = llvm::StringSwitch(Name) +#define ELF_RELOC(X, Y) .Case(#X, Y) +#include "llvm/BinaryFormat/ELFRelocs/Sparc.def" +#undef ELF_RELOC + .Case("BFD_RELOC_NONE", ELF::R_SPARC_NONE) + .Case("BFD_RELOC_8", ELF::R_SPARC_8) + .Case("BFD_RELOC_16", ELF::R_SPARC_16) + .Case("BFD_RELOC_32", ELF::R_SPARC_32) + .Case("BFD_RELOC_64", ELF::R_SPARC_64) + .Default(-1u); + if (Type == -1u) + return None; + return static_cast(FirstLiteralRelocationKind + Type); + } + const MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const override { const static MCFixupKindInfo InfosBE[Sparc::NumTargetFixupKinds] = { // name offset bits flags @@ -216,6 +236,11 @@ { "fixup_sparc_tls_le_lox10", 0, 0, 0 } }; + // Fixup kinds from .reloc directive are like R_SPARC_NONE. They do + // not require any extra processing. + if (Kind >= FirstLiteralRelocationKind) + return MCAsmBackend::getFixupKindInfo(FK_NONE); + if (Kind < FirstTargetFixupKind) return MCAsmBackend::getFixupKindInfo(Kind); @@ -229,6 +254,8 @@ bool shouldForceRelocation(const MCAssembler &Asm, const MCFixup &Fixup, const MCValue &Target) override { + if (Fixup.getKind() >= FirstLiteralRelocationKind) + return true; switch ((Sparc::Fixups)Fixup.getKind()) { default: return false; @@ -299,6 +326,8 @@ uint64_t Value, bool IsResolved, const MCSubtargetInfo *STI) const override { + if (Fixup.getKind() >= FirstLiteralRelocationKind) + return; Value = adjustFixupValue(Fixup.getKind(), Value); if (!Value) return; // Doesn't change encoding. diff --git a/llvm/lib/Target/Sparc/MCTargetDesc/SparcELFObjectWriter.cpp b/llvm/lib/Target/Sparc/MCTargetDesc/SparcELFObjectWriter.cpp --- a/llvm/lib/Target/Sparc/MCTargetDesc/SparcELFObjectWriter.cpp +++ b/llvm/lib/Target/Sparc/MCTargetDesc/SparcELFObjectWriter.cpp @@ -42,6 +42,9 @@ const MCValue &Target, const MCFixup &Fixup, bool IsPCRel) const { + MCFixupKind Kind = Fixup.getKind(); + if (Kind >= FirstLiteralRelocationKind) + return Kind - FirstLiteralRelocationKind; if (const SparcMCExpr *SExpr = dyn_cast(Fixup.getValue())) { if (SExpr->getKind() == SparcMCExpr::VK_Sparc_R_DISP32) @@ -68,6 +71,7 @@ switch(Fixup.getTargetKind()) { default: llvm_unreachable("Unimplemented fixup -> relocation"); + case FK_NONE: return ELF::R_SPARC_NONE; case FK_Data_1: return ELF::R_SPARC_8; case FK_Data_2: return ((Fixup.getOffset() % 2) ? ELF::R_SPARC_UA16