Compare commits

..

No commits in common. "a51114d7b7185156754a0f7aae07dd7e506be21a" and "654151715e7230c08c45bc5b4846714c99b88ecf" have entirely different histories.

11 changed files with 1283 additions and 359 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,197 @@
From de95947ae5db07e4589bb16bab30b6c8ba2b3106 Mon Sep 17 00:00:00 2001
From: Roland Schatz <roland.schatz@oracle.com>
Date: Tue, 24 May 2022 03:04:43 +0200
Subject: [PATCH] Fix check for invalid varargs arguments. (#707)
Conflict:NA
Reference:https://github.com/libffi/libffi/commit/de95947ae5db07e4589bb16bab30b6c8ba2b3106
---
src/prep_cif.c | 3 +-
testsuite/libffi.call/va_3.c | 154 +++++++++++++++++++++++++++++++++++
2 files changed, 156 insertions(+), 1 deletion(-)
create mode 100644 testsuite/libffi.call/va_3.c
diff --git a/src/prep_cif.c b/src/prep_cif.c
index c1832b1..2d0f252 100644
--- a/src/prep_cif.c
+++ b/src/prep_cif.c
@@ -1,6 +1,7 @@
/* -----------------------------------------------------------------------
prep_cif.c - Copyright (c) 2011, 2012, 2021 Anthony Green
Copyright (c) 1996, 1998, 2007 Red Hat, Inc.
+ Copyright (c) 2022 Oracle and/or its affiliates.
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
@@ -240,7 +241,7 @@ ffi_status ffi_prep_cif_var(ffi_cif *cif,
if (rc != FFI_OK)
return rc;
- for (i = 1; i < ntotalargs; i++)
+ for (i = nfixedargs; i < ntotalargs; i++)
{
ffi_type *arg_type = atypes[i];
if (arg_type == &ffi_type_float
diff --git a/testsuite/libffi.call/va_3.c b/testsuite/libffi.call/va_3.c
new file mode 100644
index 0000000..b3e73b5
--- /dev/null
+++ b/testsuite/libffi.call/va_3.c
@@ -0,0 +1,154 @@
+/* Area: ffi_call
+ Purpose: Test function with multiple fixed args and variable argument list.
+ Limitations: none.
+ PR: none.
+ Originator: ARM Ltd., Oracle */
+
+/* { dg-do run } */
+/* { dg-output "" { xfail avr32*-*-* m68k-*-* } } */
+
+#include "ffitest.h"
+#include <stdarg.h>
+
+/*
+ * This is a modified version of va_2.c that has fixed arguments with "small" types that
+ * are not allowed as variable arguments, but they should be still allowed as fixed args.
+ */
+
+static int
+test_fn (char a1, float a2, int n, ...)
+{
+ va_list ap;
+ unsigned char uc;
+ signed char sc;
+ unsigned short us;
+ signed short ss;
+ unsigned int ui;
+ signed int si;
+ unsigned long ul;
+ signed long sl;
+ float f;
+ double d;
+
+ va_start (ap, n);
+
+ uc = va_arg (ap, unsigned);
+ sc = va_arg (ap, signed);
+
+ us = va_arg (ap, unsigned);
+ ss = va_arg (ap, signed);
+
+ ui = va_arg (ap, unsigned int);
+ si = va_arg (ap, signed int);
+
+ ul = va_arg (ap, unsigned long);
+ sl = va_arg (ap, signed long);
+
+ f = va_arg (ap, double); /* C standard promotes float->double
+ when anonymous */
+ d = va_arg (ap, double);
+
+ printf ("%d %f uc=%u sc=%d %u %d %u %d %lu %ld %f %f\n",
+ a1, a2,
+ uc, sc,
+ us, ss,
+ ui, si,
+ ul, sl,
+ f, d);
+
+ va_end (ap);
+
+ CHECK(a1 == 1);
+ CHECK((int)a2 == 2);
+ CHECK(uc == 9);
+ CHECK(sc == 10);
+ CHECK(us == 11);
+ CHECK(ss == 12);
+ CHECK(ui == 13);
+ CHECK(si == 14);
+ CHECK(ul == 15);
+ CHECK(sl == 16);
+ CHECK((int)f == 2);
+ CHECK((int)d == 3);
+
+ return n + 1;
+}
+
+int
+main (void)
+{
+ ffi_cif cif;
+ void* args[14];
+ ffi_type* arg_types[14];
+
+ char a1;
+ float a2;
+ int n;
+ ffi_arg res;
+
+ unsigned int uc;
+ signed int sc;
+ unsigned int us;
+ signed int ss;
+ unsigned int ui;
+ signed int si;
+ unsigned long ul;
+ signed long sl;
+ double d1;
+ double f1;
+
+ arg_types[0] = &ffi_type_schar;
+ arg_types[1] = &ffi_type_float;
+ arg_types[2] = &ffi_type_sint;
+ arg_types[3] = &ffi_type_uint;
+ arg_types[4] = &ffi_type_sint;
+ arg_types[5] = &ffi_type_uint;
+ arg_types[6] = &ffi_type_sint;
+ arg_types[7] = &ffi_type_uint;
+ arg_types[8] = &ffi_type_sint;
+ arg_types[9] = &ffi_type_ulong;
+ arg_types[10] = &ffi_type_slong;
+ arg_types[11] = &ffi_type_double;
+ arg_types[12] = &ffi_type_double;
+ arg_types[13] = NULL;
+
+ CHECK(ffi_prep_cif_var(&cif, FFI_DEFAULT_ABI, 3, 13, &ffi_type_sint, arg_types) == FFI_OK);
+
+ a1 = 1;
+ a2 = 2.0f;
+ n = 41;
+
+ uc = 9;
+ sc = 10;
+ us = 11;
+ ss = 12;
+ ui = 13;
+ si = 14;
+ ul = 15;
+ sl = 16;
+ f1 = 2.12;
+ d1 = 3.13;
+
+ args[0] = &a1;
+ args[1] = &a2;
+ args[2] = &n;
+ args[3] = &uc;
+ args[4] = &sc;
+ args[5] = &us;
+ args[6] = &ss;
+ args[7] = &ui;
+ args[8] = &si;
+ args[9] = &ul;
+ args[10] = &sl;
+ args[11] = &f1;
+ args[12] = &d1;
+ args[13] = NULL;
+
+ ffi_call(&cif, FFI_FN(test_fn), &res, args);
+ /* { dg-output "1 2.000000 uc=9 sc=10 11 12 13 14 15 16 2.120000 3.130000" } */
+ printf("res: %d\n", (int) res);
+ /* { dg-output "\nres: 42" } */
+ CHECK(res == 42);
+
+ return 0;
+}
--
2.23.0

View File

@ -1,44 +0,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
Conflict:NA
Reference:https://github.com/libffi/libffi/commit/92d384df196a099fde384f9178864dbfe8c6b0fc
---
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 079634e..13fef64 100644
--- a/testsuite/libffi.call/struct_int_float.c
+++ b/testsuite/libffi.call/struct_int_float.c
@@ -16,11 +16,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;
}
@@ -84,7 +84,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);
}
--
2.27.0

