[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:02:10 PDT 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-lld-elf

Author: wanglei (wangleiat)

<details>
<summary>Changes</summary>

`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.


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


2 Files Affected:

- (modified) lld/ELF/Arch/LoongArch.cpp (+6-1) 
- (added) lld/test/ELF/loongarch-emit-relocs-mark-la.s (+22) 


``````````diff
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

``````````

</details>


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


More information about the llvm-commits mailing list