Skip to content

Conversation

@zhaoqi5
Copy link
Contributor

@zhaoqi5 zhaoqi5 commented Aug 15, 2025

In some cases, such as using lto or llc, relax feature is not available from this SubtargetInfo (LoongArchAsmBackend is instantiated too early), causing loss of relocations.

This commit modifiy the condition to check whether the section which contains the two symbols is relaxable. If not relaxable, no need to record relocations.

@llvmbot
Copy link
Member

llvmbot commented Aug 15, 2025

@llvm/pr-subscribers-backend-loongarch

Author: ZhaoQi (zhaoqi5)

Changes

In some cases, such as using lto or llc, relax feature is not available from this SubtargetInfo (LoongArchAsmBackend is instantiated too early), causing loss of relocations.

This commit modifiy the condition to check whether the section which contains the two symbols is relaxable. If not relaxable, no need to record relocations.


Full diff: https://github.com/llvm/llvm-project/pull/153792.diff

1 Files Affected:

  • (modified) llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp (+2-2)
diff --git a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp
index ca5d27d54bb81..34a5d802daed6 100644
--- a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp
+++ b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp
@@ -448,10 +448,10 @@ bool LoongArchAsmBackend::addReloc(const MCFragment &F, const MCFixup &Fixup,
           isPCRelFixupResolved(Target.getSubSym(), F))
         return Fallback();
 
-      // In SecA == SecB case. If the linker relaxation is disabled, the
+      // In SecA == SecB case. If the section is not linker-relaxable, the
       // FixedValue has already been calculated out in evaluateFixup,
       // return true and avoid record relocations.
-      if (&SecA == &SecB && !STI.hasFeature(LoongArch::FeatureRelax))
+      if (&SecA == &SecB && !SecA.isLinkerRelaxable())
         return true;
     }
 

@zhaoqi5 zhaoqi5 force-pushed the users/zhaoqi5/replace-relax-feature-condition branch from d7be080 to c0ecb48 Compare August 18, 2025 02:59
… STI

In some cases, such as using lto or llc, relax feature is not
available from this SubtargetInfo (LoongArchAsmBackend is instantiated
too early), causing loss of relocations.

This commit modifiy the condition to check whether the section
which contains the two symbols is relaxable. If not relaxable,
no need to record relocations.
@zhaoqi5 zhaoqi5 force-pushed the users/zhaoqi5/replace-relax-feature-condition branch from c0ecb48 to cbc67fd Compare August 18, 2025 12:38
@zhaoqi5 zhaoqi5 changed the base branch from main to users/zhaoqi5/test-fix-add-sub August 18, 2025 12:39
Base automatically changed from users/zhaoqi5/test-fix-add-sub to main August 19, 2025 01:15
@zhaoqi5 zhaoqi5 merged commit be3fd6a into main Aug 19, 2025
9 checks passed
@zhaoqi5 zhaoqi5 deleted the users/zhaoqi5/replace-relax-feature-condition branch August 19, 2025 01:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants