commit:     6521e1f5d4cceb00f082def621d7e28b7788b7f5
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Wed Oct 16 03:08:22 2024 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Wed Oct 16 03:08:22 2024 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=6521e1f5

dev-libs/libffi: backport several patches to 3.4.6

Backport first a fix for arm64 CFI which fixes build w/ the macOS
assembler (reported by olfway on IRC when looking at 
https://github.com/gentoo/prefix/pull/34).

While here, backport a few more fixes:
* runtime: sparc: struct args
* runtime: x86: sse
* tests: fix dg-* typo

Signed-off-by: Sam James <sam <AT> gentoo.org>

 dev-libs/libffi/files/libffi-3.4.6-arm64-cfi.patch |  44 ++++++++
 .../files/libffi-3.4.6-sparc-struct-targs.patch    |  46 ++++++++
 dev-libs/libffi/files/libffi-3.4.6-test-typo.patch |  19 ++++
 dev-libs/libffi/files/libffi-3.4.6-x86-sse.patch   | 124 +++++++++++++++++++++
 dev-libs/libffi/libffi-3.4.6-r1.ebuild             |  80 +++++++++++++
 5 files changed, 313 insertions(+)

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 <antun...@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-sparc-struct-targs.patch 
b/dev-libs/libffi/files/libffi-3.4.6-sparc-struct-targs.patch
new file mode 100644
index 000000000000..f5eebad9edd7
--- /dev/null
+++ b/dev-libs/libffi/files/libffi-3.4.6-sparc-struct-targs.patch
@@ -0,0 +1,46 @@
+https://github.com/libffi/libffi/commit/8e3ef965c2d0015ed129a06d0f11f30c2120a413
+
+From 8e3ef965c2d0015ed129a06d0f11f30c2120a413 Mon Sep 17 00:00:00 2001
+From: Anthony Green <gr...@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 <s...@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-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+kel...@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 (&reg_args->gpr[gprcount], a, size);
++                    memcpy (&reg_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-r1.ebuild 
b/dev-libs/libffi/libffi-3.4.6-r1.ebuild
new file mode 100644
index 000000000000..5ac383d4cbeb
--- /dev/null
+++ b/dev-libs/libffi/libffi-3.4.6-r1.ebuild
@@ -0,0 +1,80 @@
+# 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/";
+SRC_URI="https://github.com/libffi/libffi/releases/download/v${MY_PV}/${MY_P}.tar.gz";
+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
+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"
+IUSE="debug exec-static-trampoline pax-kernel static-libs test"
+
+RESTRICT="!test? ( test )"
+BDEPEND="test? ( dev-util/dejagnu )"
+
+PATCHES=(
+       "${FILESDIR}"/${P}-arm64-cfi.patch
+       "${FILESDIR}"/${P}-sparc-struct-targs.patch
+       "${FILESDIR}"/${P}-test-typo.patch
+       "${FILESDIR}"/${P}-x86-sse.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
+}

Reply via email to