From cc5d476fb1f5f10116d1df256da0141b93c61b6f Mon Sep 17 00:00:00 2001 From: Sebastian Sumpf Date: Wed, 10 May 2023 08:50:10 +0200 Subject: [PATCH] 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 --- repos/libports/ports/libc.hash | 2 +- .../lib/libc/patches/sigsetjmp_riscv.patch | 40 +++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 repos/libports/src/lib/libc/patches/sigsetjmp_riscv.patch diff --git a/repos/libports/ports/libc.hash b/repos/libports/ports/libc.hash index f0b791929a..04993bcf7a 100644 --- a/repos/libports/ports/libc.hash +++ b/repos/libports/ports/libc.hash @@ -1 +1 @@ -a4d148016cfbc4c494b277e164d67617cf540e31 +dfcf0321f6f20fb8051954bc3fb4e661467a3434 diff --git a/repos/libports/src/lib/libc/patches/sigsetjmp_riscv.patch b/repos/libports/src/lib/libc/patches/sigsetjmp_riscv.patch new file mode 100644 index 0000000000..5a10980395 --- /dev/null +++ b/repos/libports/src/lib/libc/patches/sigsetjmp_riscv.patch @@ -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 + + 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)