[llvm] 4182d2d - [ARM,PowerPC] shouldForceRelocation: check MCValue::Specifier

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sat Apr 5 20:04:12 PDT 2025


Author: Fangrui Song
Date: 2025-04-05T20:04:07-07:00
New Revision: 4182d2dcb5ecbfc34d41a6cd11810cd36844eddb

URL: https://github.com/llvm/llvm-project/commit/4182d2dcb5ecbfc34d41a6cd11810cd36844eddb
DIFF: https://github.com/llvm/llvm-project/commit/4182d2dcb5ecbfc34d41a6cd11810cd36844eddb.diff

LOG: [ARM,PowerPC] shouldForceRelocation: check MCValue::Specifier

Follow-up to 38c3ad36be1facbe6db2dede7e93c0f12fb4e1dc

Removes reliance on a MCAssembler::evaluateFixup hack
`if (Target.SymSpecifier || SA.isUndefined()) {` (previosuly
`if (A->getKind() != MCSymbolRefExpr::VK_None || SA.isUndefined()) {`)

Target.SymSpecifier will soon go away when MCValue replaces
MCSymbolRefExpr members with MCSymbol and removes the temporary
`SymSpecifier` workaround.

Added: 
    

Modified: 
    llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp
    llvm/lib/Target/PowerPC/MCTargetDesc/PPCAsmBackend.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp b/llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp
index afe4be54fa843..bed15bdc274ba 100644
--- a/llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp
+++ b/llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp
@@ -993,7 +993,7 @@ bool ARMAsmBackend::shouldForceRelocation(const MCAssembler &Asm,
               FixupKind == ARM::fixup_arm_uncondbl ||
               FixupKind == ARM::fixup_arm_condbl))
     return true;
-  return false;
+  return Target.getSpecifier();
 }
 
 /// getFixupKindNumBytes - The number of bytes the fixup may change.

diff  --git a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCAsmBackend.cpp b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCAsmBackend.cpp
index 5d6999dbcf1b6..34a1424f08486 100644
--- a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCAsmBackend.cpp
+++ b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCAsmBackend.cpp
@@ -159,6 +159,10 @@ class PPCAsmBackend : public MCAsmBackend {
   bool shouldForceRelocation(const MCAssembler &Asm, const MCFixup &Fixup,
                              const MCValue &Target,
                              const MCSubtargetInfo *STI) override {
+    // If there is a @ specifier, unless it is optimized out (e.g. constant @l),
+    // force a relocation.
+    if (Target.getSpecifier())
+      return true;
     MCFixupKind Kind = Fixup.getKind();
     switch ((unsigned)Kind) {
     default:


        


More information about the llvm-commits mailing list