diff options
Diffstat (limited to 'dev-libs/libffi')
-rw-r--r-- | dev-libs/libffi/Manifest | 13 | ||||
-rw-r--r-- | dev-libs/libffi/files/libffi-3.4.6-arm64-bti-spelling.patch | 26 | ||||
-rw-r--r-- | dev-libs/libffi/files/libffi-3.4.6-arm64-bti.patch | 82 | ||||
-rw-r--r-- | dev-libs/libffi/files/libffi-3.4.6-arm64-cfi.patch | 44 | ||||
-rw-r--r-- | dev-libs/libffi/files/libffi-3.4.6-arm64-fix-build.patch | 36 | ||||
-rw-r--r-- | dev-libs/libffi/files/libffi-3.4.6-arm64-support-pac.patch | 332 | ||||
-rw-r--r-- | dev-libs/libffi/files/libffi-3.4.6-asan.patch | 88 | ||||
-rw-r--r-- | dev-libs/libffi/files/libffi-3.4.6-regenerate-autotools.patch | 48 | ||||
-rw-r--r-- | dev-libs/libffi/files/libffi-3.4.6-sparc-struct-targs.patch | 47 | ||||
-rw-r--r-- | dev-libs/libffi/files/libffi-3.4.6-test-typo.patch | 19 | ||||
-rw-r--r-- | dev-libs/libffi/files/libffi-3.4.6-tests.patch | 104 | ||||
-rw-r--r-- | dev-libs/libffi/files/libffi-3.4.6-x86-sse.patch | 124 | ||||
-rw-r--r-- | dev-libs/libffi/libffi-3.4.6-r2.ebuild | 95 | ||||
-rw-r--r-- | dev-libs/libffi/libffi-9999.ebuild | 81 |
14 files changed, 1139 insertions, 0 deletions
diff --git a/dev-libs/libffi/Manifest b/dev-libs/libffi/Manifest index 467c71b93763..919fa8bad7fc 100644 --- a/dev-libs/libffi/Manifest +++ b/dev-libs/libffi/Manifest @@ -4,8 +4,21 @@ AUX libffi-3.4.4-hppa-large-struct.patch 1129 BLAKE2B 3b172af9af01c629ce56730989 AUX libffi-3.4.4-lld-17.patch 828 BLAKE2B 3462bc7db0cf754cb14a9fa0de6377da401c78d021d5e86fc51501d78e4c1104bd821093047af557f1ef8bb375b2eff7c26972524bf179fdfd926089fd8fefc7 SHA512 48d804fe7167c373c0cb3aafc969aedf555651d698857a791062d81e77ba88ba5db3fcabdf975040e19298d418ae12161160fc31e5515017cfc441fc61e66e63 AUX libffi-3.4.4-sparc-float-typo.patch 830 BLAKE2B cdec73bd227f0bcfb077ae0383bdea782886015189da8f3ac89d693a94967f1055edaa34462815709327ebc8a2c3d195a89090b3553db0ee7fa03b92c2341043 SHA512 3314e46725276df7fc91032a2446b9a379d54e9eceee0875952424bd6fd8b6e41a5103bcb990865b18f59ab3264db3bd106474b27a24b3e00196e9257f111022 AUX libffi-3.4.4-trampoline-c99.patch 1174 BLAKE2B da7990d940b5b0e6944c5b87d599c4955b75224c4f679477fd89cafdfa2ec7cab175986b25db08f0674c56f012456a20bcfce4cdabca1feb224ebd6ebf741e40 SHA512 5ba4e178d4d15a6149bd0bfa44542329812a8c98bae6350b0d2c760c5d4c376cb789c1f313bc6004f458578b18718f23f35c900fb14e5e697b43a2ebd02d7e57 +AUX libffi-3.4.6-arm64-bti-spelling.patch 1002 BLAKE2B 6198423affb75e38ae84ece75263d187eab8049b9766f90de4ac0aae0285696bc278b5fd498ff2684cfcaa81983f34db3c381679bfd56b28a72604945fa6bee0 SHA512 a8f64b92fdc539fcdc56fb9563677d63e27a221f923d1bb823ff4a360e1a25934e6f92a1ef5433b155986e4aef5ff8eb7ce246fa0dd9b62fb52056253de9defe +AUX libffi-3.4.6-arm64-bti.patch 3035 BLAKE2B 8e5bf0629924e85e86310265f51715ee7a66ba777a131b179d238c1d363001d8cf4c5f09d77b432f5859b818bb71de2283dd375e3197436df4dd97d8ea998308 SHA512 e7453e250ef0a95ae8e9de3f86dfbc87a41aba28ce76845ae998bbabf0d386b271bf566604f398409493d518f0c0b625e72403b5e6933c39fc2604a999c73bc8 +AUX libffi-3.4.6-arm64-cfi.patch 1260 BLAKE2B 8d1de858574f98aeb5c9c34922940edb9538d5a129f223a34865b929b5e553f8134effa729e8618c0c3298e19bee0bd685c434045528b9b998575792de6aa7b8 SHA512 623e83462e23d0934818a2a771be2896ec59801f30d56e81a181c7d2da12e8c0bacc2a18809d8a9c004a36036abcc427cc0e26ec2468948a99baa97df8781074 +AUX libffi-3.4.6-arm64-fix-build.patch 1359 BLAKE2B 4213faffae10f6fe9d5df68b6cf32722963204d40be5d4db79af82526ad86fe4e06763f7edb2eba44a33546bd66634dc7df85fe90601e51df257ce8048c49c68 SHA512 96891a3c4de0f741fc96f22b6eda4e8db59440d3bd2a601e7ee9abe6b5af7b1cefbf710e38fed55b5733aba79a92a9240aacae16a53fb3677f4288b7b131d36c +AUX libffi-3.4.6-arm64-support-pac.patch 11600 BLAKE2B e399fb5919fc20dc8f342227b17401a5327272a3d8bbe7e2e55c7e22d0c0b5d6dbdc13e2eb32a5ca032cb9ee67b2ce61819914d6cb39c4ae3dda2ea3dee01bf6 SHA512 93ee04c62a41b21bd0b47e92246aa2c16f58805f22320a741cfa4c3b2c156edb1d214f1f45f71b327913d49dff69da92b6a9d61b204caf58affbf28f53bdec54 +AUX libffi-3.4.6-asan.patch 3180 BLAKE2B df2d6da347d556484f490f29494020849625d03f3b0e22822e2924fce218689c621df061aa4c80c2f98656a159d7545d175acf544c493bc78e696d495e1fc2f1 SHA512 8da8704fcece33935483d3823b0478d16600b0c13e1c26b1ddf89862d4e338662dd58ec259c8883017900366dbc44c59aa136622ae356594e31f582a0bb2256e +AUX libffi-3.4.6-regenerate-autotools.patch 2025 BLAKE2B 1995777379a703d2d837f0a2b0425204d83cc20e5023e01ed72f83491e000c778d479dfaa8d568304214c706ff5be607cbd1bf04fc79fee668616950c2d2034d SHA512 9717d46723aeaeaae96ba728707134539b8f477be425add221532b0391402ad3c09fcdc0f38234d06db8f5c044f16ff7ca9b8a68e31e8ee894f9af926e26154a +AUX libffi-3.4.6-sparc-struct-targs.patch 1440 BLAKE2B 5a9485f30b6f165e1121bbec4ed7c8cf9288870051c658e11c39d389b01737d90ba47b3d90afcb36d0508784535654a086e27a449dcab78757bf71f3fb06eea0 SHA512 e44e691cf5347ab229601892f13e12e99cbd85613a3a10f12dfe44eb1d9d9be56004b4b6641c66fbada40db52a25b2b3f620d58a442adf5e09458cead6b05ba2 +AUX libffi-3.4.6-test-typo.patch 765 BLAKE2B 3c27254852f6ebb6f879ec9b98ccdcbdf4e2cb06a44a40078a2316924b35098291c9f375eac667939624ddba4542c725c7cdb200f26acb2f3d28420f8256dc45 SHA512 29a2de08179e9928fc235aa5fddf44cde50f72d5ba091b13d73afbc284523c7fec00f2f389b1de32fd78cbb6b90d3b6346a0d1b6b4553095c1fab8bc22fe326e +AUX libffi-3.4.6-tests.patch 3398 BLAKE2B a3a6e7d1800ff27cb3bcfabd0a656ae47bfdcd3996083b4847bb7a78e2bc9256423bb8272663181227450996308dc4c73a9dc20d38ed6872c3b04aadfdf56439 SHA512 1153bf4cb32f5dfa873e11c932986a49cae2b48e6cfd04dba09f95399da8d19d0efdefe3b24e7a39970290513578db3170b9184f3f334ca03a0ad969fea5ff00 +AUX libffi-3.4.6-x86-sse.patch 3535 BLAKE2B d6d3a0f16fa69ced4d1c6667e784ecae293415d21d807bbf245152c57b7b2cc14ece57471c43797232b1bab90139e31a518d4a0af050c79f25d75c0981bd2475 SHA512 bb47364794bc17bad6447c243c5b72f05645e236f3bf0a45ab7b6aa16acf392d9a993efed6cd70c795319bc4c4330f8f6df67a477fc5c00253b5f87c7ef9b4f1 DIST libffi-3.4.4.tar.gz 1362394 BLAKE2B 189fe1ffe9507f204581b0ab09995dc7e7b761bb4eac7e338e9f5ff81431aebcef6c182c1839c9f9acb2706697a260c67e6d1351cf7e2aed7c4eb5d694f6f8fd SHA512 88680aeb0fa0dc0319e5cd2ba45b4b5a340bc9b4bcf20b1e0613b39cd898f177a3863aa94034d8e23a7f6f44d858a53dcd36d1bb8dee13b751ef814224061889 DIST libffi-3.4.6.tar.gz 1391684 BLAKE2B af8402a09bdbd59b4e9400d2d71bd5ce98f6f1d981d35d1ab40d77a831b13b32c5bd34ca54ff75999e39f0d8a9c066381fae7a8d6c5216d955e064f929f08b88 SHA512 033d2600e879b83c6bce0eb80f69c5f32aa775bf2e962c9d39fbd21226fa19d1e79173d8eaa0d0157014d54509ea73315ad86842356fc3a303c0831c94c6ab39 EBUILD libffi-3.4.4-r4.ebuild 2540 BLAKE2B 6a85dd1d002e6ec61c57a4d5db58a20ff58e987da7ceb6630abfdd08ebd9f2fad574c29ab10d7a623310bb61b161e4c26c23a5d26af91e67bfa193d191e8a822 SHA512 f5d4049d6e5fe432321df11c0295a7bc579212eb5db54613d0ecc986975bdae1d9f26b9abcd9949db7e2efe156f4e5c9f8a90d870b9cf380308a848ad533c747 +EBUILD libffi-3.4.6-r2.ebuild 2828 BLAKE2B 335b24a19f4c0cf5e8d4b7076adca08f902d20992fee8f37af17ea1f3620af5aaa01c96f63f7b5fda49e9a88a7c8f435539fef84f2f20d591e8cbd9e5a5f65b7 SHA512 d9f8583dcc6f7ab61f8e47b30d5075f1c553ffb3754f52af923be0182b573008be9e65adeb9683cb89bbfba8f9c7584691d9b5178d0c91dabcdb0c93e0bcf9fa EBUILD libffi-3.4.6.ebuild 2270 BLAKE2B a8af8687618bc1541f71db585727f33228b96c446729761accd7e2dc3ebd59de141e629371b97a3e7fc6e7c412f4696a7cac7e02ca8c271e103747f7c9d439b4 SHA512 6447b4fd561836bee7cd7148f1b2fdf7e100ffa292a1e94051aca03ed19acf5446f1db74241e6ecc445317f272b3773930f1184f25588658aa12234472897ce0 +EBUILD libffi-9999.ebuild 2387 BLAKE2B 02ccc0b986ef2b4cd58ccb86dcdfd44777719d214d0f43262c6d8e6d9d14425d09096b62b1713727f4ee9d330a9efa83c889677bf14cac73e1b2367924231f97 SHA512 2a776a077a95ccae1641d26a4f942b383d04958e507900c1914620fe3070ef0918d8867ee67b82495a731ba416c5987a333a1dfd99c5f9377957bfa707c64edc MISC metadata.xml 2110 BLAKE2B 2653be2cf09c047e45e489d7265d00165ddab2f94744988e4e8bca449bd1e40eeab74cb0b8d7d47a2d8b73563869460fcccb06e1fbccad697a9f213be362cb03 SHA512 e1a280792b929d38451fea1eb360053ed3a452592094f3e327ce4a4ff7eb8e0119435e8ee98f215585d8d98440512b5b68f92d1cd472a3bfd12e2f382e1981a1 diff --git a/dev-libs/libffi/files/libffi-3.4.6-arm64-bti-spelling.patch b/dev-libs/libffi/files/libffi-3.4.6-arm64-bti-spelling.patch new file mode 100644 index 000000000000..2a06292546d0 --- /dev/null +++ b/dev-libs/libffi/files/libffi-3.4.6-arm64-bti-spelling.patch @@ -0,0 +1,26 @@ +https://github.com/libffi/libffi/commit/38732240c125b6af9db66d940c0725a69292cc49 + +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] ffi: fix spelling mistake (#833) + +Signed-off-by: Bill Roberts <bill.roberts@arm.com> +--- + 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; + diff --git a/dev-libs/libffi/files/libffi-3.4.6-arm64-bti.patch b/dev-libs/libffi/files/libffi-3.4.6-arm64-bti.patch new file mode 100644 index 000000000000..ad8a95ae506d --- /dev/null +++ b/dev-libs/libffi/files/libffi-3.4.6-arm64-bti.patch @@ -0,0 +1,82 @@ +https://github.com/libffi/libffi/issues/855 +https://github.com/libffi/libffi/commit/f64141ee3f9e455a060bd09e9ab72b6c94653d7c + +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] 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 <bill.roberts@arm.com> + +* testsuite: fix whitespace in Makefile.am + +Signed-off-by: Bill Roberts <bill.roberts@arm.com> + +* 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 <bill.roberts@arm.com> + +--------- + +Signed-off-by: Bill Roberts <bill.roberts@arm.com> +--- + 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 \ + diff --git a/dev-libs/libffi/files/libffi-3.4.6-arm64-cfi.patch b/dev-libs/libffi/files/libffi-3.4.6-arm64-cfi.patch new file mode 100644 index 000000000000..0eb4cf807f3b --- /dev/null +++ b/dev-libs/libffi/files/libffi-3.4.6-arm64-cfi.patch @@ -0,0 +1,44 @@ +https://github.com/libffi/libffi/pull/857 +https://github.com/libffi/libffi/commit/8308bed5b2423878aa20d7884a99cf2e30b8daf7 + +From 3065c530d3aa50c2b5ee9c01f88a9c0b61732805 Mon Sep 17 00:00:00 2001 +From: Ivan Tadeu Ferreira Antunes Filho <antunesi@google.com> +Date: Mon, 16 Sep 2024 16:10:39 -0400 +Subject: [PATCH] Move cfi_startproc after CNAME(label) + +This is a fix for https://github.com/libffi/libffi/issues/852: error: invalid CFI advance_loc expression on apple targets. + +The CFI for darwin arm64 was broken because the CNAME macro was being used after the +cfi_startproc macro. +--- a/src/aarch64/sysv.S ++++ b/src/aarch64/sysv.S +@@ -89,8 +89,8 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ + x5 closure + */ + +- cfi_startproc + CNAME(ffi_call_SYSV): ++ cfi_startproc + BTI_C + PAC_CFI_WINDOW_SAVE + /* Sign the lr with x1 since that is the CFA which is the modifer used in auth instructions */ +@@ -348,8 +348,8 @@ CNAME(ffi_closure_SYSV_V): + #endif + + .align 4 +- cfi_startproc + CNAME(ffi_closure_SYSV): ++ cfi_startproc + BTI_C + SIGN_LR + PAC_CFI_WINDOW_SAVE +@@ -647,8 +647,8 @@ CNAME(ffi_go_closure_SYSV_V): + #endif + + .align 4 +- cfi_startproc + CNAME(ffi_go_closure_SYSV): ++ cfi_startproc + BTI_C + SIGN_LR_LINUX_ONLY + PAC_CFI_WINDOW_SAVE diff --git a/dev-libs/libffi/files/libffi-3.4.6-arm64-fix-build.patch b/dev-libs/libffi/files/libffi-3.4.6-arm64-fix-build.patch new file mode 100644 index 000000000000..20eaf6a2d8cd --- /dev/null +++ b/dev-libs/libffi/files/libffi-3.4.6-arm64-fix-build.patch @@ -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?= <martin@martin.st> +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 */ + diff --git a/dev-libs/libffi/files/libffi-3.4.6-arm64-support-pac.patch b/dev-libs/libffi/files/libffi-3.4.6-arm64-support-pac.patch new file mode 100644 index 000000000000..288533367499 --- /dev/null +++ b/dev-libs/libffi/files/libffi-3.4.6-arm64-support-pac.patch @@ -0,0 +1,332 @@ +https://github.com/libffi/libffi/commit/45d284f2d066cc3a080c5be88e51b4d934349797 + +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] aarch64: support pointer authentication (#834) + +* 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 <bill.roberts@arm.com> + +* 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 <bill.roberts@arm.com> + +* 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 <bill.roberts@arm.com> + +* 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 <bill.roberts@arm.com> + +--------- + +Signed-off-by: Bill Roberts <bill.roberts@arm.com> +--- + 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 816bfd666..b35a999fb 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 f4c292d00..856566324 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 b13738e38..964934dfb 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 <ptrauth.h> + #endif + #include <mach/vm_param.h> +@@ -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 b5d102b4a..c39f9cb22 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 60cfa505b..6a9a5611f 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 67a94a822..02cf78fa2 100644 +--- a/src/closures.c ++++ b/src/closures.c +@@ -164,7 +164,7 @@ ffi_tramp_is_present (__attribute__((unused)) void *ptr) + + #include <mach/mach.h> + #include <pthread.h> +-#ifdef HAVE_PTRAUTH ++#ifdef HAVE_ARM64E_PTRAUTH + #include <ptrauth.h> + #endif + #include <stdio.h> +@@ -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 + + diff --git a/dev-libs/libffi/files/libffi-3.4.6-asan.patch b/dev-libs/libffi/files/libffi-3.4.6-asan.patch new file mode 100644 index 000000000000..4c62f970a3c9 --- /dev/null +++ b/dev-libs/libffi/files/libffi-3.4.6-asan.patch @@ -0,0 +1,88 @@ +https://github.com/libffi/libffi/commit/01db744b4af8665f9b7494d00cc2a1cc45ee9636 + +From 01db744b4af8665f9b7494d00cc2a1cc45ee9636 Mon Sep 17 00:00:00 2001 +From: KJ Tsanaktsidis <kj@kjtsanaktsidis.id.au> +Date: Fri, 20 Sep 2024 20:00:49 +1000 +Subject: [PATCH] Disable ASAN in ffi_call_int functions (#858) + +The pattern for several of the architectures is for ffi_call_int to +stack-allocate some arguments + the registers, and then +ffi_call_$ARCH will pop the top of that structure into registers, and +then adjust the stack pointer such that the alloca'd buffer _becomes_ +the stack-passed arguments for the function being called. + +If libffi is compiled with ASAN, then there will be a redzone inserted +after the alloca'd buffer which is marked as poisoned. This redzone +appears beyond the end of $sp upon entry to the called function. + +If the called function does anything to use this stack memory, ASAN will +notice that it's poisoned and report an error. + +This commit fixes the situation (on the architectures that I have access +to) disabling instrumentation for ffi_call_int; that means there will be +no alloca redzone left on the shadow-stack. +--- a/include/ffi_common.h ++++ b/include/ffi_common.h +@@ -83,6 +83,23 @@ char *alloca (); + #include <stdio.h> + #endif + ++#ifndef __SANITIZE_ADDRESS__ ++# ifdef __clang__ ++# if __has_feature(address_sanitizer) ++# define FFI_ASAN ++# endif ++# endif ++#endif ++#ifdef __SANITIZE_ADDRESS__ ++#define FFI_ASAN ++#endif ++ ++#ifdef FFI_ASAN ++#define FFI_ASAN_NO_SANITIZE __attribute__((no_sanitize_address)) ++#else ++#define FFI_ASAN_NO_SANITIZE ++#endif ++ + #ifdef FFI_DEBUG + NORETURN void ffi_assert(const char *expr, const char *file, int line); + void ffi_stop_here(void); +--- a/src/aarch64/ffi.c ++++ b/src/aarch64/ffi.c +@@ -645,7 +645,10 @@ extern void ffi_call_SYSV (struct call_context *context, void *frame, + void *closure) FFI_HIDDEN; + + /* Call a function with the provided arguments and capture the return +- value. */ ++ value. ++ n.b. ffi_call_SYSV will steal the alloca'd `stack` variable here for use ++ _as its own stack_ - so we need to compile this function without ASAN */ ++FFI_ASAN_NO_SANITIZE + static void + ffi_call_int (ffi_cif *cif, void (*fn)(void), void *orig_rvalue, + void **avalue, void *closure) +--- a/src/x86/ffi.c ++++ b/src/x86/ffi.c +@@ -270,6 +270,9 @@ extern void FFI_DECLARE_FASTCALL ffi_call_i386(struct call_frame *, char *) FFI_ + #if defined(_MSC_VER) + #pragma runtime_checks("s", off) + #endif ++/* n.b. ffi_call_unix64 will steal the alloca'd `stack` variable here for use ++ _as its own stack_ - so we need to compile this function without ASAN */ ++FFI_ASAN_NO_SANITIZE + static void + ffi_call_int (ffi_cif *cif, void (*fn)(void), void *rvalue, + void **avalue, void *closure) +--- a/src/x86/ffi64.c ++++ b/src/x86/ffi64.c +@@ -557,6 +557,9 @@ ffi_prep_cif_machdep (ffi_cif *cif) + return FFI_OK; + } + ++/* n.b. ffi_call_unix64 will steal the alloca'd `stack` variable here for use ++ _as its own stack_ - so we need to compile this function without ASAN */ ++FFI_ASAN_NO_SANITIZE + static void + ffi_call_int (ffi_cif *cif, void (*fn)(void), void *rvalue, + void **avalue, void *closure) + diff --git a/dev-libs/libffi/files/libffi-3.4.6-regenerate-autotools.patch b/dev-libs/libffi/files/libffi-3.4.6-regenerate-autotools.patch new file mode 100644 index 000000000000..81fe671f509c --- /dev/null +++ b/dev-libs/libffi/files/libffi-3.4.6-regenerate-autotools.patch @@ -0,0 +1,48 @@ +The arm64 patches we backported to 3.4.6 mean we need to autoreconf ourselves, +apply this patch to avoid needing to do it in the ebuild b/c of deps. +--- a/Makefile.in ++++ b/Makefile.in +@@ -330,8 +330,8 @@ am__define_uniq_tagged_files = \ + done | $(am__uniquify_input)` + DIST_SUBDIRS = include testsuite man doc + am__DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/fficonfig.h.in \ +- $(srcdir)/libffi.pc.in README.md compile config.guess \ +- config.sub depcomp install-sh ltmain.sh missing ++ $(srcdir)/libffi.pc.in ChangeLog README.md compile \ ++ config.guess config.sub depcomp install-sh ltmain.sh missing + DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) + distdir = $(PACKAGE)-$(VERSION) + top_distdir = $(distdir) +--- a/fficonfig.h.in ++++ b/fficonfig.h.in +@@ -31,6 +31,9 @@ + /* Define to 1 if you have the <alloca.h> header file. */ + #undef HAVE_ALLOCA_H + ++/* Define if your compiler supports pointer authentication. */ ++#undef HAVE_ARM64E_PTRAUTH ++ + /* Define if your assembler supports .cfi_* directives. */ + #undef HAVE_AS_CFI_PSEUDO_OP + +@@ -71,9 +74,6 @@ + /* Define to 1 if you have the `memfd_create' function. */ + #undef HAVE_MEMFD_CREATE + +-/* Define if your compiler supports pointer authentication. */ +-#undef HAVE_PTRAUTH +- + /* Define if .eh_frame sections should be read-only. */ + #undef HAVE_RO_EH_FRAME + +--- a/testsuite/Makefile.in ++++ b/testsuite/Makefile.in +@@ -292,7 +292,7 @@ EXTRA_DEJAGNU_SITE_CONFIG = ../local.exp + 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 \ diff --git a/dev-libs/libffi/files/libffi-3.4.6-sparc-struct-targs.patch b/dev-libs/libffi/files/libffi-3.4.6-sparc-struct-targs.patch new file mode 100644 index 000000000000..592e543f88ee --- /dev/null +++ b/dev-libs/libffi/files/libffi-3.4.6-sparc-struct-targs.patch @@ -0,0 +1,47 @@ +https://github.com/libffi/libffi/issues/841 +https://github.com/libffi/libffi/commit/8e3ef965c2d0015ed129a06d0f11f30c2120a413 + +From 8e3ef965c2d0015ed129a06d0f11f30c2120a413 Mon Sep 17 00:00:00 2001 +From: Anthony Green <green@moxielogic.com> +Date: Fri, 28 Jun 2024 04:07:09 -0400 +Subject: [PATCH] Fix struct args (Rainer Orth) + +--- + src/sparc/ffi.c | 16 ++++++++++++++++ + 1 file changed, 16 insertions(+) + +diff --git a/src/sparc/ffi.c b/src/sparc/ffi.c +index 9e406d0af..cf819ee67 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); + } + + diff --git a/dev-libs/libffi/files/libffi-3.4.6-test-typo.patch b/dev-libs/libffi/files/libffi-3.4.6-test-typo.patch new file mode 100644 index 000000000000..78beab646470 --- /dev/null +++ b/dev-libs/libffi/files/libffi-3.4.6-test-typo.patch @@ -0,0 +1,19 @@ +https://github.com/libffi/libffi/commit/f7e4992789fa563b4cc74521c37ff703555da21c + +From f7e4992789fa563b4cc74521c37ff703555da21c Mon Sep 17 00:00:00 2001 +From: Sam James <sam@cmpct.info> +Date: Fri, 20 Sep 2024 10:58:06 +0100 +Subject: [PATCH] testsuite: fix dejagnu directive typo (#859) + +--- a/testsuite/libffi.complex/complex_int.c ++++ b/testsuite/libffi.complex/complex_int.c +@@ -76,7 +76,7 @@ int main (void) + + printf ("%d,%di %d,%di, x %d 1234, y %d 11110\n", + (int)tc_result, (int)(tc_result * -I), 2, 8, tc_int_arg_x, tc_y); +- /* dg-output "-2,8i 2,8i, x 1234 1234, y 11110 11110" */ ++ /* { dg-output "-2,8i 2,8i, x 1234 1234, y 11110 11110" } */ + CHECK (creal (tc_result) == -2); + CHECK (cimag (tc_result) == 8); + CHECK (tc_int_arg_x == 1234); + diff --git a/dev-libs/libffi/files/libffi-3.4.6-tests.patch b/dev-libs/libffi/files/libffi-3.4.6-tests.patch new file mode 100644 index 000000000000..e24d01f4c028 --- /dev/null +++ b/dev-libs/libffi/files/libffi-3.4.6-tests.patch @@ -0,0 +1,104 @@ +https://github.com/libffi/libffi/commit/efb98a72d8b9bdb71b4f972efced073bee3b30fc +https://github.com/libffi/libffi/commit/92d384df196a099fde384f9178864dbfe8c6b0fc + +From efb98a72d8b9bdb71b4f972efced073bee3b30fc Mon Sep 17 00:00:00 2001 +From: Anthony Green <green@moxielogic.com> +Date: Sun, 15 Sep 2024 07:31:33 -0400 +Subject: [PATCH] Robustify floating point comparison in test + +--- + testsuite/libffi.call/struct_int_float.c | 24 ++++++++++++------------ + 1 file changed, 12 insertions(+), 12 deletions(-) + +diff --git a/testsuite/libffi.call/struct_int_float.c b/testsuite/libffi.call/struct_int_float.c +index dab1d1fed..82685814c 100644 +--- a/testsuite/libffi.call/struct_int_float.c ++++ b/testsuite/libffi.call/struct_int_float.c +@@ -54,35 +54,35 @@ int main (void) + values[4] = &ts_arg[4]; + args[5] = &ts_type; + values[5] = &ts_arg[5]; +- ++ + /* Initialize the cif */ + CHECK(ffi_prep_cif(&cif, ABI_NUM, 6, &ffi_type_float, args) == FFI_OK); +- ++ + ts_arg[0].i = 1; +- ts_arg[0].f = 1.11f; ++ ts_arg[0].f = 11.11f; + ts_arg[1].i = 2; +- ts_arg[1].f = 2.22f; ++ ts_arg[1].f = 22.22f; + ts_arg[2].i = 3; +- ts_arg[2].f = 3.33f; ++ ts_arg[2].f = 33.33f; + ts_arg[3].i = 4; +- ts_arg[3].f = 4.44f; ++ ts_arg[3].f = 44.44f; + ts_arg[4].i = 5; +- ts_arg[4].f = 5.55f; ++ ts_arg[4].f = 55.55f; + ts_arg[5].i = 6; +- ts_arg[5].f = 6.66f; +- ++ ts_arg[5].f = 66.66f; ++ + printf ("%g\n", ts_arg[0].f); + printf ("%g\n", ts_arg[1].f); + printf ("%g\n", ts_arg[2].f); + printf ("%g\n", ts_arg[3].f); + printf ("%g\n", ts_arg[4].f); + printf ("%g\n", ts_arg[5].f); +- ++ + ffi_call(&cif, FFI_FN(struct_int_float), &rfloat, values); + + printf ("%g\n", rfloat); +- +- CHECK(rfloat == 1.11f); ++ ++ CHECK(fabs(rfloat - 11.11) < FLT_EPSILON); + + exit(0); + } + +From 92d384df196a099fde384f9178864dbfe8c6b0fc Mon Sep 17 00:00:00 2001 +From: Anthony Green <green@moxielogic.com> +Date: Sun, 15 Sep 2024 12:32:29 -0400 +Subject: [PATCH] Fix floating point compare + +--- + testsuite/libffi.call/struct_int_float.c | 12 ++++++------ + 1 file changed, 6 insertions(+), 6 deletions(-) + +diff --git a/testsuite/libffi.call/struct_int_float.c b/testsuite/libffi.call/struct_int_float.c +index 82685814..66ef6c45 100644 +--- a/testsuite/libffi.call/struct_int_float.c ++++ b/testsuite/libffi.call/struct_int_float.c +@@ -14,11 +14,11 @@ typedef struct + } test_structure_int_float; + + static float ABI_ATTR struct_int_float(test_structure_int_float ts1, +- test_structure_int_float ts2, +- test_structure_int_float ts3, +- test_structure_int_float ts4, +- test_structure_int_float ts5, +- test_structure_int_float ts6) ++ test_structure_int_float ts2 __UNUSED__, ++ test_structure_int_float ts3 __UNUSED__, ++ test_structure_int_float ts4 __UNUSED__, ++ test_structure_int_float ts5 __UNUSED__, ++ test_structure_int_float ts6 __UNUSED__) + { + return ts1.f; + } +@@ -82,7 +82,7 @@ int main (void) + + printf ("%g\n", rfloat); + +- CHECK(fabs(rfloat - 11.11) < FLT_EPSILON); ++ CHECK(fabs(rfloat - 11.11) < 3 * FLT_EPSILON); + + exit(0); + } diff --git a/dev-libs/libffi/files/libffi-3.4.6-x86-sse.patch b/dev-libs/libffi/files/libffi-3.4.6-x86-sse.patch new file mode 100644 index 000000000000..75c0e892ef3a --- /dev/null +++ b/dev-libs/libffi/files/libffi-3.4.6-x86-sse.patch @@ -0,0 +1,124 @@ +https://github.com/libffi/libffi/commit/d21881f55ed4a44d464c9091871e69b0bb47611a + +From d21881f55ed4a44d464c9091871e69b0bb47611a Mon Sep 17 00:00:00 2001 +From: kellda <59569234+kellda@users.noreply.github.com> +Date: Sun, 15 Sep 2024 13:29:42 +0200 +Subject: [PATCH] Fix x86/ffi64 calls with 6 gp and some sse registers (#848) + +* Fix x86/ffi64 calls with 6 gp and some sse registers + +* Add test demonstating issue when mixing gp and sse registers +--- + src/x86/ffi64.c | 2 +- + testsuite/libffi.call/struct_int_float.c | 88 ++++++++++++++++++++++++ + 2 files changed, 89 insertions(+), 1 deletion(-) + create mode 100644 testsuite/libffi.call/struct_int_float.c + +diff --git a/src/x86/ffi64.c b/src/x86/ffi64.c +index 6a8e37fc5..39f0bfd33 100644 +--- a/src/x86/ffi64.c ++++ b/src/x86/ffi64.c +@@ -651,7 +651,7 @@ ffi_call_int (ffi_cif *cif, void (*fn)(void), void *rvalue, + break; + default: + reg_args->gpr[gprcount] = 0; +- memcpy (®_args->gpr[gprcount], a, size); ++ memcpy (®_args->gpr[gprcount], a, sizeof(UINT64)); + } + gprcount++; + break; +diff --git a/testsuite/libffi.call/struct_int_float.c b/testsuite/libffi.call/struct_int_float.c +new file mode 100644 +index 000000000..dab1d1fed +--- /dev/null ++++ b/testsuite/libffi.call/struct_int_float.c +@@ -0,0 +1,88 @@ ++/* Area: ffi_call ++ Purpose: Demonstrate structures with integers corrupting earlier floats ++ Limitations: none. ++ PR: #848 ++ Originator: kellda */ ++ ++/* { dg-do run } */ ++#include "ffitest.h" ++ ++typedef struct ++{ ++ unsigned long i; ++ float f; ++} test_structure_int_float; ++ ++static float ABI_ATTR struct_int_float(test_structure_int_float ts1, ++ test_structure_int_float ts2, ++ test_structure_int_float ts3, ++ test_structure_int_float ts4, ++ test_structure_int_float ts5, ++ test_structure_int_float ts6) ++{ ++ return ts1.f; ++} ++ ++int main (void) ++{ ++ ffi_cif cif; ++ ffi_type *args[MAX_ARGS]; ++ void *values[MAX_ARGS]; ++ ffi_type ts_type; ++ ffi_type *ts_type_elements[3]; ++ float rfloat; ++ ++ test_structure_int_float ts_arg[6]; ++ ++ ts_type.size = 0; ++ ts_type.alignment = 0; ++ ts_type.type = FFI_TYPE_STRUCT; ++ ts_type.elements = ts_type_elements; ++ ts_type_elements[0] = &ffi_type_ulong; ++ ts_type_elements[1] = &ffi_type_float; ++ ts_type_elements[2] = NULL; ++ ++ args[0] = &ts_type; ++ values[0] = &ts_arg[0]; ++ args[1] = &ts_type; ++ values[1] = &ts_arg[1]; ++ args[2] = &ts_type; ++ values[2] = &ts_arg[2]; ++ args[3] = &ts_type; ++ values[3] = &ts_arg[3]; ++ args[4] = &ts_type; ++ values[4] = &ts_arg[4]; ++ args[5] = &ts_type; ++ values[5] = &ts_arg[5]; ++ ++ /* Initialize the cif */ ++ CHECK(ffi_prep_cif(&cif, ABI_NUM, 6, &ffi_type_float, args) == FFI_OK); ++ ++ ts_arg[0].i = 1; ++ ts_arg[0].f = 1.11f; ++ ts_arg[1].i = 2; ++ ts_arg[1].f = 2.22f; ++ ts_arg[2].i = 3; ++ ts_arg[2].f = 3.33f; ++ ts_arg[3].i = 4; ++ ts_arg[3].f = 4.44f; ++ ts_arg[4].i = 5; ++ ts_arg[4].f = 5.55f; ++ ts_arg[5].i = 6; ++ ts_arg[5].f = 6.66f; ++ ++ printf ("%g\n", ts_arg[0].f); ++ printf ("%g\n", ts_arg[1].f); ++ printf ("%g\n", ts_arg[2].f); ++ printf ("%g\n", ts_arg[3].f); ++ printf ("%g\n", ts_arg[4].f); ++ printf ("%g\n", ts_arg[5].f); ++ ++ ffi_call(&cif, FFI_FN(struct_int_float), &rfloat, values); ++ ++ printf ("%g\n", rfloat); ++ ++ CHECK(rfloat == 1.11f); ++ ++ exit(0); ++} + diff --git a/dev-libs/libffi/libffi-3.4.6-r2.ebuild b/dev-libs/libffi/libffi-3.4.6-r2.ebuild new file mode 100644 index 000000000000..2235dc0d702f --- /dev/null +++ b/dev-libs/libffi/libffi-3.4.6-r2.ebuild @@ -0,0 +1,95 @@ +# Copyright 1999-2024 Gentoo Authors +# Distributed under the terms of the GNU General Public License v2 + +EAPI=8 + +inherit multilib-minimal preserve-libs + +MY_PV=${PV/_rc/-rc} +MY_P=${PN}-${MY_PV} + +DESCRIPTION="Portable, high level programming interface to various calling conventions" +HOMEPAGE="https://sourceware.org/libffi/" + +if [[ ${PV} == 9999 ]] ; then + EGIT_REPO_URI="https://github.com/libffi/libffi" + inherit git-r3 +else + SRC_URI="https://github.com/libffi/libffi/releases/download/v${MY_PV}/${MY_P}.tar.gz" + + KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~loong ~m68k ~mips ~ppc ~ppc64 ~riscv ~s390 ~sparc ~x86 ~amd64-linux ~x86-linux ~arm64-macos ~ppc-macos ~x64-macos ~x64-solaris" +fi + +S="${WORKDIR}"/${MY_P} + +LICENSE="MIT" +# This is a core package which is depended on by e.g. Python. +# Please use preserve-libs.eclass in pkg_{pre,post}inst to cover users +# with FEATURES="-preserved-libs" or another package manager if SONAME changes. +SLOT="0/8" # SONAME=libffi.so.8 +IUSE="debug exec-static-trampoline pax-kernel static-libs test" + +RESTRICT="!test? ( test )" +BDEPEND="test? ( dev-util/dejagnu )" + +PATCHES=( + "${FILESDIR}"/${P}-arm64-bti.patch + "${FILESDIR}"/${P}-arm64-bti-spelling.patch + "${FILESDIR}"/${P}-arm64-support-pac.patch + "${FILESDIR}"/${P}-arm64-fix-build.patch + "${FILESDIR}"/${P}-sparc-struct-targs.patch + "${FILESDIR}"/${P}-test-typo.patch + "${FILESDIR}"/${P}-x86-sse.patch + "${FILESDIR}"/${P}-arm64-cfi.patch + "${FILESDIR}"/${P}-asan.patch + "${FILESDIR}"/${P}-tests.patch + "${FILESDIR}"/${P}-regenerate-autotools.patch +) + +src_prepare() { + default + + if [[ ${CHOST} == arm64-*-darwin* ]] ; then + # ensure we use aarch64 asm, not x86 on arm64 + sed -i -e 's/aarch64\*-\*-\*/arm64*-*-*|&/' \ + configure configure.host || die + fi +} + +multilib_src_configure() { + # --includedir= path maintains a few properties: + # 1. have stable name across libffi versions: some packages like + # dev-lang/ghc or kde-frameworks/networkmanager-qt embed + # ${includedir} at build-time. Don't require those to be + # rebuilt unless SONAME changes. bug #695788 + # + # We use /usr/.../${PN} (instead of former /usr/.../${P}). + # + # 2. have ${ABI}-specific location as ffi.h is target-dependent. + # + # We use /usr/$(get_libdir)/... to have ABI identifier. + ECONF_SOURCE="${S}" econf \ + --includedir="${EPREFIX}"/usr/$(get_libdir)/${PN}/include \ + --disable-multi-os-directory \ + $(use_enable static-libs static) \ + $(use_enable exec-static-trampoline exec-static-tramp) \ + $(use_enable pax-kernel pax_emutramp) \ + $(use_enable debug) +} + +multilib_src_test() { + emake -Onone check +} + +multilib_src_install_all() { + einstalldocs + find "${ED}" -name "*.la" -delete || die +} + +pkg_preinst() { + preserve_old_lib /usr/$(get_libdir)/libffi.so.7 +} + +pkg_postinst() { + preserve_old_lib_notify /usr/$(get_libdir)/libffi.so.7 +} diff --git a/dev-libs/libffi/libffi-9999.ebuild b/dev-libs/libffi/libffi-9999.ebuild new file mode 100644 index 000000000000..51d1f5c466e6 --- /dev/null +++ b/dev-libs/libffi/libffi-9999.ebuild @@ -0,0 +1,81 @@ +# Copyright 1999-2024 Gentoo Authors +# Distributed under the terms of the GNU General Public License v2 + +EAPI=8 + +inherit multilib-minimal preserve-libs + +MY_PV=${PV/_rc/-rc} +MY_P=${PN}-${MY_PV} + +DESCRIPTION="Portable, high level programming interface to various calling conventions" +HOMEPAGE="https://sourceware.org/libffi/" + +if [[ ${PV} == 9999 ]] ; then + EGIT_REPO_URI="https://github.com/libffi/libffi" + inherit git-r3 +else + SRC_URI="https://github.com/libffi/libffi/releases/download/v${MY_PV}/${MY_P}.tar.gz" + + KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~loong ~m68k ~mips ~ppc ~ppc64 ~riscv ~s390 ~sparc ~x86 ~amd64-linux ~x86-linux ~arm64-macos ~ppc-macos ~x64-macos ~x64-solaris" +fi + +S="${WORKDIR}"/${MY_P} + +LICENSE="MIT" +# This is a core package which is depended on by e.g. Python. +# Please use preserve-libs.eclass in pkg_{pre,post}inst to cover users +# with FEATURES="-preserved-libs" or another package manager if SONAME changes. +SLOT="0/8" # SONAME=libffi.so.8 +IUSE="debug exec-static-trampoline pax-kernel static-libs test" + +RESTRICT="!test? ( test )" +BDEPEND="test? ( dev-util/dejagnu )" + +src_prepare() { + default + + if [[ ${CHOST} == arm64-*-darwin* ]] ; then + # ensure we use aarch64 asm, not x86 on arm64 + sed -i -e 's/aarch64\*-\*-\*/arm64*-*-*|&/' \ + configure configure.host || die + fi +} + +multilib_src_configure() { + # --includedir= path maintains a few properties: + # 1. have stable name across libffi versions: some packages like + # dev-lang/ghc or kde-frameworks/networkmanager-qt embed + # ${includedir} at build-time. Don't require those to be + # rebuilt unless SONAME changes. bug #695788 + # + # We use /usr/.../${PN} (instead of former /usr/.../${P}). + # + # 2. have ${ABI}-specific location as ffi.h is target-dependent. + # + # We use /usr/$(get_libdir)/... to have ABI identifier. + ECONF_SOURCE="${S}" econf \ + --includedir="${EPREFIX}"/usr/$(get_libdir)/${PN}/include \ + --disable-multi-os-directory \ + $(use_enable static-libs static) \ + $(use_enable exec-static-trampoline exec-static-tramp) \ + $(use_enable pax-kernel pax_emutramp) \ + $(use_enable debug) +} + +multilib_src_test() { + emake -Onone check +} + +multilib_src_install_all() { + einstalldocs + find "${ED}" -name "*.la" -delete || die +} + +pkg_preinst() { + preserve_old_lib /usr/$(get_libdir)/libffi.so.7 +} + +pkg_postinst() { + preserve_old_lib_notify /usr/$(get_libdir)/libffi.so.7 +} |