[llvm] 38c3ad3 - Define MCAsmBackend::shouldForceRelocation
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sat Apr 5 19:01:20 PDT 2025
Author: Fangrui Song
Date: 2025-04-05T19:01:16-07:00
New Revision: 38c3ad36be1facbe6db2dede7e93c0f12fb4e1dc
URL: https://github.com/llvm/llvm-project/commit/38c3ad36be1facbe6db2dede7e93c0f12fb4e1dc
DIFF: https://github.com/llvm/llvm-project/commit/38c3ad36be1facbe6db2dede7e93c0f12fb4e1dc.diff
LOG: 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.
Added:
Modified:
llvm/include/llvm/MC/MCAsmBackend.h
llvm/lib/MC/MCAsmBackend.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/MC/MCAsmBackend.h b/llvm/include/llvm/MC/MCAsmBackend.h
index 69ba400fac879..5953de30c2eb2 100644
--- a/llvm/include/llvm/MC/MCAsmBackend.h
+++ b/llvm/include/llvm/MC/MCAsmBackend.h
@@ -89,13 +89,10 @@ class MCAsmBackend {
/// Get information on a fixup kind.
virtual const MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const;
- /// Hook to check if a relocation is needed for some target specific reason.
- virtual bool shouldForceRelocation(const MCAssembler &Asm,
- const MCFixup &Fixup,
- const MCValue &Target,
- const MCSubtargetInfo *STI) {
- return false;
- }
+ // Hook to check if a relocation is needed. The default implementation tests
+ // whether the MCValue has a relocation specifier.
+ virtual bool shouldForceRelocation(const MCAssembler &, const MCFixup &,
+ const MCValue &, const MCSubtargetInfo *);
/// 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
diff --git a/llvm/lib/MC/MCAsmBackend.cpp b/llvm/lib/MC/MCAsmBackend.cpp
index b5a0766988e14..23cc134f65b52 100644
--- a/llvm/lib/MC/MCAsmBackend.cpp
+++ b/llvm/lib/MC/MCAsmBackend.cpp
@@ -109,6 +109,12 @@ const MCFixupKindInfo &MCAsmBackend::getFixupKindInfo(MCFixupKind Kind) const {
return Builtins[Kind];
}
+bool MCAsmBackend::shouldForceRelocation(const MCAssembler &, const MCFixup &,
+ const MCValue &Target,
+ const MCSubtargetInfo *) {
+ return Target.getSpecifier();
+}
+
bool MCAsmBackend::fixupNeedsRelaxationAdvanced(const MCAssembler &Asm,
const MCFixup &Fixup,
bool Resolved, uint64_t Value,
More information about the llvm-commits
mailing list