libc/riscv: fix link errors with GCC 12

Dynamically linked functions can not be called directly with jump ("j",
"jal") and friends. Calls must go through the PLT.

issue #4827
This commit is contained in:
Sebastian Sumpf 2023-05-10 08:50:10 +02:00 committed by Christian Helmuth
parent ff497bc710
commit cc5d476fb1
2 changed files with 41 additions and 1 deletions

View File

@ -1 +1 @@
a4d148016cfbc4c494b277e164d67617cf540e31
dfcf0321f6f20fb8051954bc3fb4e661467a3434

View File

@ -0,0 +1,40 @@
Back port from FreeBSD 13.1. required for GCC 12
Fixes ld error message: "relocation R_RISCV_JAL against `setjmp' which may bind
externally can not be used when making a shared object" which means that there
can not be a direct jump ("j", "jal", etc.) to a function is a jump slot (in
PLT). So do not use the "j" calls.
--- src/lib/libc/lib/libc/riscv/gen/sigsetjmp.S
+++ src/lib/libc/lib/libc/riscv/gen/sigsetjmp.S
@@ -38,20 +38,24 @@ __FBSDID("$FreeBSD: releng/12.0/lib/libc/riscv/gen/sigsetjmp.S 294227 2016-01-17
#include <machine/setjmp.h>
ENTRY(sigsetjmp)
- beqz a1, _C_LABEL(_setjmp)
- j _C_LABEL(setjmp)
+ beqz a1, 1f
+tail _C_LABEL(setjmp)
+ 1:
+ tail _C_LABEL(_setjmp)
END(sigsetjmp)
ENTRY(siglongjmp)
/* Load the _setjmp magic */
ld a2, .Lmagic
- ld a3, 0(a0)
+ld a3, 0(a0)
/* Check the magic */
- beq a2, a3, _C_LABEL(_longjmp)
- j _C_LABEL(longjmp)
+ beq a2, a3, 1f
+tail _C_LABEL(longjmp)
+ 1:
+tail _C_LABEL(_longjmp)
.align 3
-.Lmagic:
+ .Lmagic:
.quad _JB_MAGIC__SETJMP
END(siglongjmp)