[llvm-branch-commits] [LoongArch] Generate more PCRel relocations for resolvable sub-symbols (PR #211754)

via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Jul 30 23:56:54 PDT 2026


================
@@ -401,51 +401,31 @@ bool LoongArchAsmBackend::isPCRelFixupResolved(const MCSymbol *SymA,
 void LoongArchAsmBackend::addReloc(const MCFragment &F, const MCFixup &Fixup,
                                    const MCValue &Target, uint64_t &FixedValue,
                                    bool IsResolved) {
-  auto Fallback = [&]() {
-    MCAsmBackend::maybeAddReloc(F, Fixup, Target, FixedValue, IsResolved);
+  // If the fixup is in a .dwo section (where relocations are forbidden), we
+  // must resolve the difference directly. The computed Value in evaluateFixup
+  // is correct based on the current layout.
+  if (F.getParent()->getName().ends_with(".dwo"))
----------------
wangleiat wrote:

I noticed that a similar issue was addressed in the previous patch:

[dwarf] make dwarf fission compatible with RISCV relaxations 2/2 (#164813)

That patch avoids emitting DW_AT_high_pc as a label delta when the range can be relaxed at link time by using `isRangeRelaxable()`:
```
if (DD->getDwarfVersion() >= 4 &&
    (!isDwoUnit() || !llvm::isRangeRelaxable(Begin, End))) {
  addLabelDelta(D, dwarf::DW_AT_high_pc, End, Begin);
  return;
}
```
https://github.com/llvm/llvm-project/blob/88fb1a93f4dd4e2bc5637b5e30ff0fab9edc21a9/llvm/lib/MC/MCSymbol.cpp#L94-L104

As far as I understand, for RISC-V, the range between two labels can always be affected by linker relaxation, so checking fragments works well there.

For LoongArch, however, some relaxable ranges may not have their fragments marked as LinkerRelaxable. This makes me wonder whether the relaxation property should be checked at the section level instead of the fragment level.

I am not very familiar with the DWARF handling here. Would it be more appropriate to generalize `isRangeRelaxable()` or add a section-level property to indicate whether relocations/range differences can change at link time, instead of adding a .dwo-specific special case?

https://github.com/llvm/llvm-project/pull/211754


More information about the llvm-branch-commits mailing list