From e940beb3afab1a64f0c6cd8ed5228ca828983a80 Mon Sep 17 00:00:00 2001 From: Carlos O'Donell Date: Mon, 26 Aug 2024 08:42:21 -0400 Subject: [PATCH] Fix AArch64 BTI enablement issues (#2305877) Resolves: #2305877 --- 0001-Fix-bti-support-830.patch | 82 ++ 0002-ffi-fix-spelling-mistake-833.patch | 27 + ...4-support-pointer-authentication-834.patch | 333 ++++++++ 0005-Import-from-upstream.patch | 758 ++++++++++++++++++ ...ssing-no-op-define-of-SIGN_LR_LINUX_.patch | 37 + 0007-Fix-struct-args-Rainer-Orth.patch | 47 ++ libffi.spec | 21 +- 7 files changed, 1301 insertions(+), 4 deletions(-) create mode 100644 0001-Fix-bti-support-830.patch create mode 100644 0002-ffi-fix-spelling-mistake-833.patch create mode 100644 0003-aarch64-support-pointer-authentication-834.patch create mode 100644 0005-Import-from-upstream.patch create mode 100644 0006-aarch64-Add-a-missing-no-op-define-of-SIGN_LR_LINUX_.patch create mode 100644 0007-Fix-struct-args-Rainer-Orth.patch diff --git a/0001-Fix-bti-support-830.patch b/0001-Fix-bti-support-830.patch new file mode 100644 index 0000000..22f68d6 --- /dev/null +++ b/0001-Fix-bti-support-830.patch @@ -0,0 +1,82 @@ +From f64141ee3f9e455a060bd09e9ab72b6c94653d7c Mon Sep 17 00:00:00 2001 +From: Bill Roberts <152999275+billatarm@users.noreply.github.com> +Date: Tue, 19 Mar 2024 11:44:55 -0500 +Subject: [PATCH 1/7] Fix bti support (#830) +Content-type: text/plain; charset=UTF-8 + +* 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 + +* testsuite: fix whitespace in Makefile.am + +Signed-off-by: Bill Roberts + +* 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 + +--------- + +Signed-off-by: Bill Roberts +--- + 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 fdd0e8b..60cfa50 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 d286cf7..6ba98e1 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 \ +-- +2.46.0 + diff --git a/0002-ffi-fix-spelling-mistake-833.patch b/0002-ffi-fix-spelling-mistake-833.patch new file mode 100644 index 0000000..053fcce --- /dev/null +++ b/0002-ffi-fix-spelling-mistake-833.patch @@ -0,0 +1,27 @@ +From 38732240c125b6af9db66d940c0725a69292cc49 Mon Sep 17 00:00:00 2001 +From: Bill Roberts <152999275+billatarm@users.noreply.github.com> +Date: Sat, 1 Jun 2024 12:33:28 -0500 +Subject: [PATCH 2/7] ffi: fix spelling mistake (#833) +Content-type: text/plain; charset=UTF-8 + +Signed-off-by: Bill Roberts +--- + 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 8661a35..b13738e 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; +-- +2.46.0 + diff --git a/0003-aarch64-support-pointer-authentication-834.patch b/0003-aarch64-support-pointer-authentication-834.patch new file mode 100644 index 0000000..0386ada --- /dev/null +++ b/0003-aarch64-support-pointer-authentication-834.patch @@ -0,0 +1,333 @@ +From 45d284f2d066cc3a080c5be88e51b4d934349797 Mon Sep 17 00:00:00 2001 +From: Bill Roberts <152999275+billatarm@users.noreply.github.com> +Date: Sat, 1 Jun 2024 12:34:53 -0500 +Subject: [PATCH 3/7] aarch64: support pointer authentication (#834) +Content-type: text/plain; charset=UTF-8 + +* aarch64: fix callstack in ffi_call_SYSV + +The debug stack gets corrupted between the frame and stack pivots, update +the CFI directives so the call stack stays correct in the debugger. + +str x9, [x1, #32] // stack is ffi_call_SYSV() -> ffi_call_int() -> ffi_call_int() -> main() (good) +mov x29, x1 // stack is ffi_call_SYSV() -> ffi_call_int() -> ffi_call_int() -> ffi_call() -> main() (bad) +mov sp, x0 // stack is ffi_call_SYSV() -> ffi_call_int() -> ffi_call_int() -> main() (good) + +The CFA data needs to be updated around the pivots, after this patch the +callstack stays correct. + +Signed-off-by: Bill Roberts + +* aarch64: remove uneeded CFI directive + +This directive doesn't actually set the CFA to anything valid, and +during unwinding this isn't even used. Note that the PAC/Darwin usage +is quite suspect as well, as the CFA is either x1 or x29 after the frame +pivot, and the CFA address is what's used as the modifier when verifying +the PAC. At least this is the behavior on Linux with PAC, I need to +verify ARME ABI unwinding. So for now leave Darwin as is. + +Signed-off-by: Bill Roberts + +* ptrauth: rename define for clarity + +Rename the HAVE_PTRAUTH define for clarity that its associated with the +ARM64E ABI and not the ARM64 ABI that can be supported on Linux and +enabled with -mbranch-protection=standard. + +Signed-off-by: Bill Roberts + +* aarch64: add PAC support to ffi_call_SYSV + +Support AARCH64 Pointer Authentication Codes (PAC) within ffi_call_SYSV +and support exception unwinding. + +The Linux ABI for PAC is to use paciasp/autiasp instructions which also +have hint space equivelent instructions. They sign the LR (x30) with the +A key and the current stack pointer as the salt. Note that this can also be +configured to use the B key and will use pacibsp/autibsp hint instructions. + +The Linux ABI for exception frame data when PAC is enabled assumes that the +Connonical Frame Address, or CFA is equal to the stack pointer. I.E sp is +equal to x29 (fp). When the unwinder is invoked the cfa will point to +the frame which will include the *signed* return address from the LR. +This will then be passed to __builtin_aarch64_autia1716 where the CFA +will be used as the salt and stored to register x16 and register x17 +will contain the signed address to demangle. This can be noted in: + - https://github.com/gcc-mirror/gcc/blob/d6d7afcdbc04adb0ec42a44b2d7e05600945af42/libgcc/config/aarch64/aarch64-unwind.h#L56 + +The other required portion of this is to indicate to the unwinder that +this is a signed address that needs to go the special demangle route in +the unwinder. This is accomplished by using CFI directive "cfi_window_save" +which marks that frame as being signed. + +Putting all of this together is a bit tricky, as the internals of +ffi_call_SYSV the callee allocates its stack and frame and passes it in +arg1 (x0) and arg2 (x1) to the called function, where that function +pivots its stack, so care must be taken to get the sp == fp before +paciasp is called and also restore that state before autiasp is called. + +Signed-off-by: Bill Roberts + +--------- + +Signed-off-by: Bill Roberts +--- + configure.ac | 6 ++-- + include/ffi_cfi.h | 2 ++ + src/aarch64/ffi.c | 4 +-- + src/aarch64/internal.h | 76 ++++++++++++++++++++++++++++++++---------- + src/aarch64/sysv.S | 20 ++++++----- + src/closures.c | 6 ++-- + 6 files changed, 81 insertions(+), 33 deletions(-) + +diff --git a/configure.ac b/configure.ac +index 816bfd6..b35a999 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -189,17 +189,17 @@ AC_CACHE_CHECK([whether compiler supports pointer authentication], + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[ + #ifdef __clang__ + # if __has_feature(ptrauth_calls) +-# define HAVE_PTRAUTH 1 ++# define HAVE_ARM64E_PTRAUTH 1 + # endif + #endif + +-#ifndef HAVE_PTRAUTH ++#ifndef HAVE_ARM64E_PTRAUTH + # error Pointer authentication not supported + #endif + ]])],[libffi_cv_as_ptrauth=yes],[libffi_cv_as_ptrauth=no]) + ]) + if test "x$libffi_cv_as_ptrauth" = xyes; then +- AC_DEFINE(HAVE_PTRAUTH, 1, ++ AC_DEFINE(HAVE_ARM64E_PTRAUTH, 1, + [Define if your compiler supports pointer authentication.]) + fi + +diff --git a/include/ffi_cfi.h b/include/ffi_cfi.h +index f4c292d..8565663 100644 +--- a/include/ffi_cfi.h ++++ b/include/ffi_cfi.h +@@ -49,6 +49,7 @@ + # define cfi_personality(enc, exp) .cfi_personality enc, exp + # define cfi_lsda(enc, exp) .cfi_lsda enc, exp + # define cfi_escape(...) .cfi_escape __VA_ARGS__ ++# define cfi_window_save .cfi_window_save + + #else + +@@ -71,6 +72,7 @@ + # define cfi_personality(enc, exp) + # define cfi_lsda(enc, exp) + # define cfi_escape(...) ++# define cfi_window_save + + #endif /* HAVE_AS_CFI_PSEUDO_OP */ + #endif /* FFI_CFI_H */ +diff --git a/src/aarch64/ffi.c b/src/aarch64/ffi.c +index b13738e..964934d 100644 +--- a/src/aarch64/ffi.c ++++ b/src/aarch64/ffi.c +@@ -63,7 +63,7 @@ struct call_context + #if FFI_EXEC_TRAMPOLINE_TABLE + + #ifdef __MACH__ +-#ifdef HAVE_PTRAUTH ++#ifdef HAVE_ARM64E_PTRAUTH + #include + #endif + #include +@@ -877,7 +877,7 @@ ffi_prep_closure_loc (ffi_closure *closure, + + #if FFI_EXEC_TRAMPOLINE_TABLE + # ifdef __MACH__ +-# ifdef HAVE_PTRAUTH ++# ifdef HAVE_ARM64E_PTRAUTH + codeloc = ptrauth_auth_data(codeloc, ptrauth_key_function_pointer, 0); + # endif + void **config = (void **)((uint8_t *)codeloc - PAGE_MAX_SIZE); +diff --git a/src/aarch64/internal.h b/src/aarch64/internal.h +index b5d102b..c39f9cb 100644 +--- a/src/aarch64/internal.h ++++ b/src/aarch64/internal.h +@@ -81,20 +81,62 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ + /* Helpers for writing assembly compatible with arm ptr auth */ + #ifdef LIBFFI_ASM + +-#ifdef HAVE_PTRAUTH +-#define SIGN_LR pacibsp +-#define SIGN_LR_WITH_REG(x) pacib lr, x +-#define AUTH_LR_AND_RET retab +-#define AUTH_LR_WITH_REG(x) autib lr, x +-#define BRANCH_AND_LINK_TO_REG blraaz +-#define BRANCH_TO_REG braaz +-#else +-#define SIGN_LR +-#define SIGN_LR_WITH_REG(x) +-#define AUTH_LR_AND_RET ret +-#define AUTH_LR_WITH_REG(x) +-#define BRANCH_AND_LINK_TO_REG blr +-#define BRANCH_TO_REG br +-#endif +- +-#endif ++ #if defined(HAVE_ARM64E_PTRAUTH) ++ /* ARM64E ABI For Darwin */ ++ #define SIGN_LR pacibsp ++ #define SIGN_LR_WITH_REG(x) pacib lr, x ++ #define AUTH_LR_AND_RET retab ++ #define AUTH_LR_WITH_REG(x) autib lr, x ++ #define BRANCH_AND_LINK_TO_REG blraaz ++ #define BRANCH_TO_REG braaz ++ #define PAC_CFI_WINDOW_SAVE ++ /* Linux PAC Support */ ++ #elif defined(__ARM_FEATURE_PAC_DEFAULT) ++ #define GNU_PROPERTY_AARCH64_POINTER_AUTH (1 << 1) ++ #define PAC_CFI_WINDOW_SAVE cfi_window_save ++ #define TMP_REG x9 ++ #define BRANCH_TO_REG br ++ #define BRANCH_AND_LINK_TO_REG blr ++ #define SIGN_LR_LINUX_ONLY SIGN_LR ++ /* Which key to sign with? */ ++ #if (__ARM_FEATURE_PAC_DEFAULT & 1) == 1 ++ /* Signed with A-key */ ++ #define SIGN_LR hint #25 /* paciasp */ ++ #define AUTH_LR hint #29 /* autiasp */ ++ #else ++ /* Signed with B-key */ ++ #define SIGN_LR hint #27 /* pacibsp */ ++ #define AUTH_LR hint #31 /* autibsp */ ++ #endif /* __ARM_FEATURE_PAC_DEFAULT */ ++ #define AUTH_LR_WITH_REG(x) _auth_lr_with_reg x ++.macro _auth_lr_with_reg modifier ++ mov TMP_REG, sp ++ mov sp, \modifier ++ AUTH_LR ++ mov sp, TMP_REG ++.endm ++ #define SIGN_LR_WITH_REG(x) _sign_lr_with_reg x ++.macro _sign_lr_with_reg modifier ++ mov TMP_REG, sp ++ mov sp, \modifier ++ SIGN_LR ++ mov sp, TMP_REG ++.endm ++ #define AUTH_LR_AND_RET _auth_lr_and_ret modifier ++.macro _auth_lr_and_ret modifier ++ AUTH_LR ++ ret ++.endm ++ #undef TMP_REG ++ ++ /* No Pointer Auth */ ++ #else ++ #define SIGN_LR ++ #define SIGN_LR_WITH_REG(x) ++ #define AUTH_LR_AND_RET ret ++ #define AUTH_LR_WITH_REG(x) ++ #define BRANCH_AND_LINK_TO_REG blr ++ #define BRANCH_TO_REG br ++ #define PAC_CFI_WINDOW_SAVE ++ #endif /* HAVE_ARM64E_PTRAUTH */ ++#endif /* LIBFFI_ASM */ +diff --git a/src/aarch64/sysv.S b/src/aarch64/sysv.S +index 60cfa50..6a9a561 100644 +--- a/src/aarch64/sysv.S ++++ b/src/aarch64/sysv.S +@@ -92,27 +92,27 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ + cfi_startproc + CNAME(ffi_call_SYSV): + BTI_C +- /* Sign the lr with x1 since that is where it will be stored */ ++ PAC_CFI_WINDOW_SAVE ++ /* Sign the lr with x1 since that is the CFA which is the modifer used in auth instructions */ + SIGN_LR_WITH_REG(x1) + +- /* Use a stack frame allocated by our caller. */ +-#if defined(HAVE_PTRAUTH) && defined(__APPLE__) ++#if defined(HAVE_ARM64E_PTRAUTH) && defined(__APPLE__) + /* darwin's libunwind assumes that the cfa is the sp and that's the data + * used to sign the lr. In order to allow unwinding through this + * function it is necessary to point the cfa at the signing register. + */ + cfi_def_cfa(x1, 0); +-#else +- cfi_def_cfa(x1, 40); + #endif ++ /* Use a stack frame allocated by our caller. */ + stp x29, x30, [x1] ++ cfi_def_cfa_register(x1) ++ cfi_rel_offset (x29, 0) ++ cfi_rel_offset (x30, 8) + mov x9, sp + str x9, [x1, #32] + mov x29, x1 +- mov sp, x0 + cfi_def_cfa_register(x29) +- cfi_rel_offset (x29, 0) +- cfi_rel_offset (x30, 8) ++ mov sp, x0 + + mov x9, x2 /* save fn */ + mov x8, x3 /* install structure return */ +@@ -326,6 +326,7 @@ CNAME(ffi_closure_SYSV_V): + cfi_startproc + BTI_C + SIGN_LR ++ PAC_CFI_WINDOW_SAVE + stp x29, x30, [sp, #-ffi_closure_SYSV_FS]! + cfi_adjust_cfa_offset (ffi_closure_SYSV_FS) + cfi_rel_offset (x29, 0) +@@ -351,6 +352,7 @@ CNAME(ffi_closure_SYSV_V): + CNAME(ffi_closure_SYSV): + BTI_C + SIGN_LR ++ PAC_CFI_WINDOW_SAVE + stp x29, x30, [sp, #-ffi_closure_SYSV_FS]! + cfi_adjust_cfa_offset (ffi_closure_SYSV_FS) + cfi_rel_offset (x29, 0) +@@ -648,6 +650,8 @@ CNAME(ffi_go_closure_SYSV_V): + cfi_startproc + CNAME(ffi_go_closure_SYSV): + BTI_C ++ SIGN_LR_LINUX_ONLY ++ PAC_CFI_WINDOW_SAVE + stp x29, x30, [sp, #-ffi_closure_SYSV_FS]! + cfi_adjust_cfa_offset (ffi_closure_SYSV_FS) + cfi_rel_offset (x29, 0) +diff --git a/src/closures.c b/src/closures.c +index 67a94a8..02cf78f 100644 +--- a/src/closures.c ++++ b/src/closures.c +@@ -164,7 +164,7 @@ ffi_tramp_is_present (__attribute__((unused)) void *ptr) + + #include + #include +-#ifdef HAVE_PTRAUTH ++#ifdef HAVE_ARM64E_PTRAUTH + #include + #endif + #include +@@ -223,7 +223,7 @@ ffi_trampoline_table_alloc (void) + /* Remap the trampoline table on top of the placeholder page */ + trampoline_page = config_page + PAGE_MAX_SIZE; + +-#ifdef HAVE_PTRAUTH ++#ifdef HAVE_ARM64E_PTRAUTH + trampoline_page_template = (vm_address_t)(uintptr_t)ptrauth_auth_data((void *)&ffi_closure_trampoline_table_page, ptrauth_key_function_pointer, 0); + #else + trampoline_page_template = (vm_address_t)&ffi_closure_trampoline_table_page; +@@ -268,7 +268,7 @@ ffi_trampoline_table_alloc (void) + ffi_trampoline_table_entry *entry = &table->free_list_pool[i]; + entry->trampoline = + (void *) (trampoline_page + (i * FFI_TRAMPOLINE_SIZE)); +-#ifdef HAVE_PTRAUTH ++#ifdef HAVE_ARM64E_PTRAUTH + entry->trampoline = ptrauth_sign_unauthenticated(entry->trampoline, ptrauth_key_function_pointer, 0); + #endif + +-- +2.46.0 + diff --git a/0005-Import-from-upstream.patch b/0005-Import-from-upstream.patch new file mode 100644 index 0000000..5e68935 --- /dev/null +++ b/0005-Import-from-upstream.patch @@ -0,0 +1,758 @@ +From 6993bc14dad1cd24294d64bf91e4503a4d7835d6 Mon Sep 17 00:00:00 2001 +From: Anthony Green +Date: Sat, 1 Jun 2024 13:42:29 -0400 +Subject: [PATCH 5/7] Import from upstream +Content-type: text/plain; charset=UTF-8 + +--- + config.guess | 102 +++++++++++++++++----- + config.sub | 241 ++++++++++++++++++++++++++++++++++----------------- + 2 files changed, 240 insertions(+), 103 deletions(-) + +diff --git a/config.guess b/config.guess +index 7f76b62..f6d217a 100644 +--- a/config.guess ++++ b/config.guess +@@ -1,10 +1,10 @@ + #! /bin/sh + # Attempt to guess a canonical system name. +-# Copyright 1992-2022 Free Software Foundation, Inc. ++# Copyright 1992-2024 Free Software Foundation, Inc. + + # shellcheck disable=SC2006,SC2268 # see below for rationale + +-timestamp='2022-01-09' ++timestamp='2024-01-01' + + # This file is free software; you can redistribute it and/or modify it + # under the terms of the GNU General Public License as published by +@@ -47,7 +47,7 @@ me=`echo "$0" | sed -e 's,.*/,,'` + usage="\ + Usage: $0 [OPTION] + +-Output the configuration name of the system \`$me' is run on. ++Output the configuration name of the system '$me' is run on. + + Options: + -h, --help print this help, then exit +@@ -60,13 +60,13 @@ version="\ + GNU config.guess ($timestamp) + + Originally written by Per Bothner. +-Copyright 1992-2022 Free Software Foundation, Inc. ++Copyright 1992-2024 Free Software Foundation, Inc. + + This is free software; see the source for copying conditions. There is NO + warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." + + help=" +-Try \`$me --help' for more information." ++Try '$me --help' for more information." + + # Parse command line + while test $# -gt 0 ; do +@@ -102,8 +102,8 @@ GUESS= + # temporary files to be created and, as you can see below, it is a + # headache to deal with in a portable fashion. + +-# Historically, `CC_FOR_BUILD' used to be named `HOST_CC'. We still +-# use `HOST_CC' if defined, but it is deprecated. ++# Historically, 'CC_FOR_BUILD' used to be named 'HOST_CC'. We still ++# use 'HOST_CC' if defined, but it is deprecated. + + # Portable tmp directory creation inspired by the Autoconf team. + +@@ -155,6 +155,9 @@ Linux|GNU|GNU/*) + + set_cc_for_build + cat <<-EOF > "$dummy.c" ++ #if defined(__ANDROID__) ++ LIBC=android ++ #else + #include + #if defined(__UCLIBC__) + LIBC=uclibc +@@ -162,6 +165,8 @@ Linux|GNU|GNU/*) + LIBC=dietlibc + #elif defined(__GLIBC__) + LIBC=gnu ++ #elif defined(__LLVM_LIBC__) ++ LIBC=llvm + #else + #include + /* First heuristic to detect musl libc. */ +@@ -169,6 +174,7 @@ Linux|GNU|GNU/*) + LIBC=musl + #endif + #endif ++ #endif + EOF + cc_set_libc=`$CC_FOR_BUILD -E "$dummy.c" 2>/dev/null | grep '^LIBC' | sed 's, ,,g'` + eval "$cc_set_libc" +@@ -459,7 +465,7 @@ case $UNAME_MACHINE:$UNAME_SYSTEM:$UNAME_RELEASE:$UNAME_VERSION in + UNAME_RELEASE=`uname -v` + ;; + esac +- # Japanese Language versions have a version number like `4.1.3-JL'. ++ # Japanese Language versions have a version number like '4.1.3-JL'. + SUN_REL=`echo "$UNAME_RELEASE" | sed -e 's/-/_/'` + GUESS=sparc-sun-sunos$SUN_REL + ;; +@@ -904,7 +910,7 @@ EOF + fi + ;; + *:FreeBSD:*:*) +- UNAME_PROCESSOR=`/usr/bin/uname -p` ++ UNAME_PROCESSOR=`uname -p` + case $UNAME_PROCESSOR in + amd64) + UNAME_PROCESSOR=x86_64 ;; +@@ -966,11 +972,37 @@ EOF + GNU_REL=`echo "$UNAME_RELEASE" | sed -e 's/[-(].*//'` + GUESS=$UNAME_MACHINE-unknown-$GNU_SYS$GNU_REL-$LIBC + ;; ++ x86_64:[Mm]anagarm:*:*|i?86:[Mm]anagarm:*:*) ++ GUESS="$UNAME_MACHINE-pc-managarm-mlibc" ++ ;; ++ *:[Mm]anagarm:*:*) ++ GUESS="$UNAME_MACHINE-unknown-managarm-mlibc" ++ ;; + *:Minix:*:*) + GUESS=$UNAME_MACHINE-unknown-minix + ;; + aarch64:Linux:*:*) +- GUESS=$UNAME_MACHINE-unknown-linux-$LIBC ++ set_cc_for_build ++ CPU=$UNAME_MACHINE ++ LIBCABI=$LIBC ++ if test "$CC_FOR_BUILD" != no_compiler_found; then ++ ABI=64 ++ sed 's/^ //' << EOF > "$dummy.c" ++ #ifdef __ARM_EABI__ ++ #ifdef __ARM_PCS_VFP ++ ABI=eabihf ++ #else ++ ABI=eabi ++ #endif ++ #endif ++EOF ++ cc_set_abi=`$CC_FOR_BUILD -E "$dummy.c" 2>/dev/null | grep '^ABI' | sed 's, ,,g'` ++ eval "$cc_set_abi" ++ case $ABI in ++ eabi | eabihf) CPU=armv8l; LIBCABI=$LIBC$ABI ;; ++ esac ++ fi ++ GUESS=$CPU-unknown-linux-$LIBCABI + ;; + aarch64_be:Linux:*:*) + UNAME_MACHINE=aarch64_be +@@ -1036,7 +1068,16 @@ EOF + k1om:Linux:*:*) + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; +- loongarch32:Linux:*:* | loongarch64:Linux:*:* | loongarchx32:Linux:*:*) ++ kvx:Linux:*:*) ++ GUESS=$UNAME_MACHINE-unknown-linux-$LIBC ++ ;; ++ kvx:cos:*:*) ++ GUESS=$UNAME_MACHINE-unknown-cos ++ ;; ++ kvx:mbr:*:*) ++ GUESS=$UNAME_MACHINE-unknown-mbr ++ ;; ++ loongarch32:Linux:*:* | loongarch64:Linux:*:*) + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; + m32r*:Linux:*:*) +@@ -1151,16 +1192,27 @@ EOF + ;; + x86_64:Linux:*:*) + set_cc_for_build ++ CPU=$UNAME_MACHINE + LIBCABI=$LIBC + if test "$CC_FOR_BUILD" != no_compiler_found; then +- if (echo '#ifdef __ILP32__'; echo IS_X32; echo '#endif') | \ +- (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | \ +- grep IS_X32 >/dev/null +- then +- LIBCABI=${LIBC}x32 +- fi ++ ABI=64 ++ sed 's/^ //' << EOF > "$dummy.c" ++ #ifdef __i386__ ++ ABI=x86 ++ #else ++ #ifdef __ILP32__ ++ ABI=x32 ++ #endif ++ #endif ++EOF ++ cc_set_abi=`$CC_FOR_BUILD -E "$dummy.c" 2>/dev/null | grep '^ABI' | sed 's, ,,g'` ++ eval "$cc_set_abi" ++ case $ABI in ++ x86) CPU=i686 ;; ++ x32) LIBCABI=${LIBC}x32 ;; ++ esac + fi +- GUESS=$UNAME_MACHINE-pc-linux-$LIBCABI ++ GUESS=$CPU-pc-linux-$LIBCABI + ;; + xtensa*:Linux:*:*) + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC +@@ -1180,7 +1232,7 @@ EOF + GUESS=$UNAME_MACHINE-pc-sysv4.2uw$UNAME_VERSION + ;; + i*86:OS/2:*:*) +- # If we were able to find `uname', then EMX Unix compatibility ++ # If we were able to find 'uname', then EMX Unix compatibility + # is probably installed. + GUESS=$UNAME_MACHINE-pc-os2-emx + ;; +@@ -1321,7 +1373,7 @@ EOF + GUESS=ns32k-sni-sysv + fi + ;; +- PENTIUM:*:4.0*:*) # Unisys `ClearPath HMP IX 4000' SVR4/MP effort ++ PENTIUM:*:4.0*:*) # Unisys 'ClearPath HMP IX 4000' SVR4/MP effort + # says + GUESS=i586-unisys-sysv4 + ;; +@@ -1367,8 +1419,11 @@ EOF + BePC:Haiku:*:*) # Haiku running on Intel PC compatible. + GUESS=i586-pc-haiku + ;; +- x86_64:Haiku:*:*) +- GUESS=x86_64-unknown-haiku ++ ppc:Haiku:*:*) # Haiku running on Apple PowerPC ++ GUESS=powerpc-apple-haiku ++ ;; ++ *:Haiku:*:*) # Haiku modern gcc (not bound by BeOS compat) ++ GUESS=$UNAME_MACHINE-unknown-haiku + ;; + SX-4:SUPER-UX:*:*) + GUESS=sx4-nec-superux$UNAME_RELEASE +@@ -1540,6 +1595,9 @@ EOF + *:Unleashed:*:*) + GUESS=$UNAME_MACHINE-unknown-unleashed$UNAME_RELEASE + ;; ++ *:Ironclad:*:*) ++ GUESS=$UNAME_MACHINE-unknown-ironclad ++ ;; + esac + + # Do we have a guess based on uname results? +diff --git a/config.sub b/config.sub +index 630b5d9..2c6a07a 100755 +--- a/config.sub ++++ b/config.sub +@@ -1,10 +1,10 @@ + #! /bin/sh + # Configuration validation subroutine script. +-# Copyright 1992-2022 Free Software Foundation, Inc. ++# Copyright 1992-2024 Free Software Foundation, Inc. + + # shellcheck disable=SC2006,SC2268 # see below for rationale + +-timestamp='2022-01-03' ++timestamp='2024-01-01' + + # This file is free software; you can redistribute it and/or modify it + # under the terms of the GNU General Public License as published by +@@ -76,13 +76,13 @@ Report bugs and patches to ." + version="\ + GNU config.sub ($timestamp) + +-Copyright 1992-2022 Free Software Foundation, Inc. ++Copyright 1992-2024 Free Software Foundation, Inc. + + This is free software; see the source for copying conditions. There is NO + warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." + + help=" +-Try \`$me --help' for more information." ++Try '$me --help' for more information." + + # Parse command line + while test $# -gt 0 ; do +@@ -130,7 +130,7 @@ IFS=$saved_IFS + # Separate into logical components for further validation + case $1 in + *-*-*-*-*) +- echo Invalid configuration \`"$1"\': more than four components >&2 ++ echo "Invalid configuration '$1': more than four components" >&2 + exit 1 + ;; + *-*-*-*) +@@ -145,7 +145,8 @@ case $1 in + nto-qnx* | linux-* | uclinux-uclibc* \ + | uclinux-gnu* | kfreebsd*-gnu* | knetbsd*-gnu* | netbsd*-gnu* \ + | netbsd*-eabi* | kopensolaris*-gnu* | cloudabi*-eabi* \ +- | storm-chaos* | os2-emx* | rtmk-nova*) ++ | storm-chaos* | os2-emx* | rtmk-nova* | managarm-* \ ++ | windows-* ) + basic_machine=$field1 + basic_os=$maybe_os + ;; +@@ -943,7 +944,7 @@ $basic_machine + EOF + IFS=$saved_IFS + ;; +- # We use `pc' rather than `unknown' ++ # We use 'pc' rather than 'unknown' + # because (1) that's what they normally are, and + # (2) the word "unknown" tends to confuse beginning users. + i*86 | x86_64) +@@ -1075,7 +1076,7 @@ case $cpu-$vendor in + pentium-* | p5-* | k5-* | k6-* | nexgen-* | viac3-*) + cpu=i586 + ;; +- pentiumpro-* | p6-* | 6x86-* | athlon-* | athalon_*-*) ++ pentiumpro-* | p6-* | 6x86-* | athlon-* | athlon_*-*) + cpu=i686 + ;; + pentiumii-* | pentium2-* | pentiumiii-* | pentium3-*) +@@ -1126,7 +1127,7 @@ case $cpu-$vendor in + xscale-* | xscalee[bl]-*) + cpu=`echo "$cpu" | sed 's/^xscale/arm/'` + ;; +- arm64-* | arm64_32-* | aarch64le-*) ++ arm64-* | aarch64le-*) + cpu=aarch64 + ;; + +@@ -1180,7 +1181,7 @@ case $cpu-$vendor in + case $cpu in + 1750a | 580 \ + | a29k \ +- | aarch64 | aarch64_be \ ++ | aarch64 | aarch64_be | aarch64c | arm64ec \ + | abacus \ + | alpha | alphaev[4-8] | alphaev56 | alphaev6[78] \ + | alpha64 | alpha64ev[4-8] | alpha64ev56 | alpha64ev6[78] \ +@@ -1199,50 +1200,29 @@ case $cpu-$vendor in + | d10v | d30v | dlx | dsp16xx \ + | e2k | elxsi | epiphany \ + | f30[01] | f700 | fido | fr30 | frv | ft32 | fx80 \ ++ | javascript \ + | h8300 | h8500 \ + | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \ + | hexagon \ + | i370 | i*86 | i860 | i960 | ia16 | ia64 \ + | ip2k | iq2000 \ + | k1om \ ++ | kvx \ + | le32 | le64 \ + | lm32 \ +- | loongarch32 | loongarch64 | loongarchx32 \ ++ | loongarch32 | loongarch64 \ + | m32c | m32r | m32rle \ + | m5200 | m68000 | m680[012346]0 | m68360 | m683?2 | m68k \ + | m6811 | m68hc11 | m6812 | m68hc12 | m68hcs12x \ + | m88110 | m88k | maxq | mb | mcore | mep | metag \ + | microblaze | microblazeel \ +- | mips | mipsbe | mipseb | mipsel | mipsle \ +- | mips16 \ +- | mips64 | mips64eb | mips64el \ +- | mips64octeon | mips64octeonel \ +- | mips64orion | mips64orionel \ +- | mips64r5900 | mips64r5900el \ +- | mips64vr | mips64vrel \ +- | mips64vr4100 | mips64vr4100el \ +- | mips64vr4300 | mips64vr4300el \ +- | mips64vr5000 | mips64vr5000el \ +- | mips64vr5900 | mips64vr5900el \ +- | mipsisa32 | mipsisa32el \ +- | mipsisa32r2 | mipsisa32r2el \ +- | mipsisa32r3 | mipsisa32r3el \ +- | mipsisa32r5 | mipsisa32r5el \ +- | mipsisa32r6 | mipsisa32r6el \ +- | mipsisa64 | mipsisa64el \ +- | mipsisa64r2 | mipsisa64r2el \ +- | mipsisa64r3 | mipsisa64r3el \ +- | mipsisa64r5 | mipsisa64r5el \ +- | mipsisa64r6 | mipsisa64r6el \ +- | mipsisa64sb1 | mipsisa64sb1el \ +- | mipsisa64sr71k | mipsisa64sr71kel \ +- | mipsr5900 | mipsr5900el \ +- | mipstx39 | mipstx39el \ ++ | mips* \ + | mmix \ + | mn10200 | mn10300 \ + | moxie \ + | mt \ + | msp430 \ ++ | nanomips* \ + | nds32 | nds32le | nds32be \ + | nfp \ + | nios | nios2 | nios2eb | nios2el \ +@@ -1274,6 +1254,7 @@ case $cpu-$vendor in + | ubicom32 \ + | v70 | v850 | v850e | v850e1 | v850es | v850e2 | v850e2v3 \ + | vax \ ++ | vc4 \ + | visium \ + | w65 \ + | wasm32 | wasm64 \ +@@ -1285,7 +1266,7 @@ case $cpu-$vendor in + ;; + + *) +- echo Invalid configuration \`"$1"\': machine \`"$cpu-$vendor"\' not recognized 1>&2 ++ echo "Invalid configuration '$1': machine '$cpu-$vendor' not recognized" 1>&2 + exit 1 + ;; + esac +@@ -1306,11 +1287,12 @@ esac + + # Decode manufacturer-specific aliases for certain operating systems. + +-if test x$basic_os != x ++if test x"$basic_os" != x + then + + # First recognize some ad-hoc cases, or perhaps split kernel-os, or else just + # set os. ++obj= + case $basic_os in + gnu/linux*) + kernel=linux +@@ -1341,6 +1323,10 @@ EOF + kernel=linux + os=`echo "$basic_os" | sed -e 's|linux|gnu|'` + ;; ++ managarm*) ++ kernel=managarm ++ os=`echo "$basic_os" | sed -e 's|managarm|mlibc|'` ++ ;; + *) + kernel= + os=$basic_os +@@ -1506,10 +1492,16 @@ case $os in + os=eabi + ;; + *) +- os=elf ++ os= ++ obj=elf + ;; + esac + ;; ++ aout* | coff* | elf* | pe*) ++ # These are machine code file formats, not OSes ++ obj=$os ++ os= ++ ;; + *) + # No normalization, but not necessarily accepted, that comes below. + ;; +@@ -1528,12 +1520,15 @@ else + # system, and we'll never get to this point. + + kernel= ++obj= + case $cpu-$vendor in + score-*) +- os=elf ++ os= ++ obj=elf + ;; + spu-*) +- os=elf ++ os= ++ obj=elf + ;; + *-acorn) + os=riscix1.2 +@@ -1543,28 +1538,35 @@ case $cpu-$vendor in + os=gnu + ;; + arm*-semi) +- os=aout ++ os= ++ obj=aout + ;; + c4x-* | tic4x-*) +- os=coff ++ os= ++ obj=coff + ;; + c8051-*) +- os=elf ++ os= ++ obj=elf + ;; + clipper-intergraph) + os=clix + ;; + hexagon-*) +- os=elf ++ os= ++ obj=elf + ;; + tic54x-*) +- os=coff ++ os= ++ obj=coff + ;; + tic55x-*) +- os=coff ++ os= ++ obj=coff + ;; + tic6x-*) +- os=coff ++ os= ++ obj=coff + ;; + # This must come before the *-dec entry. + pdp10-*) +@@ -1586,19 +1588,24 @@ case $cpu-$vendor in + os=sunos3 + ;; + m68*-cisco) +- os=aout ++ os= ++ obj=aout + ;; + mep-*) +- os=elf ++ os= ++ obj=elf + ;; + mips*-cisco) +- os=elf ++ os= ++ obj=elf + ;; +- mips*-*) +- os=elf ++ mips*-*|nanomips*-*) ++ os= ++ obj=elf + ;; + or32-*) +- os=coff ++ os= ++ obj=coff + ;; + *-tti) # must be before sparc entry or we get the wrong os. + os=sysv3 +@@ -1607,7 +1614,8 @@ case $cpu-$vendor in + os=sunos4.1.1 + ;; + pru-*) +- os=elf ++ os= ++ obj=elf + ;; + *-be) + os=beos +@@ -1688,10 +1696,12 @@ case $cpu-$vendor in + os=uxpv + ;; + *-rom68k) +- os=coff ++ os= ++ obj=coff + ;; + *-*bug) +- os=coff ++ os= ++ obj=coff + ;; + *-apple) + os=macos +@@ -1709,10 +1719,11 @@ esac + + fi + +-# Now, validate our (potentially fixed-up) OS. ++# Now, validate our (potentially fixed-up) individual pieces (OS, OBJ). ++ + case $os in + # Sometimes we do "kernel-libc", so those need to count as OSes. +- musl* | newlib* | relibc* | uclibc*) ++ llvm* | musl* | newlib* | relibc* | uclibc*) + ;; + # Likewise for "kernel-abi" + eabi* | gnueabi*) +@@ -1720,6 +1731,9 @@ case $os in + # VxWorks passes extra cpu info in the 4th filed. + simlinux | simwindows | spe) + ;; ++ # See `case $cpu-$os` validation below ++ ghcjs) ++ ;; + # Now accept the basic system types. + # The portable systems comes first. + # Each alternative MUST end in a * to match a version number. +@@ -1728,7 +1742,7 @@ case $os in + | hpux* | unos* | osf* | luna* | dgux* | auroraux* | solaris* \ + | sym* | plan9* | psp* | sim* | xray* | os68k* | v88r* \ + | hiux* | abug | nacl* | netware* | windows* \ +- | os9* | macos* | osx* | ios* | watchos* | tvos* \ ++ | os9* | macos* | osx* | ios* | tvos* | watchos* \ + | mpw* | magic* | mmixware* | mon960* | lnews* \ + | amigaos* | amigados* | msdos* | newsos* | unicos* | aof* \ + | aos* | aros* | cloudabi* | sortix* | twizzler* \ +@@ -1737,11 +1751,11 @@ case $os in + | mirbsd* | netbsd* | dicos* | openedition* | ose* \ + | bitrig* | openbsd* | secbsd* | solidbsd* | libertybsd* | os108* \ + | ekkobsd* | freebsd* | riscix* | lynxos* | os400* \ +- | bosx* | nextstep* | cxux* | aout* | elf* | oabi* \ +- | ptx* | coff* | ecoff* | winnt* | domain* | vsta* \ ++ | bosx* | nextstep* | cxux* | oabi* \ ++ | ptx* | ecoff* | winnt* | domain* | vsta* \ + | udi* | lites* | ieee* | go32* | aux* | hcos* \ + | chorusrdb* | cegcc* | glidix* | serenity* \ +- | cygwin* | msys* | pe* | moss* | proelf* | rtems* \ ++ | cygwin* | msys* | moss* | proelf* | rtems* \ + | midipix* | mingw32* | mingw64* | mint* \ + | uxpv* | beos* | mpeix* | udk* | moxiebox* \ + | interix* | uwin* | mks* | rhapsody* | darwin* \ +@@ -1754,51 +1768,116 @@ case $os in + | onefs* | tirtos* | phoenix* | fuchsia* | redox* | bme* \ + | midnightbsd* | amdhsa* | unleashed* | emscripten* | wasi* \ + | nsk* | powerunix* | genode* | zvmoe* | qnx* | emx* | zephyr* \ +- | fiwix* ) ++ | fiwix* | mlibc* | cos* | mbr* | ironclad* ) + ;; + # This one is extra strict with allowed versions + sco3.2v2 | sco3.2v[4-9]* | sco5v6*) + # Don't forget version if it is 3.2v4 or newer. + ;; ++ # This refers to builds using the UEFI calling convention ++ # (which depends on the architecture) and PE file format. ++ # Note that this is both a different calling convention and ++ # different file format than that of GNU-EFI ++ # (x86_64-w64-mingw32). ++ uefi) ++ ;; + none) + ;; ++ kernel* | msvc* ) ++ # Restricted further below ++ ;; ++ '') ++ if test x"$obj" = x ++ then ++ echo "Invalid configuration '$1': Blank OS only allowed with explicit machine code file format" 1>&2 ++ fi ++ ;; ++ *) ++ echo "Invalid configuration '$1': OS '$os' not recognized" 1>&2 ++ exit 1 ++ ;; ++esac ++ ++case $obj in ++ aout* | coff* | elf* | pe*) ++ ;; ++ '') ++ # empty is fine ++ ;; + *) +- echo Invalid configuration \`"$1"\': OS \`"$os"\' not recognized 1>&2 ++ echo "Invalid configuration '$1': Machine code format '$obj' not recognized" 1>&2 ++ exit 1 ++ ;; ++esac ++ ++# Here we handle the constraint that a (synthetic) cpu and os are ++# valid only in combination with each other and nowhere else. ++case $cpu-$os in ++ # The "javascript-unknown-ghcjs" triple is used by GHC; we ++ # accept it here in order to tolerate that, but reject any ++ # variations. ++ javascript-ghcjs) ++ ;; ++ javascript-* | *-ghcjs) ++ echo "Invalid configuration '$1': cpu '$cpu' is not valid with os '$os$obj'" 1>&2 + exit 1 + ;; + esac + + # As a final step for OS-related things, validate the OS-kernel combination + # (given a valid OS), if there is a kernel. +-case $kernel-$os in +- linux-gnu* | linux-dietlibc* | linux-android* | linux-newlib* \ +- | linux-musl* | linux-relibc* | linux-uclibc* ) ++case $kernel-$os-$obj in ++ linux-gnu*- | linux-android*- | linux-dietlibc*- | linux-llvm*- \ ++ | linux-mlibc*- | linux-musl*- | linux-newlib*- \ ++ | linux-relibc*- | linux-uclibc*- ) ++ ;; ++ uclinux-uclibc*- ) ++ ;; ++ managarm-mlibc*- | managarm-kernel*- ) + ;; +- uclinux-uclibc* ) ++ windows*-msvc*-) + ;; +- -dietlibc* | -newlib* | -musl* | -relibc* | -uclibc* ) ++ -dietlibc*- | -llvm*- | -mlibc*- | -musl*- | -newlib*- | -relibc*- \ ++ | -uclibc*- ) + # These are just libc implementations, not actual OSes, and thus + # require a kernel. +- echo "Invalid configuration \`$1': libc \`$os' needs explicit kernel." 1>&2 ++ echo "Invalid configuration '$1': libc '$os' needs explicit kernel." 1>&2 + exit 1 + ;; +- kfreebsd*-gnu* | kopensolaris*-gnu*) ++ -kernel*- ) ++ echo "Invalid configuration '$1': '$os' needs explicit kernel." 1>&2 ++ exit 1 + ;; +- vxworks-simlinux | vxworks-simwindows | vxworks-spe) ++ *-kernel*- ) ++ echo "Invalid configuration '$1': '$kernel' does not support '$os'." 1>&2 ++ exit 1 + ;; +- nto-qnx*) ++ *-msvc*- ) ++ echo "Invalid configuration '$1': '$os' needs 'windows'." 1>&2 ++ exit 1 + ;; +- os2-emx) ++ kfreebsd*-gnu*- | kopensolaris*-gnu*-) ++ ;; ++ vxworks-simlinux- | vxworks-simwindows- | vxworks-spe-) ++ ;; ++ nto-qnx*-) ++ ;; ++ os2-emx-) + ;; +- ios*-simulator | tvos*-simulator | watchos*-simulator) ++ *-eabi*- | *-gnueabi*-) + ;; +- *-eabi* | *-gnueabi*) ++ none--*) ++ # None (no kernel, i.e. freestanding / bare metal), ++ # can be paired with an machine code file format + ;; +- -*) ++ -*-) + # Blank kernel with real OS is always fine. + ;; +- *-*) +- echo "Invalid configuration \`$1': Kernel \`$kernel' not known to work with OS \`$os'." 1>&2 ++ --*) ++ # Blank kernel and OS with real machine code file format is always fine. ++ ;; ++ *-*-*) ++ echo "Invalid configuration '$1': Kernel '$kernel' not known to work with OS '$os'." 1>&2 + exit 1 + ;; + esac +@@ -1881,7 +1960,7 @@ case $vendor in + ;; + esac + +-echo "$cpu-$vendor-${kernel:+$kernel-}$os" ++echo "$cpu-$vendor${kernel:+-$kernel}${os:+-$os}${obj:+-$obj}" + exit + + # Local variables: +-- +2.46.0 + diff --git a/0006-aarch64-Add-a-missing-no-op-define-of-SIGN_LR_LINUX_.patch b/0006-aarch64-Add-a-missing-no-op-define-of-SIGN_LR_LINUX_.patch new file mode 100644 index 0000000..bcf6f0f --- /dev/null +++ b/0006-aarch64-Add-a-missing-no-op-define-of-SIGN_LR_LINUX_.patch @@ -0,0 +1,37 @@ +From 9c9e8368e49804c4f7c35ac9f0d7c1d0d533308b Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Martin=20Storsj=C3=B6?= +Date: Tue, 4 Jun 2024 14:13:08 +0300 +Subject: [PATCH 6/7] aarch64: Add a missing no-op define of SIGN_LR_LINUX_ONLY + (#838) +Content-type: text/plain; charset=UTF-8 + +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 c39f9cb..50fa5c1 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 */ +-- +2.46.0 + diff --git a/0007-Fix-struct-args-Rainer-Orth.patch b/0007-Fix-struct-args-Rainer-Orth.patch new file mode 100644 index 0000000..cf2ec18 --- /dev/null +++ b/0007-Fix-struct-args-Rainer-Orth.patch @@ -0,0 +1,47 @@ +From 8e3ef965c2d0015ed129a06d0f11f30c2120a413 Mon Sep 17 00:00:00 2001 +From: Anthony Green +Date: Fri, 28 Jun 2024 04:07:09 -0400 +Subject: [PATCH 7/7] Fix struct args (Rainer Orth) +Content-type: text/plain; charset=UTF-8 + +--- + src/sparc/ffi.c | 16 ++++++++++++++++ + 1 file changed, 16 insertions(+) + +diff --git a/src/sparc/ffi.c b/src/sparc/ffi.c +index 9e406d0..cf819ee 100644 +--- a/src/sparc/ffi.c ++++ b/src/sparc/ffi.c +@@ -286,6 +286,8 @@ ffi_call_int (ffi_cif *cif, void (*fn)(void), void *rvalue, + void **avalue, void *closure) + { + size_t bytes = cif->bytes; ++ size_t i, nargs = cif->nargs; ++ ffi_type **arg_types = cif->arg_types; + + FFI_ASSERT (cif->abi == FFI_V8); + +@@ -295,6 +297,20 @@ ffi_call_int (ffi_cif *cif, void (*fn)(void), void *rvalue, + && (cif->flags & SPARC_FLAG_RET_MASK) == SPARC_RET_STRUCT) + bytes += FFI_ALIGN (cif->rtype->size, 8); + ++ /* If we have any structure arguments, make a copy so we are passing ++ by value. */ ++ for (i = 0; i < nargs; i++) ++ { ++ ffi_type *at = arg_types[i]; ++ int size = at->size; ++ if (at->type == FFI_TYPE_STRUCT) ++ { ++ char *argcopy = alloca (size); ++ memcpy (argcopy, avalue[i], size); ++ avalue[i] = argcopy; ++ } ++ } ++ + ffi_call_v8(cif, fn, rvalue, avalue, -bytes, closure); + } + +-- +2.46.0 + diff --git a/libffi.spec b/libffi.spec index cf2abf4..87590b8 100644 --- a/libffi.spec +++ b/libffi.spec @@ -4,7 +4,7 @@ Name: libffi Version: 3.4.6 -Release: 2%{?dist} +Release: 3%{?dist} Summary: A portable foreign function interface library # No license change for 3.4.6 # The following SPDX licenses are extracted from the sources using @@ -41,9 +41,19 @@ Source0: https://github.com/libffi/libffi/releases/download/v%{version}/libffi-% Source1: ffi-multilib.h Source2: ffitarget-multilib.h -# error: implicit declaration of function 'open_temp_exec_file' -# https://github.com/libffi/libffi/pull/764 -#Patch0: 0001-Forward-declare-open_temp_exec_file.patch +# Fix AArch64 BTI issues by pulling in upstream commits after 3.4.6. +# "Install ISO's die when run on an arm64 machine with BTI" +# https://bugzilla.redhat.com/show_bug.cgi?id=2305877 +# +# Patch numbers relative to v3.4.6 tag: +Patch0: 0001-Fix-bti-support-830.patch +Patch1: 0002-ffi-fix-spelling-mistake-833.patch +Patch2: 0003-aarch64-support-pointer-authentication-834.patch +# Skip manual fix to avoid needing makeinfo to build libffi. +# Patch3: 0004-A-fix-to-the-struct-type-example-837.patch +Patch4: 0005-Import-from-upstream.patch +Patch5: 0006-aarch64-Add-a-missing-no-op-define-of-SIGN_LR_LINUX_.patch +Patch6: 0007-Fix-struct-args-Rainer-Orth.patch BuildRequires: make BuildRequires: gcc @@ -145,6 +155,9 @@ install -m644 %{SOURCE2} $RPM_BUILD_ROOT%{_includedir}/ffitarget.h %{_infodir}/libffi.info.* %changelog +* Wed Aug 21 2024 Carlos O'Donell 3.4.6-3 +- Fix AArch64 BTI enablement issues (#2305877) + * Thu Jul 18 2024 Fedora Release Engineering - 3.4.6-2 - Rebuilt for https://fedoraproject.org/wiki/Fedora_41_Mass_Rebuild