[PATCH] D118136: [Sparc] Implement BFD_RELOC_NONE
Rainer Orth via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 25 05:34:56 PST 2022
ro created this revision.
ro added reviewers: joerg, RKSimon, MaskRay.
Herald added subscribers: pengfei, jrtc27, fedor.sergeev, hiraditya, jyknight.
ro requested review of this revision.
Herald added a project: LLVM.
`instrprof-icall-promo.test` `FAIL`s on Solaris/sparcv9:
Profile-sparc :: instrprof-icall-promo.test
Profile-sparcv9 :: instrprof-icall-promo.test
when compiling `compiler-rt/test/profile/Inputs/instrprof-icall-promo_2.cpp` with
fatal error: error in backend: Relocation for CG Profile could not be created: unknown relocation name
This happens because the Sparc backend doesn't implement `BFD_RELOC_NONE`. This patch fixes that, following what X86 does.
Tested on `sparcv9-sun-solaris2.11`.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D118136
Files:
llvm/lib/Target/Sparc/MCTargetDesc/SparcAsmBackend.cpp
llvm/lib/Target/Sparc/MCTargetDesc/SparcELFObjectWriter.cpp
Index: llvm/lib/Target/Sparc/MCTargetDesc/SparcELFObjectWriter.cpp
===================================================================
--- llvm/lib/Target/Sparc/MCTargetDesc/SparcELFObjectWriter.cpp
+++ 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<SparcMCExpr>(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
Index: llvm/lib/Target/Sparc/MCTargetDesc/SparcAsmBackend.cpp
===================================================================
--- llvm/lib/Target/Sparc/MCTargetDesc/SparcAsmBackend.cpp
+++ 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<MCFixupKind> getFixupKind(StringRef Name) const override {
+ unsigned Type;
+ Type = llvm::StringSwitch<unsigned>(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<MCFixupKind>(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.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D118136.402870.patch
Type: text/x-patch
Size: 3865 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220125/91c89ca9/attachment.bin>
More information about the llvm-commits
mailing list