Skip to content

Commit 38c3ad3

Browse files
committed
Define MCAsmBackend::shouldForceRelocation
Return true if the MCValue has a specifier. When a relocation specifier is specified, GNU Assembler will generate a relocation unless the specifier can be optimized due to target-specific reasons (e.g. PPC `@l` `@ha`). This reduces targets' reliance on a MCAssembler::evaluateFixup hack `if (Target.SymSpecifier || SA.isUndefined()) {`, previosuly `if (A->getKind() != MCSymbolRefExpr::VK_None || SA.isUndefined()) {` llvm/test/MC/SystemZ/fixups.s is known to rely on this hack.
1 parent 94821ce commit 38c3ad3

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

llvm/include/llvm/MC/MCAsmBackend.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,10 @@ class MCAsmBackend {
8989
/// Get information on a fixup kind.
9090
virtual const MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const;
9191

92-
/// Hook to check if a relocation is needed for some target specific reason.
93-
virtual bool shouldForceRelocation(const MCAssembler &Asm,
94-
const MCFixup &Fixup,
95-
const MCValue &Target,
96-
const MCSubtargetInfo *STI) {
97-
return false;
98-
}
92+
// Hook to check if a relocation is needed. The default implementation tests
93+
// whether the MCValue has a relocation specifier.
94+
virtual bool shouldForceRelocation(const MCAssembler &, const MCFixup &,
95+
const MCValue &, const MCSubtargetInfo *);
9996

10097
/// Hook to check if extra nop bytes must be inserted for alignment directive.
10198
/// For some targets this may be necessary in order to support linker

llvm/lib/MC/MCAsmBackend.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,12 @@ const MCFixupKindInfo &MCAsmBackend::getFixupKindInfo(MCFixupKind Kind) const {
109109
return Builtins[Kind];
110110
}
111111

112+
bool MCAsmBackend::shouldForceRelocation(const MCAssembler &, const MCFixup &,
113+
const MCValue &Target,
114+
const MCSubtargetInfo *) {
115+
return Target.getSpecifier();
116+
}
117+
112118
bool MCAsmBackend::fixupNeedsRelaxationAdvanced(const MCAssembler &Asm,
113119
const MCFixup &Fixup,
114120
bool Resolved, uint64_t Value,

0 commit comments

Comments
 (0)