[llvm] [LoongArch] Use section-relaxable check instead of relax feature from STI (PR #153792)

via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 15 04:48:55 PDT 2025


https://github.com/zhaoqi5 created https://github.com/llvm/llvm-project/pull/153792

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.

>From d7be0807af1a2dcb7fe434f6b19073e893ba85a1 Mon Sep 17 00:00:00 2001
From: Qi Zhao <zhaoqi01 at loongson.cn>
Date: Fri, 15 Aug 2025 19:25:59 +0800
Subject: [PATCH] [LoongArch] Use section-relaxable check instead of relax
 feature from 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.
---
 .../lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

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;
     }
 



More information about the llvm-commits mailing list