From c8ba658eda63dda8f927a1bd464734e833985bf5 Mon Sep 17 00:00:00 2001 From: Michael Cobb michael.cobb@iceotope.com Date: Tue, 20 Aug 2024 15:25:03 +0100 Subject: [PATCH 2/4] libffi: C64 initial commit
libffi version 3.4.2 from CHERIBSD repo: https://github.com/CTSRD-CHERI/libffi/commit/c666fdd8613b4d56130431c3e8f0bb0...
Included patch to add compile time option `--enable-cheri-ffi-closures` to enable ffi closures; this functionality was disabled in the source repo as it was not fully implemented, but needs to be enabled for Glib/GDBus signals to work. Use of FFI closures outside of GDBus signals has not been tested so use at your own risk.
Signed-off-by: Michael Cobb michael.cobb@iceotope.com --- .../libffi/libffi-morello_3.4.2.bb | 41 +++++++ ...-ffi-closures-flag-to-enable-FFI-clo.patch | 65 +++++++++++ ...m-sysv-reverted-clang-VFP-mitigation.patch | 102 ++++++++++++++++++ recipes-support/libffi/libffi/not-win32.patch | 35 ++++++ 4 files changed, 243 insertions(+) create mode 100644 recipes-support/libffi/libffi-morello_3.4.2.bb create mode 100644 recipes-support/libffi/libffi/0001-Add-enable-cheri-ffi-closures-flag-to-enable-FFI-clo.patch create mode 100644 recipes-support/libffi/libffi/0001-arm-sysv-reverted-clang-VFP-mitigation.patch create mode 100644 recipes-support/libffi/libffi/not-win32.patch
diff --git a/recipes-support/libffi/libffi-morello_3.4.2.bb b/recipes-support/libffi/libffi-morello_3.4.2.bb new file mode 100644 index 0000000..7f6ec96 --- /dev/null +++ b/recipes-support/libffi/libffi-morello_3.4.2.bb @@ -0,0 +1,41 @@ +inherit autotools texinfo purecap-sysroot + +MORELLO_SRC = "poky/meta/recipes-support/libffi/*" + +SUMMARY = "A portable foreign function interface library" +HOMEPAGE = "http://sourceware.org/libffi/" +DESCRIPTION = "The `libffi' library provides a portable, high level programming interface to various calling \ +conventions. This allows a programmer to call any function specified by a call interface description at run \ +time. FFI stands for Foreign Function Interface. A foreign function interface is the popular name for the \ +interface that allows code written in one language to call code written in another language. The `libffi' \ +library really only provides the lowest, machine dependent layer of a fully featured foreign function interface. \ +A layer must exist above `libffi' that handles type conversions for values passed between the two languages." + +LICENSE = "MIT" +LIC_FILES_CHKSUM = "file://LICENSE;md5=679b5c9bdc79a2b93ee574e193e7a7bc" + +SRC_URI = "git://github.com/CTSRD-CHERI/libffi.git;protocol=https;branch=master;rev=c666fdd8613b4d56130431c3e8f0bb05f30f07e8 \ + file://0001-Add-enable-cheri-ffi-closures-flag-to-enable-FFI-clo.patch \ + file://not-win32.patch \ + file://0001-arm-sysv-reverted-clang-VFP-mitigation.patch \ + " +SRC_URI[sha256sum] = "d66c56ad259a82cf2a9dfc408b32bf5da52371500b84745f7fb8b645712df676" + +FILESEXTRAPATHS:prepend = "${THISDIR}/libffi:" + +UPSTREAM_CHECK_URI = "https://github.com/libffi/libffi/releases/" +UPSTREAM_CHECK_REGEX = "libffi-(?P<pver>\d+(.\d+)+).tar" + +TOOLCHAIN = "${MORELLO_TOOLCHAIN}" + +S = "${WORKDIR}/git" + +EXTRA_OECONF += "--disable-builddir --disable-exec-static-tramp" +EXTRA_OECONF += " --enable-cheri-ffi-closures " +EXTRA_OEMAKE += "LIBTOOLFLAGS='--tag=CC'" + +FILES:${PN}-dev += "${libdir}/libffi-${PV}" + +# Doesn't compile in MIPS16e mode due to use of hand-written +# assembly +MIPS_INSTRUCTION_SET = "mips" diff --git a/recipes-support/libffi/libffi/0001-Add-enable-cheri-ffi-closures-flag-to-enable-FFI-clo.patch b/recipes-support/libffi/libffi/0001-Add-enable-cheri-ffi-closures-flag-to-enable-FFI-clo.patch new file mode 100644 index 0000000..b42feac --- /dev/null +++ b/recipes-support/libffi/libffi/0001-Add-enable-cheri-ffi-closures-flag-to-enable-FFI-clo.patch @@ -0,0 +1,65 @@ +From 208cb325d15f016d2fb58e11b1d97e1e4d85739b Mon Sep 17 00:00:00 2001 +From: Michael Cobb michael.cobb@iceotope.com +Date: Wed, 12 Jun 2024 16:37:18 +0100 +Subject: [PATCH] Add --enable-cheri-ffi-closures flag to enable FFI closures + on CHERI + +--- + configure.ac | 9 +++++++++ + include/ffi.h.in | 4 ++++ + src/aarch64/ffitarget.h | 3 ++- + 3 files changed, 15 insertions(+), 1 deletion(-) + +diff --git a/configure.ac b/configure.ac +index 70f6d2c..fbc0125 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -234,6 +234,15 @@ esac + AM_CONDITIONAL(FFI_EXEC_TRAMPOLINE_TABLE, test x$FFI_EXEC_TRAMPOLINE_TABLE = x1) + AC_SUBST(FFI_EXEC_TRAMPOLINE_TABLE) + ++CHERI_FFI_CLOSURES = 0 ++AC_ARG_ENABLE(cheri-ffi-closures, ++[ --enable-cheri-ffi-closures enable FFI closures on CHERI targets], ++ if test "$enable_cheri_ffi_closures" = "yes"; then ++ CHERI_FFI_CLOSURES=1 ++ AC_DEFINE(CHERI_FFI_CLOSURES, 1, [Define if you wish to enable FFI closures on CHERI targets]) ++ AC_SUBST(CHERI_FFI_CLOSURES) ++ fi) ++ + if test x$TARGET = xX86_64; then + AC_CACHE_CHECK([toolchain supports unwind section type], + libffi_cv_as_x86_64_unwind_section_type, [ +diff --git a/include/ffi.h.in b/include/ffi.h.in +index 9fd7a59..42a0cff 100644 +--- a/include/ffi.h.in ++++ b/include/ffi.h.in +@@ -56,6 +56,10 @@ extern "C" { + + /* ---- System configuration information --------------------------------- */ + ++#if defined(__CHERI_PURE_CAPABILITY__) && !defined(CHERI_FFI_CLOSURES) ++#define CHERI_FFI_CLOSURES @CHERI_FFI_CLOSURES@ ++#endif ++ + #include <ffitarget.h> + + #ifndef LIBFFI_ASM +diff --git a/src/aarch64/ffitarget.h b/src/aarch64/ffitarget.h +index 91585c3..17e5b0b 100644 +--- a/src/aarch64/ffitarget.h ++++ b/src/aarch64/ffitarget.h +@@ -61,11 +61,12 @@ typedef enum ffi_abi + + /* ---- Definitions for closures ----------------------------------------- */ + +-#if defined(__CHERI_PURE_CAPABILITY__) ++#if defined(__CHERI_PURE_CAPABILITY__) && !defined(CHERI_FFI_CLOSURES) + /* Not implemented yet for purecap. */ + #define FFI_CLOSURES 0 + #else + #define FFI_CLOSURES 1 ++#warning "FFI_CLOSURES is enabled but this feature may not be supported for purecap" + #endif + #define FFI_NATIVE_RAW_API 0 + diff --git a/recipes-support/libffi/libffi/0001-arm-sysv-reverted-clang-VFP-mitigation.patch b/recipes-support/libffi/libffi/0001-arm-sysv-reverted-clang-VFP-mitigation.patch new file mode 100644 index 0000000..ffeee10 --- /dev/null +++ b/recipes-support/libffi/libffi/0001-arm-sysv-reverted-clang-VFP-mitigation.patch @@ -0,0 +1,102 @@ +From 35d6563ce07e700b54c185f2bc997f946ee18014 Mon Sep 17 00:00:00 2001 +From: Brett Warren brett.warren@arm.com +Date: Fri, 27 Nov 2020 15:28:42 +0000 +Subject: [PATCH] arm/sysv: reverted clang VFP mitigation + +Since commit e3d2812ce43940aacae5bab2d0e965278cb1e7ea, +seperate instructions were used when compiling under clang, +as clang didn't allow the directives at the time. This mitigation +now causes compilation to fail under clang 10, as described by +https://github.com/libffi/libffi/issues/607. Now that +clang supports the LDC and SDC instructions, this mitigation +has been reverted. + +Upstream-Status: Submitted [https://github.com/libffi/libffi/pull/747] +Signed-off-by: Brett Warren brett.warren@arm.com + +--- + src/arm/sysv.S | 33 --------------------------------- + 1 file changed, 33 deletions(-) + +diff --git a/src/arm/sysv.S b/src/arm/sysv.S +index fb36213..e4272a1 100644 +--- a/src/arm/sysv.S ++++ b/src/arm/sysv.S +@@ -142,13 +142,8 @@ ARM_FUNC_START(ffi_call_VFP) + + cmp r3, #3 @ load only d0 if possible + ite le +-#ifdef __clang__ +- vldrle d0, [r0] +- vldmgt r0, {d0-d7} +-#else + ldcle p11, cr0, [r0] @ vldrle d0, [r0] + ldcgt p11, cr0, [r0], {16} @ vldmgt r0, {d0-d7} +-#endif + add r0, r0, #64 @ discard the vfp register args + /* FALLTHRU */ + ARM_FUNC_END(ffi_call_VFP) +@@ -193,25 +188,13 @@ ARM_FUNC_START(ffi_call_SYSV) + #endif + 0: + E(ARM_TYPE_VFP_S) +-#ifdef __clang__ +- vstr s0, [r2] +-#else + stc p10, cr0, [r2] @ vstr s0, [r2] +-#endif + pop {fp,pc} + E(ARM_TYPE_VFP_D) +-#ifdef __clang__ +- vstr d0, [r2] +-#else + stc p11, cr0, [r2] @ vstr d0, [r2] +-#endif + pop {fp,pc} + E(ARM_TYPE_VFP_N) +-#ifdef __clang__ +- vstm r2, {d0-d3} +-#else + stc p11, cr0, [r2], {8} @ vstm r2, {d0-d3} +-#endif + pop {fp,pc} + E(ARM_TYPE_INT64) + str r1, [r2, #4] +@@ -320,11 +303,7 @@ ARM_FUNC_START(ffi_closure_VFP) + add ip, sp, #16 + sub sp, sp, #64+32 @ allocate frame + cfi_adjust_cfa_offset(64+32) +-#ifdef __clang__ +- vstm sp, {d0-d7} +-#else + stc p11, cr0, [sp], {16} @ vstm sp, {d0-d7} +-#endif + stmdb sp!, {ip,lr} + + /* See above. */ +@@ -358,25 +337,13 @@ ARM_FUNC_START_LOCAL(ffi_closure_ret) + cfi_rel_offset(lr, 4) + 0: + E(ARM_TYPE_VFP_S) +-#ifdef __clang__ +- vldr s0, [r2] +-#else + ldc p10, cr0, [r2] @ vldr s0, [r2] +-#endif + b call_epilogue + E(ARM_TYPE_VFP_D) +-#ifdef __clang__ +- vldr d0, [r2] +-#else + ldc p11, cr0, [r2] @ vldr d0, [r2] +-#endif + b call_epilogue + E(ARM_TYPE_VFP_N) +-#ifdef __clang__ +- vldm r2, {d0-d3} +-#else + ldc p11, cr0, [r2], {8} @ vldm r2, {d0-d3} +-#endif + b call_epilogue + E(ARM_TYPE_INT64) + ldr r1, [r2, #4] diff --git a/recipes-support/libffi/libffi/not-win32.patch b/recipes-support/libffi/libffi/not-win32.patch new file mode 100644 index 0000000..0ab9c2e --- /dev/null +++ b/recipes-support/libffi/libffi/not-win32.patch @@ -0,0 +1,35 @@ +From d240a878edf4b42fa4aa3aa01f464f2173f5db1e Mon Sep 17 00:00:00 2001 +From: Ross Burton ross.burton@intel.com +Date: Thu, 4 Feb 2016 16:22:50 +0000 +Subject: [PATCH] libffi: ensure sysroot paths are not in libffi.pc + +libffi's configure assumes that cross-compiled builds are complicated and +introduces convoluted path manipulation involving gcc search paths to the +install paths, resulting in paths like -L/usr/lib/../lib/ appearing in +libffi.pc. When pkg-config is then used to obtain the linker flags for libffi +it can't tell that this path is on the default search path and returns +$SYSROOT/usr/lib/../lib which then gets written all over the target sysroot. +This then means the sstate can't be shared and triggers QA errors. + +As this block is generally pointless, disable it. + +Upstream-Status: Inappropriate +Signed-off-by: Ross Burton ross.burton@intel.com + +--- + configure.ac | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/configure.ac b/configure.ac +index fbc0125..9dd2078 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -401,7 +401,7 @@ AC_ARG_ENABLE(multi-os-directory, + + # These variables are only ever used when we cross-build to X86_WIN32. + # And we only support this with GCC, so... +-if test "x$GCC" = "xyes"; then ++if false; then + if test -n "$with_cross_host" && + test x"$with_cross_host" != x"no"; then + toolexecdir='${exec_prefix}'/'$(target_alias)'