Skip to content

Commit

Permalink
dev-libs/libffi: backport further patches (arm64 + BTI/PAC, ASAN)
Browse files Browse the repository at this point in the history
I should've done this earlier in -r1 but I equivocated.

Signed-off-by: Sam James <[email protected]>
  • Loading branch information
thesamesam committed Oct 16, 2024
1 parent 5a3e555 commit 662133e
Show file tree
Hide file tree
Showing 7 changed files with 705 additions and 0 deletions.
26 changes: 26 additions & 0 deletions dev-libs/libffi/files/libffi-3.4.6-arm64-bti-spelling.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
https://github.com/libffi/libffi/commit/38732240c125b6af9db66d940c0725a69292cc49

From 38732240c125b6af9db66d940c0725a69292cc49 Mon Sep 17 00:00:00 2001
From: Bill Roberts <[email protected]>
Date: Sat, 1 Jun 2024 12:33:28 -0500
Subject: [PATCH] ffi: fix spelling mistake (#833)

Signed-off-by: Bill Roberts <[email protected]>
---
src/aarch64/ffi.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/aarch64/ffi.c b/src/aarch64/ffi.c
index 8661a352..b13738e3 100644
--- a/src/aarch64/ffi.c
+++ b/src/aarch64/ffi.c
@@ -682,7 +682,7 @@ ffi_call_int (ffi_cif *cif, void (*fn)(void), void *orig_rvalue,
else if (flags & AARCH64_RET_NEED_COPY)
rsize = 16;

- /* Allocate consectutive stack for everything we'll need.
+ /* Allocate consecutive stack for everything we'll need.
The frame uses 40 bytes for: lr, fp, rvalue, flags, sp */
context = alloca (sizeof(struct call_context) + stack_bytes + 40 + rsize);
stack = context + 1;

81 changes: 81 additions & 0 deletions dev-libs/libffi/files/libffi-3.4.6-arm64-bti.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
https://github.com/libffi/libffi/commit/f64141ee3f9e455a060bd09e9ab72b6c94653d7c

From f64141ee3f9e455a060bd09e9ab72b6c94653d7c Mon Sep 17 00:00:00 2001
From: Bill Roberts <[email protected]>
Date: Tue, 19 Mar 2024 11:44:55 -0500
Subject: [PATCH] Fix bti support (#830)

* bti: add identifier to ffi_closure_SYSV_V_alt

This was missing BTI_C identifier.

Old Code:
ffi_closure_SYSV_V_alt:
0000fffff7f70500: ldr x17, [sp, #8]

Signed-off-by: Bill Roberts <[email protected]>

* testsuite: fix whitespace in Makefile.am

Signed-off-by: Bill Roberts <[email protected]>

* aarch64: correct comment describing BTI

The comment is incorrect, BTI is enabled per mapping via mprotect with
PROT_BTI flag set, not per-process. When the loader loads the library,
if the GNU Notes section is missing this, PROT_BTI will not be enabled
for that mapping, but is independent of other mappings.

Signed-off-by: Bill Roberts <[email protected]>

---------

Signed-off-by: Bill Roberts <[email protected]>
---
src/aarch64/sysv.S | 4 +++-
testsuite/Makefile.am | 2 +-
2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/aarch64/sysv.S b/src/aarch64/sysv.S
index fdd0e8b7..60cfa505 100644
--- a/src/aarch64/sysv.S
+++ b/src/aarch64/sysv.S
@@ -68,7 +68,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#define BTI_J hint #36
/*
* The ELF Notes section needs to indicate if BTI is supported, as the first ELF loaded that doesn't
- * declare this support disables it for the whole process.
+ * declare this support disables it for memory region containing the loaded library.
*/
# define GNU_PROPERTY_AARCH64_BTI (1 << 0) /* Has Branch Target Identification */
.text
@@ -527,6 +527,7 @@ L(do_closure):
#if defined(FFI_EXEC_STATIC_TRAMP)
.align 4
CNAME(ffi_closure_SYSV_V_alt):
+ BTI_C
/* See the comments above trampoline_code_table. */
ldr x17, [sp, #8] /* Load closure in x17 */
add sp, sp, #16 /* Restore the stack */
@@ -541,6 +542,7 @@ CNAME(ffi_closure_SYSV_V_alt):

.align 4
CNAME(ffi_closure_SYSV_alt):
+ BTI_C
/* See the comments above trampoline_code_table. */
ldr x17, [sp, #8] /* Load closure in x17 */
add sp, sp, #16 /* Restore the stack */
diff --git a/testsuite/Makefile.am b/testsuite/Makefile.am
index d286cf7f..6ba98e12 100644
--- a/testsuite/Makefile.am
+++ b/testsuite/Makefile.am
@@ -8,7 +8,7 @@ CLEANFILES = *.exe core* *.log *.sum

EXTRA_DIST = config/default.exp emscripten/build.sh emscripten/conftest.py \
emscripten/node-tests.sh emscripten/test.html emscripten/test_libffi.py \
- emscripten/build-tests.sh lib/libffi.exp lib/target-libpath.exp \
+ emscripten/build-tests.sh lib/libffi.exp lib/target-libpath.exp \
lib/wrapper.exp libffi.bhaible/Makefile libffi.bhaible/README \
libffi.bhaible/alignof.h libffi.bhaible/bhaible.exp libffi.bhaible/test-call.c \
libffi.bhaible/test-callback.c libffi.bhaible/testcases.c libffi.call/align_mixed.c \

36 changes: 36 additions & 0 deletions dev-libs/libffi/files/libffi-3.4.6-arm64-fix-build.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
https://github.com/libffi/libffi/commit/9c9e8368e49804c4f7c35ac9f0d7c1d0d533308b

From 9c9e8368e49804c4f7c35ac9f0d7c1d0d533308b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Martin=20Storsj=C3=B6?= <[email protected]>
Date: Tue, 4 Jun 2024 14:13:08 +0300
Subject: [PATCH] aarch64: Add a missing no-op define of SIGN_LR_LINUX_ONLY
(#838)

This is needed at least if building for Linux, with a toolchain
that doesn't default to having PAC enabled, fixing build errors
since 45d284f2d066cc3a080c5be88e51b4d934349797.
---
src/aarch64/internal.h | 2 ++
1 file changed, 2 insertions(+)

diff --git a/src/aarch64/internal.h b/src/aarch64/internal.h
index c39f9cb2..50fa5c13 100644
--- a/src/aarch64/internal.h
+++ b/src/aarch64/internal.h
@@ -88,6 +88,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#define AUTH_LR_AND_RET retab
#define AUTH_LR_WITH_REG(x) autib lr, x
#define BRANCH_AND_LINK_TO_REG blraaz
+ #define SIGN_LR_LINUX_ONLY
#define BRANCH_TO_REG braaz
#define PAC_CFI_WINDOW_SAVE
/* Linux PAC Support */
@@ -136,6 +137,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#define AUTH_LR_AND_RET ret
#define AUTH_LR_WITH_REG(x)
#define BRANCH_AND_LINK_TO_REG blr
+ #define SIGN_LR_LINUX_ONLY
#define BRANCH_TO_REG br
#define PAC_CFI_WINDOW_SAVE
#endif /* HAVE_ARM64E_PTRAUTH */

Loading

0 comments on commit 662133e

Please sign in to comment.