[lld] [lld][LoongArch] Prevent relaxation oscillation for LA.PCRel and CALL (PR #226713)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 30 03:02:15 PDT 2026
================
@@ -0,0 +1,47 @@
+# REQUIRES: loongarch
+##
+## call36 -> bl relaxation (relaxMediumCall, isInt<28>) must not
+## oscillate between remove=0 and remove=4. Without the fix, ld.lld reports
+## "address assignment did not converge".
+##
+## Unlike RISC-V calls (8 -> 4 -> 2 bytes), every LoongArch medium call site has
+## only two states (8 or 4 bytes), so oscillation is always a 0 <-> 4 flip.
+## The flip needs a site whose distance sits exactly at the +-128MiB limit while
+## a ".p2align 4" (R_LARCH_ALIGN) absorbs some shrinks but not others, so the
+## target address jitters between passes.
+##
+## The layout is deliberately fragile: the .space size below was found by
+## searching a model of lld's relaxation loop. Do not "round" it.
+
+# RUN: llvm-mc -filetype=obj -triple=loongarch64 -mattr=+relax %s -o %t.o
+# RUN: ld.lld -e _start %t.o -o %t
+# RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck %s
+
+## The two short-range sites in .text.a are always relaxed.
+# CHECK-LABEL: <_start>:
+# CHECK-NEXT: bl
+# CHECK-NEXT: bl
+
+.section .text.a,"ax"
----------------
heiher wrote:
> pin the section addresses explicitly, or add a check that the call site actually sits at the boundary.
All done. Thanks!
https://github.com/llvm/llvm-project/pull/226713
More information about the llvm-commits
mailing list