Skip to content

Commit

Permalink
libc/riscv: fix link errors with GCC 12
Browse files Browse the repository at this point in the history
Dynamically linked functions can not be called directly with jump ("j",
"jal") and friends. Calls must go through the PLT.

issue #4827
  • Loading branch information
ssumpf authored and chelmuth committed May 30, 2023
1 parent ff497bc commit cc5d476
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion repos/libports/ports/libc.hash
Original file line number Diff line number Diff line change
@@ -1 +1 @@
a4d148016cfbc4c494b277e164d67617cf540e31
dfcf0321f6f20fb8051954bc3fb4e661467a3434
40 changes: 40 additions & 0 deletions repos/libports/src/lib/libc/patches/sigsetjmp_riscv.patch
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit cc5d476

Please sign in to comment.