[lld] [lld][ELF][RISC-V] Fixes undefined_cc symbol (PR #203800)
Kartik Ohlan via llvm-commits
llvm-commits at lists.llvm.org
Sun Jun 14 15:46:43 PDT 2026
https://github.com/Ko496-glitch created https://github.com/llvm/llvm-project/pull/203800
Fixes #203471
added sdOther before we do an overwrite.
Added test case
>From 8772a41dbc8ac0c97a8e6cb88a91f5e227fd2096 Mon Sep 17 00:00:00 2001
From: Kartik Ohlan <kartik7ohlan at gmail.com>
Date: Sun, 14 Jun 2026 15:44:29 -0700
Subject: [PATCH] added the sdOther
---
lld/ELF/Symbols.cpp | 2 ++
lld/test/ELF/riscv-variant-cc.s | 23 +++++++++++++++++++++++
2 files changed, 25 insertions(+)
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
More information about the llvm-commits
mailing list