[lld] [LLD][LoongArch] Preserve R_LARCH_MARK_LA with --emit-relocs (PR #192033)

via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 14 04:01:37 PDT 2026


https://github.com/wangleiat created https://github.com/llvm/llvm-project/pull/192033

`R_LARCH_MARK_LA` was dropped during scanSectionImpl(), so it was
missing from --emit-relocs output. Route it through the relax hint path
to preserve it.


>From c0ea7d28130b8d36335f8492515dda3306b8b870 Mon Sep 17 00:00:00 2001
From: wanglei <wanglei at loongson.cn>
Date: Tue, 14 Apr 2026 18:59:51 +0800
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
 =?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.7
---
 lld/ELF/Arch/LoongArch.cpp                   |  7 ++++++-
 lld/test/ELF/loongarch-emit-relocs-mark-la.s | 22 ++++++++++++++++++++
 2 files changed, 28 insertions(+), 1 deletion(-)
 create mode 100644 lld/test/ELF/loongarch-emit-relocs-mark-la.s

diff --git a/lld/ELF/Arch/LoongArch.cpp b/lld/ELF/Arch/LoongArch.cpp
index 4c9ea3deece2d..dcf53f358c387 100644
--- a/lld/ELF/Arch/LoongArch.cpp
+++ b/lld/ELF/Arch/LoongArch.cpp
@@ -494,7 +494,6 @@ void LoongArch::scanSectionImpl(InputSectionBase &sec, Relocs<RelTy> rels) {
     // (fast-path helpers, TLS) call a handler and use `continue`.
     switch (type) {
     case R_LARCH_NONE:
-    case R_LARCH_MARK_LA:
     case R_LARCH_MARK_PCREL:
       continue;
 
@@ -701,6 +700,12 @@ void LoongArch::scanSectionImpl(InputSectionBase &sec, Relocs<RelTy> rels) {
       if (ctx.arg.relax)
         sec.addReloc({R_RELAX_HINT, type, offset, addend, &sym});
       continue;
+
+    // R_LARCH_MARK_LA marks a la.abs sequence. It is not used for
+    // relocation computation, but must be preserved for --emit-relocs.
+    //
+    // Treat it as a relax hint so it is retained without affecting codegen.
+    case R_LARCH_MARK_LA:
     case R_LARCH_ALIGN:
       sec.addReloc({R_RELAX_HINT, type, offset, addend, &sym});
       continue;
diff --git a/lld/test/ELF/loongarch-emit-relocs-mark-la.s b/lld/test/ELF/loongarch-emit-relocs-mark-la.s
new file mode 100644
index 0000000000000..7483b6e63ebef
--- /dev/null
+++ b/lld/test/ELF/loongarch-emit-relocs-mark-la.s
@@ -0,0 +1,22 @@
+# REQUIRES: loongarch
+
+## Test that R_LARCH_MARK_LA is preserved with --emit-relocs.
+
+# RUN: llvm-mc --filetype=obj --triple=loongarch64 %s -o %t.o
+
+# RUN: ld.lld --emit-relocs --relax %t.o -o %t.relax
+# RUN: llvm-readobj -r %t.relax | FileCheck %s
+
+# RUN: ld.lld --emit-relocs --no-relax %t.o -o %t.norelax
+# RUN: llvm-readobj -r %t.norelax | FileCheck %s
+
+# CHECK:      R_LARCH_MARK_LA
+
+  .global _start
+_start:
+  la.abs $a0, a
+  ret
+
+  .global a
+a:
+  .quad 0



More information about the llvm-commits mailing list