mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-24 06:26:07 +00:00
[MC] .reloc: move FirstLiteralRelocationKind check to evaluateFixup
Target shouldForceRelocation checks `FirstLiteralRelocationKind` to determine whether a relocation is forced due to the .reloc directive. We should move the code to evaluateFixup so that many targets don't need to override shouldForceRelocation.
This commit is contained in:
parent
687c9d359e
commit
de60c0e034
@ -220,9 +220,10 @@ bool MCAssembler::evaluateFixup(const MCFixup &Fixup, const MCFragment *DF,
|
||||
Value -= Offset;
|
||||
}
|
||||
|
||||
// Let the backend force a relocation if needed.
|
||||
// .reloc directive and the backend might force the relocation.
|
||||
if (IsResolved &&
|
||||
getBackend().shouldForceRelocation(*this, Fixup, Target, Value, STI)) {
|
||||
(Fixup.getKind() >= FirstLiteralRelocationKind ||
|
||||
getBackend().shouldForceRelocation(*this, Fixup, Target, Value, STI))) {
|
||||
IsResolved = false;
|
||||
WasForced = true;
|
||||
}
|
||||
|
@ -522,10 +522,6 @@ bool AArch64AsmBackend::shouldForceRelocation(const MCAssembler &Asm,
|
||||
const MCValue &Target,
|
||||
const uint64_t,
|
||||
const MCSubtargetInfo *STI) {
|
||||
unsigned Kind = Fixup.getKind();
|
||||
if (Kind >= FirstLiteralRelocationKind)
|
||||
return true;
|
||||
|
||||
// The ADRP instruction adds some multiple of 0x1000 to the current PC &
|
||||
// ~0xfff. This means that the required offset to reach a symbol can vary by
|
||||
// up to one step depending on where the ADRP is in memory. For example:
|
||||
@ -538,10 +534,7 @@ bool AArch64AsmBackend::shouldForceRelocation(const MCAssembler &Asm,
|
||||
// same page as the ADRP and the instruction should encode 0x0. Assuming the
|
||||
// section isn't 0x1000-aligned, we therefore need to delegate this decision
|
||||
// to the linker -- a relocation!
|
||||
if (Kind == AArch64::fixup_aarch64_pcrel_adrp_imm21)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
return Fixup.getTargetKind() == AArch64::fixup_aarch64_pcrel_adrp_imm21;
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
@ -52,9 +52,6 @@ public:
|
||||
|
||||
std::optional<MCFixupKind> getFixupKind(StringRef Name) const override;
|
||||
const MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const override;
|
||||
bool shouldForceRelocation(const MCAssembler &Asm, const MCFixup &Fixup,
|
||||
const MCValue &Target, uint64_t Value,
|
||||
const MCSubtargetInfo *STI) override;
|
||||
};
|
||||
|
||||
} //End anonymous namespace
|
||||
@ -194,13 +191,6 @@ const MCFixupKindInfo &AMDGPUAsmBackend::getFixupKindInfo(
|
||||
return Infos[Kind - FirstTargetFixupKind];
|
||||
}
|
||||
|
||||
bool AMDGPUAsmBackend::shouldForceRelocation(const MCAssembler &,
|
||||
const MCFixup &Fixup,
|
||||
const MCValue &, const uint64_t,
|
||||
const MCSubtargetInfo *STI) {
|
||||
return Fixup.getKind() >= FirstLiteralRelocationKind;
|
||||
}
|
||||
|
||||
unsigned AMDGPUAsmBackend::getMinimumNopSize() const {
|
||||
return 4;
|
||||
}
|
||||
|
@ -960,8 +960,6 @@ bool ARMAsmBackend::shouldForceRelocation(const MCAssembler &Asm,
|
||||
const MCSymbolRefExpr *A = Target.getSymA();
|
||||
const MCSymbol *Sym = A ? &A->getSymbol() : nullptr;
|
||||
const unsigned FixupKind = Fixup.getKind();
|
||||
if (FixupKind >= FirstLiteralRelocationKind)
|
||||
return true;
|
||||
if (FixupKind == ARM::fixup_arm_thumb_bl) {
|
||||
assert(Sym && "How did we resolve this?");
|
||||
|
||||
|
@ -253,8 +253,6 @@ bool LoongArchAsmBackend::shouldForceRelocation(const MCAssembler &Asm,
|
||||
const MCValue &Target,
|
||||
const uint64_t,
|
||||
const MCSubtargetInfo *STI) {
|
||||
if (Fixup.getKind() >= FirstLiteralRelocationKind)
|
||||
return true;
|
||||
switch (Fixup.getTargetKind()) {
|
||||
default:
|
||||
return STI->hasFeature(LoongArch::FeatureRelax);
|
||||
|
@ -563,8 +563,6 @@ bool MipsAsmBackend::shouldForceRelocation(const MCAssembler &Asm,
|
||||
const MCValue &Target,
|
||||
const uint64_t,
|
||||
const MCSubtargetInfo *STI) {
|
||||
if (Fixup.getKind() >= FirstLiteralRelocationKind)
|
||||
return true;
|
||||
const unsigned FixupKind = Fixup.getKind();
|
||||
switch (FixupKind) {
|
||||
default:
|
||||
|
@ -166,7 +166,7 @@ public:
|
||||
MCFixupKind Kind = Fixup.getKind();
|
||||
switch ((unsigned)Kind) {
|
||||
default:
|
||||
return Kind >= FirstLiteralRelocationKind;
|
||||
return false;
|
||||
case PPC::fixup_ppc_br24:
|
||||
case PPC::fixup_ppc_br24abs:
|
||||
case PPC::fixup_ppc_br24_notoc:
|
||||
|
@ -117,8 +117,6 @@ bool RISCVAsmBackend::shouldForceRelocation(const MCAssembler &Asm,
|
||||
const MCValue &Target,
|
||||
const uint64_t,
|
||||
const MCSubtargetInfo *STI) {
|
||||
if (Fixup.getKind() >= FirstLiteralRelocationKind)
|
||||
return true;
|
||||
switch (Fixup.getTargetKind()) {
|
||||
default:
|
||||
break;
|
||||
|
@ -275,8 +275,6 @@ namespace {
|
||||
bool shouldForceRelocation(const MCAssembler &Asm, const MCFixup &Fixup,
|
||||
const MCValue &Target, const uint64_t,
|
||||
const MCSubtargetInfo *STI) override {
|
||||
if (Fixup.getKind() >= FirstLiteralRelocationKind)
|
||||
return true;
|
||||
switch ((Sparc::Fixups)Fixup.getKind()) {
|
||||
default:
|
||||
return false;
|
||||
|
@ -115,9 +115,6 @@ public:
|
||||
}
|
||||
std::optional<MCFixupKind> getFixupKind(StringRef Name) const override;
|
||||
const MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const override;
|
||||
bool shouldForceRelocation(const MCAssembler &Asm, const MCFixup &Fixup,
|
||||
const MCValue &Target, const uint64_t Value,
|
||||
const MCSubtargetInfo *STI) override;
|
||||
void applyFixup(const MCAssembler &Asm, const MCFixup &Fixup,
|
||||
const MCValue &Target, MutableArrayRef<char> Data,
|
||||
uint64_t Value, bool IsResolved,
|
||||
@ -159,13 +156,6 @@ SystemZMCAsmBackend::getFixupKindInfo(MCFixupKind Kind) const {
|
||||
return SystemZ::MCFixupKindInfos[Kind - FirstTargetFixupKind];
|
||||
}
|
||||
|
||||
bool SystemZMCAsmBackend::shouldForceRelocation(const MCAssembler &,
|
||||
const MCFixup &Fixup,
|
||||
const MCValue &, const uint64_t,
|
||||
const MCSubtargetInfo *STI) {
|
||||
return Fixup.getKind() >= FirstLiteralRelocationKind;
|
||||
}
|
||||
|
||||
void SystemZMCAsmBackend::applyFixup(const MCAssembler &Asm,
|
||||
const MCFixup &Fixup,
|
||||
const MCValue &Target,
|
||||
|
@ -171,10 +171,6 @@ public:
|
||||
|
||||
const MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const override;
|
||||
|
||||
bool shouldForceRelocation(const MCAssembler &Asm, const MCFixup &Fixup,
|
||||
const MCValue &Target, const uint64_t Value,
|
||||
const MCSubtargetInfo *STI) override;
|
||||
|
||||
void applyFixup(const MCAssembler &Asm, const MCFixup &Fixup,
|
||||
const MCValue &Target, MutableArrayRef<char> Data,
|
||||
uint64_t Value, bool IsResolved,
|
||||
@ -656,13 +652,6 @@ const MCFixupKindInfo &X86AsmBackend::getFixupKindInfo(MCFixupKind Kind) const {
|
||||
return Infos[Kind - FirstTargetFixupKind];
|
||||
}
|
||||
|
||||
bool X86AsmBackend::shouldForceRelocation(const MCAssembler &,
|
||||
const MCFixup &Fixup, const MCValue &,
|
||||
const uint64_t,
|
||||
const MCSubtargetInfo *STI) {
|
||||
return Fixup.getKind() >= FirstLiteralRelocationKind;
|
||||
}
|
||||
|
||||
static unsigned getFixupKindSize(unsigned Kind) {
|
||||
switch (Kind) {
|
||||
default:
|
||||
|
Loading…
x
Reference in New Issue
Block a user