[MC] Restore MCAsmBackend::shouldForceRelocation to false
For IsPCRel fixups, we had the `A->getKind() != MCSymbolRefExpr::VK_None` condition to force relocations. The condition has then been changed to `Target.getSpecifier()` (086af83688).38c3ad36beupdated shouldForceRelocation to test `Target.getSpecifier`. It is not a good fit as many targets with %lo/%hi style specifiers (SPARC, MIPS, PowerPC, RISC-V) do not force relocations for these specifiers. Revert the Target.getSpecifier implementation (38c3ad36be) and update targets that need it (SystemZAsmBackend/X86AsmBackend) instead. Targets need customization might define addReloc instead. Note: The X86AsmBackend implementation is too conservative. GNU Assembler doesn't emit a relocation for `call local@plt; local`a3d3931676added missing coverage for GOT/PLT related relocations.
This commit is contained in:
@@ -88,10 +88,11 @@ public:
|
||||
/// Get information on a fixup kind.
|
||||
virtual MCFixupKindInfo getFixupKindInfo(MCFixupKind Kind) const;
|
||||
|
||||
// Hook to check if a relocation is needed. The default implementation tests
|
||||
// whether the MCValue has a relocation specifier.
|
||||
// Hook used by the default `addReloc` to check if a relocation is needed.
|
||||
virtual bool shouldForceRelocation(const MCAssembler &, const MCFixup &,
|
||||
const MCValue &, const MCSubtargetInfo *);
|
||||
const MCValue &, const MCSubtargetInfo *) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/// Hook to check if extra nop bytes must be inserted for alignment directive.
|
||||
/// For some targets this may be necessary in order to support linker
|
||||
|
||||
@@ -109,12 +109,6 @@ MCFixupKindInfo MCAsmBackend::getFixupKindInfo(MCFixupKind Kind) const {
|
||||
return Builtins[Kind - FK_NONE];
|
||||
}
|
||||
|
||||
bool MCAsmBackend::shouldForceRelocation(const MCAssembler &, const MCFixup &,
|
||||
const MCValue &Target,
|
||||
const MCSubtargetInfo *) {
|
||||
return Target.getSpecifier();
|
||||
}
|
||||
|
||||
bool MCAsmBackend::fixupNeedsRelaxationAdvanced(const MCAssembler &,
|
||||
const MCFixup &Fixup,
|
||||
const MCValue &, uint64_t Value,
|
||||
|
||||
@@ -200,12 +200,6 @@ namespace {
|
||||
return Info;
|
||||
}
|
||||
|
||||
bool shouldForceRelocation(const MCAssembler &, const MCFixup &,
|
||||
const MCValue &,
|
||||
const MCSubtargetInfo *) override {
|
||||
return false;
|
||||
}
|
||||
|
||||
void relaxInstruction(MCInst &Inst,
|
||||
const MCSubtargetInfo &STI) const override {
|
||||
// FIXME.
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include "llvm/MC/MCInst.h"
|
||||
#include "llvm/MC/MCObjectWriter.h"
|
||||
#include "llvm/MC/MCSubtargetInfo.h"
|
||||
#include "llvm/MC/MCValue.h"
|
||||
|
||||
using namespace llvm;
|
||||
|
||||
@@ -112,6 +113,8 @@ public:
|
||||
// Override MCAsmBackend
|
||||
std::optional<MCFixupKind> getFixupKind(StringRef Name) const override;
|
||||
MCFixupKindInfo getFixupKindInfo(MCFixupKind Kind) const override;
|
||||
bool shouldForceRelocation(const MCAssembler &, const MCFixup &,
|
||||
const MCValue &, const MCSubtargetInfo *) override;
|
||||
void applyFixup(const MCAssembler &Asm, const MCFixup &Fixup,
|
||||
const MCValue &Target, MutableArrayRef<char> Data,
|
||||
uint64_t Value, bool IsResolved,
|
||||
@@ -152,6 +155,13 @@ MCFixupKindInfo SystemZMCAsmBackend::getFixupKindInfo(MCFixupKind Kind) const {
|
||||
return SystemZ::MCFixupKindInfos[Kind - FirstTargetFixupKind];
|
||||
}
|
||||
|
||||
bool SystemZMCAsmBackend::shouldForceRelocation(const MCAssembler &,
|
||||
const MCFixup &,
|
||||
const MCValue &Target,
|
||||
const MCSubtargetInfo *) {
|
||||
return Target.getSpecifier();
|
||||
}
|
||||
|
||||
void SystemZMCAsmBackend::applyFixup(const MCAssembler &Asm,
|
||||
const MCFixup &Fixup,
|
||||
const MCValue &Target,
|
||||
|
||||
@@ -169,6 +169,9 @@ public:
|
||||
|
||||
MCFixupKindInfo getFixupKindInfo(MCFixupKind Kind) const override;
|
||||
|
||||
bool shouldForceRelocation(const MCAssembler &, const MCFixup &,
|
||||
const MCValue &, const MCSubtargetInfo *) override;
|
||||
|
||||
void applyFixup(const MCAssembler &Asm, const MCFixup &Fixup,
|
||||
const MCValue &Target, MutableArrayRef<char> Data,
|
||||
uint64_t Value, bool IsResolved,
|
||||
@@ -687,6 +690,14 @@ static unsigned getFixupKindSize(unsigned Kind) {
|
||||
}
|
||||
}
|
||||
|
||||
// Force relocation when there is a specifier. This might be too conservative -
|
||||
// GAS doesn't emit a relocation for call local@plt; local:.
|
||||
bool X86AsmBackend::shouldForceRelocation(const MCAssembler &, const MCFixup &,
|
||||
const MCValue &Target,
|
||||
const MCSubtargetInfo *) {
|
||||
return Target.getSpecifier();
|
||||
}
|
||||
|
||||
void X86AsmBackend::applyFixup(const MCAssembler &Asm, const MCFixup &Fixup,
|
||||
const MCValue &, MutableArrayRef<char> Data,
|
||||
uint64_t Value, bool IsResolved,
|
||||
|
||||
Reference in New Issue
Block a user