View File

@ -1,74 +0,0 @@
From ebbc5e14cdbfcc24bf3c9bb7b41ee10cd979c535 Mon Sep 17 00:00:00 2001
From: serge-sans-paille <serge.guelton@telecom-bretagne.eu>
Date: Thu, 2 Feb 2023 11:40:17 +0000
Subject: [PATCH] Fix signed vs unsigned comparison (#765)
As reported by -Wsign-compare. In the case of getting the result of
comparing the result of sysconf (_SC_PAGESIZE) to other value, this also
correctly handles edge cases where the above fails and returns -1.
Co-authored-by: serge-sans-paille <sguelton@mozilla.com>
---
src/closures.c | 2 +-
src/prep_cif.c | 2 +-
src/tramp.c | 7 +++++--
3 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/src/closures.c b/src/closures.c
index 9aafbec4b..c42527795 100644
--- a/src/closures.c
+++ b/src/closures.c
@@ -795,7 +795,7 @@ open_temp_exec_file (void)
static int
allocate_space (int fd, off_t offset, off_t len)
{
- static size_t page_size;
+ static long page_size;
/* Obtain system page size. */
if (!page_size)
diff --git a/src/prep_cif.c b/src/prep_cif.c
index 2d0f2521f..0e2d58e5e 100644
--- a/src/prep_cif.c
+++ b/src/prep_cif.c
@@ -234,7 +234,7 @@ ffi_status ffi_prep_cif_var(ffi_cif *cif,
{
ffi_status rc;
size_t int_size = ffi_type_sint.size;
- int i;
+ unsigned int i;
rc = ffi_prep_cif_core(cif, abi, 1, nfixedargs, ntotalargs, rtype, atypes);
diff --git a/src/tramp.c b/src/tramp.c
index b9d273a1a..7e005b054 100644
--- a/src/tramp.c
+++ b/src/tramp.c
@@ -266,7 +266,7 @@ ffi_tramp_get_temp_file (void)
* trampoline table to make sure that the temporary file can be mapped.
*/
count = write(tramp_globals.fd, tramp_globals.text, tramp_globals.map_size);
- if (count == tramp_globals.map_size && tramp_table_alloc ())
+ if (count >=0 && (size_t)count == tramp_globals.map_size && tramp_table_alloc ())
return 1;
close (tramp_globals.fd);
@@ -374,6 +374,8 @@ tramp_table_unmap (struct tramp_table *table)
static int
ffi_tramp_init (void)
{
+ long page_size;
+
if (tramp_globals.status == TRAMP_GLOBALS_PASSED)
return 1;
@@ -396,7 +398,8 @@ ffi_tramp_init (void)
&tramp_globals.map_size);
tramp_globals.ntramp = tramp_globals.map_size / tramp_globals.size;
- if (sysconf (_SC_PAGESIZE) > tramp_globals.map_size)
+ page_size = sysconf (_SC_PAGESIZE);
+ if (page_size >= 0 && (size_t)page_size > tramp_globals.map_size)
return 0;
if (ffi_tramp_init_os ())

View File

@ -1,51 +0,0 @@
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
Conflict:NA
Reference:https://github.com/libffi/libffi/commit/efb98a72d8b9bdb71b4f972efced073bee3b30fc
---
testsuite/libffi.call/struct_int_float.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/testsuite/libffi.call/struct_int_float.c b/testsuite/libffi.call/struct_int_float.c
index 7014f13..079634e 100644
--- a/testsuite/libffi.call/struct_int_float.c
+++ b/testsuite/libffi.call/struct_int_float.c
@@ -61,17 +61,17 @@ int main (void)
CHECK(ffi_prep_cif(&cif, 2, 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);
@@ -84,7 +84,7 @@ int main (void)
printf ("%g\n", rfloat);
- CHECK(rfloat == 1.11f);
+ CHECK(fabs(rfloat - 11.11) < FLT_EPSILON);
exit(0);
}
--
2.27.0

View File

@ -1,129 +0,0 @@
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)
Conflict:(1)add two header files.
(2)modify the incorrect parameters passed in.
Reference:https://github.com/libffi/libffi/commit/d21881f55ed4a44d464c9091871e69b0bb47611a
* 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 | 90 ++++++++++++++++++++++++
2 files changed, 91 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 6a8e37f..39f0bfd 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 0000000..7014f13
--- /dev/null
+++ b/testsuite/libffi.call/struct_int_float.c
@@ -0,0 +1,90 @@
+/* Area: ffi_call
+ Purpose: Demonstrate structures with integers corrupting earlier floats
+ Limitations: none.
+ PR: #848
+ Originator: kellda */
+
+/* { dg-do run } */
+#include "ffitest.h"
+#include <math.h>
+#include <float.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, 2, 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);
+}
--
2.27.0

View File

@ -0,0 +1,54 @@
From 3ac265d5c0e038e324bae29131dbc4bacb4935ea Mon Sep 17 00:00:00 2001
From: hjl-tools <hjl.tools@gmail.com>
Date: Sun, 15 May 2022 18:43:56 -0700
Subject: [PATCH] x86-64: Always double jump table slot size for CET (#710)
(#711)
When CET is enabled, double jump table slot size to add 4 bytes of ENDBR64
for CET. Since CET enabled clang doesn't have the LLVM assembler bug:
https://bugs.llvm.org/show_bug.cgi?id=21501
fixed by
commit 04d39260d64e08b8bfb3844109ad43d4055b2e8d
Author: Rafael Espindola <rafael.espindola@gmail.com>
Date: Wed Nov 4 23:50:29 2015 +0000
Simplify .org processing and make it a bit more powerful.
we can use .org to allocate jump table slot size to 16 bytes.
Conflict:NA
Reference:https://github.com/libffi/libffi/commit/3ac265d5c0e038e324bae29131dbc4bacb4935ea
---
src/x86/unix64.S | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/src/x86/unix64.S b/src/x86/unix64.S
index 8cf3a23..d9c5bd4 100644
--- a/src/x86/unix64.S
+++ b/src/x86/unix64.S
@@ -39,14 +39,13 @@
actual table. The entry points into the table are all 8 bytes.
The use of ORG asserts that we're at the correct location. */
/* ??? The clang assembler doesn't handle .org with symbolic expressions. */
-#if defined(__clang__) || defined(__APPLE__) || (defined (__sun__) && defined(__svr4__))
+#ifdef __CET__
+/* Double slot size to 16 byte to add 4 bytes of ENDBR64. */
+# define E(BASE, X) .balign 8; .org BASE + X * 16
+#elif defined(__clang__) || defined(__APPLE__) || (defined (__sun__) && defined(__svr4__))
# define E(BASE, X) .balign 8
#else
-# ifdef __CET__
-# define E(BASE, X) .balign 8; .org BASE + X * 16
-# else
-# define E(BASE, X) .balign 8; .org BASE + X * 8
-# endif
+# define E(BASE, X) .balign 8; .org BASE + X * 8
#endif
/* ffi_call_unix64 (void *args, unsigned long bytes, unsigned flags,
--
2.23.0

View File

@ -1,28 +0,0 @@
From f34e5ab850b1d1d3cceedd6e409a07a051f5ee55 Mon Sep 17 00:00:00 2001
From: Xin Shi <shixin21@huawei.com>
Date: Thu, 25 May 2023 14:38:06 +0800
Subject: [PATCH] fix AARCH64EB support
Signed-off-by: Xin Shi <shixin21@huawei.com>
---
src/aarch64/ffi.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/src/aarch64/ffi.c b/src/aarch64/ffi.c
index 6544ac0..0111aa6 100644
--- a/src/aarch64/ffi.c
+++ b/src/aarch64/ffi.c
@@ -758,6 +758,10 @@ ffi_call_int (ffi_cif *cif, void (*fn)(void), void *orig_rvalue,
}
state.nsrn = N_V_ARG_REG;
dest = allocate_to_stack (&state, stack, ty->alignment, s);
+#ifdef __AARCH64EB__
+ if (t == FFI_TYPE_FLOAT)
+ dest = dest + 4;
+#endif
}
}
else if (s > 16)
--
2.27.0

BIN
libffi-3.4.2.tar.gz Normal file

Binary file not shown.

Binary file not shown.

View File

@ -1,6 +1,6 @@
Name: libffi
Version: 3.4.4
Release: 4
Version: 3.4.2
Release: 3
Summary: A Portable Foreign Function Interface Library
License: MIT
URL: http://sourceware.org/libffi
@ -8,14 +8,10 @@ Source0: https://github.com/libffi/libffi/releases/download/v%{version}/%{name}-
Source1: ffi-multilib.h
Source2: ffitarget-multilib.h
Patch0: backport-Fix-signed-vs-unsigned-comparison.patch
Patch1: fix-AARCH64EB-support.patch
Patch2: backport-fix-x86-ffi64-calls-with-6-gp-and-some-sse-registers.patch
Patch3: backport-Robustify-floating-point-comparison-in-test.patch
Patch4: backport-Fix-floating-point-compare.patch
Patch6000: backport-x86-64-Always-double-jump-table-slot-size-for-CET-71.patch
Patch6001: backport-Fix-check-for-invalid-varargs-arguments-707.patch
Patch6002: add-loongarch64-support.patch
BuildRequires: gcc gcc-c++ dejagnu
BuildRequires: make
%description
Compilers for high level languages generate code that follows certain conventions. These
@ -56,7 +52,12 @@ BuildArch: noarch
The help package contains man files.
%prep
%autosetup -p1 -n %{name}-%{version}
%setup -q
%patch6000 -p1
%patch6001 -p1
%ifarch loongarch64
%patch6002 -p1
%endif
%build
%configure \
@ -100,29 +101,6 @@ fi
%{_infodir}/libffi.info.gz
%changelog
* Tue Jan 14 2025 shixuantong <shixuantong1@huawei.com> - 3.4.4-4
- Type:bugfix
- CVE:NA
- SUG:NA
- DESC:Fix x86/ffi64 calls with 6 gp and some sse registers
Robustify floating point comparison in test
Fix floating point compare
* Thu May 25 2023 shixin <shixin21@huawei.com> - 3.4.4-3
- Type:bugfix
- ID:NA
- SUG:NA
- DSEC:Fix AARCH64EB support
* Thu Mar 23 2023 fuanan <fuanan3@h-partners.com> -3.4.4-2
- backport patches from upstream
* Thu Jan 19 2023 gaoruoshu <gaoruoshu@huawei.com> -3.4.4-1
- update version to 3.4.4
* Fri Dec 16 2022 wangjiang <wangjiang37@h-partners.com> - 3.4.2-4
- add BuildRequires make
* Fri Nov 18 2022 doupengda<doupengda@loongson.cn> - 3.4.2-3
- add loongarch support