[lld] [lld][ELF][RISC-V] Fixes undefined_cc symbol (PR #203800)

via llvm-commits llvm-commits at lists.llvm.org
Sun Jun 14 15:47:19 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-lld-elf

Author: Kartik Ohlan (Ko496-glitch)

<details>
<summary>Changes</summary>

Fixes #<!-- -->203471

added sdOther before we do an overwrite. 
Added test case

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


2 Files Affected:

- (modified) lld/ELF/Symbols.cpp (+2) 
- (modified) lld/test/ELF/riscv-variant-cc.s (+23) 


``````````diff
diff --git a/lld/ELF/Symbols.cpp b/lld/ELF/Symbols.cpp
index 7bad4ceccec33..0ead490476324 100644
--- a/lld/ELF/Symbols.cpp
+++ b/lld/ELF/Symbols.cpp
@@ -683,8 +683,10 @@ void Symbol::resolve(Ctx &ctx, const SharedSymbol &other) {
     // An undefined symbol with non default visibility must be satisfied
     // in the same DSO.
     uint8_t bind = binding;
+    uint8_t oldStOther = stOther;
     other.overwrite(*this);
     binding = bind;
+    stOther |= oldStOther & ~0x3;
   } else if (traced)
     printTraceSymbol(other, getName());
 }
diff --git a/lld/test/ELF/riscv-variant-cc.s b/lld/test/ELF/riscv-variant-cc.s
index 024266d236a67..3afdd0a4913ac 100644
--- a/lld/test/ELF/riscv-variant-cc.s
+++ b/lld/test/ELF/riscv-variant-cc.s
@@ -1,3 +1,4 @@
+// NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
 # REQUIRES: riscv
 # RUN: rm -rf %t && split-file %s %t && cd %t
 
@@ -54,6 +55,12 @@
 # CHECK5-NEXT: 0 NOTYPE  GLOBAL DEFAULT [VARIANT_CC] UND   func_global_undef
 # CHECK5-NEXT: 0 IFUNC   GLOBAL DEFAULT [VARIANT_CC] [[#]] ifunc_global_def
 
+# RUN: llvm-mc -filetype=obj -triple=riscv64 6a.s -o 6a.o
+# RUN: llvm-mc -filetype=obj -triple=riscv64 6b.s -o 6b.o
+# RUN: ld.lld 6b.o --shared -o 6b.so
+# RUN: ld.lld 6a.o 6b.so --shared -o 6.so
+# RUN: llvm-readelf -d -s 6.so | FileCheck --check-prefix=CHECK6 %s
+
 #--- 1.s
 ## An object with a variant_pcs symbol but without a R_RISCV_JMP_SLOT
 ## should not generate a DT_RISCV_VARIANT_CC.
@@ -126,3 +133,19 @@ ifunc_global_def:
 ifunc_global_hidden:
 ifunc_local:
   ret
+
+#--- 6a.s
+.text
+.global foo
+.variant_cc ext
+.type ext, @function
+foo:
+  call ext
+  ret
+
+#--- 6b.s
+.text
+.global ext
+.type ext, @function
+ext:
+  ret

``````````

</details>


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


More information about the llvm-commits mailing list