guix: patch around riscv issue with newer (2.40+) binutils
What changed, and why it matters
This commit adds a build-system patch for Bitcoin Core's Guix reproducible-build environment. The patch fixes a glibc RISC-V assembly issue where jump instructions could incorrectly target symbols that the linker is allowed to override (preemptible symbols). It is a build-toolchain compatibility fix for newer binutils (2.40+) and does not change Bitcoin Core's runtime consensus or networking code.
No immediate action required for Bitcoin Core users or operators. Treat as a build-system maintenance patch. Review that the patch file hash and source match the upstream glibc commit when auditing reproducible build supply chain integrity.
Security signals we found
Fixes a glibc RISC-V assembly correctness issue that could produce broken jump targets in libc/ld.so
Only affects the Guix reproducible build toolchain for RISC-V targets
No changes to Bitcoin Core consensus, P2P, wallet, or RPC code
Patch is a backport of an upstream glibc fix, not a new vulnerability disclosure
Evidence from the diff
The commit applies an upstream glibc patch (commit 68389203832ab39dd0dbaabbc4059e7fff51c29b) to Bitcoin Core’s Guix manifest. The patch replaces direct j/jal targets to __sigsetjmp, __setcontext, and exit with HIDDEN_JUMPTARGET(…) in RISC-V glibc assembly. This avoids linking problems because j/jal cannot target preemptible STV_DEFAULT symbols in shared objects; the linker may otherwise generate incorrect code or fail to link. The patch is needed for binutils 2.40+ and can be dropped once glibc 2.35+ is used.
Changed components
contrib/guix/manifest.scmcontrib/guix/patches/glibc-riscv-jumptarget.patchGuix reproducible builds for RISC-VInspect captured patch +59 / −1
diff --git a/contrib/guix/manifest.scm b/contrib/guix/manifest.scm
index a230eea9..795e45dc 100644
--- a/contrib/guix/manifest.scm
+++ b/contrib/guix/manifest.scm
@@ -466,7 +466,8 @@ inspecting signatures in Mach-O binaries.")
(sha256
(base32
"017qdpr5id7ddb4lpkzj2li1abvw916m3fc6n7nw28z4h5qbv2n0"))
- (patches (search-our-patches "glibc-guix-prefix.patch"))))
+ (patches (search-our-patches "glibc-guix-prefix.patch"
+ "glibc-riscv-jumptarget.patch"))))
(arguments
(substitute-keyword-arguments (package-arguments glibc)
((#:configure-flags flags)
diff --git a/contrib/guix/patches/glibc-riscv-jumptarget.patch b/contrib/guix/patches/glibc-riscv-jumptarget.patch
new file mode 100644
index 00000000..70295943
--- /dev/null
+++ b/contrib/guix/patches/glibc-riscv-jumptarget.patch
@@ -0,0 +1,57 @@
+commit 68389203832ab39dd0dbaabbc4059e7fff51c29b
+Author: Fangrui Song <maskray@google.com>
+Date: Thu Oct 28 11:39:49 2021 -0700
+
+ riscv: Fix incorrect jal with HIDDEN_JUMPTARGET
+
+ A non-local STV_DEFAULT defined symbol is by default preemptible in a
+ shared object. j/jal cannot target a preemptible symbol. On other
+ architectures, such a jump instruction either causes PLT [BZ #18822], or
+ if short-ranged, sometimes rejected by the linker (but not by GNU ld's
+ riscv port [ld PR/28509]).
+
+ Use HIDDEN_JUMPTARGET to target a non-preemptible symbol instead.
+
+ With this patch, ld.so and libc.so can be linked with LLD if source
+ files are compiled/assembled with -mno-relax/-Wa,-mno-relax.
+
+ Acked-by: Palmer Dabbelt <palmer@dabbelt.com>
+ Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
+
+Can be dropped when we are using glibc 2.35 or later.
+
+diff --git a/sysdeps/riscv/setjmp.S b/sysdeps/riscv/setjmp.S
+index 0b92016b31..bec7ff80f4 100644
+--- a/sysdeps/riscv/setjmp.S
++++ b/sysdeps/riscv/setjmp.S
+@@ -21,7 +21,7 @@
+
+ ENTRY (_setjmp)
+ li a1, 0
+- j __sigsetjmp
++ j HIDDEN_JUMPTARGET (__sigsetjmp)
+ END (_setjmp)
+ ENTRY (setjmp)
+ li a1, 1
+diff --git a/sysdeps/unix/sysv/linux/riscv/setcontext.S b/sysdeps/unix/sysv/linux/riscv/setcontext.S
+index 9510518750..e44a68aad4 100644
+--- a/sysdeps/unix/sysv/linux/riscv/setcontext.S
++++ b/sysdeps/unix/sysv/linux/riscv/setcontext.S
+@@ -95,6 +95,7 @@ LEAF (__setcontext)
+ 99: j __syscall_error
+
+ END (__setcontext)
++libc_hidden_def (__setcontext)
+ weak_alias (__setcontext, setcontext)
+
+ LEAF (__start_context)
+@@ -108,7 +109,7 @@ LEAF (__start_context)
+ /* Invoke subsequent context if present, else exit(0). */
+ mv a0, s2
+ beqz s2, 1f
+- jal __setcontext
+-1: j exit
++ jal HIDDEN_JUMPTARGET (__setcontext)
++1: j HIDDEN_JUMPTARGET (exit)
+
+ END (__start_context)
Why this scored 18/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.