aboutsummaryrefslogtreecommitdiff
path: root/libffi
diff options
context:
space:
mode:
authorRainer Orth <ro@CeBiTec.Uni-Bielefeld.DE>2024-07-01 11:20:15 +0200
committerRainer Orth <ro@CeBiTec.Uni-Bielefeld.DE>2024-07-01 11:20:15 +0200
commit61aa380bad45fb070379f259f7abc5e5f50c9009 (patch)
tree0bb3de0021929dafbc31605d1c5a0d7d3dc3db7d /libffi
parent286cda3461d6f5ce7d911d3f26bd4975ea7ea11d (diff)
downloadgcc-61aa380bad45fb070379f259f7abc5e5f50c9009.zip
gcc-61aa380bad45fb070379f259f7abc5e5f50c9009.tar.gz
gcc-61aa380bad45fb070379f259f7abc5e5f50c9009.tar.bz2
libffi: Fix 32-bit SPARC structure passing [PR115681]
The libffi.closures/single_entry_structs2.c test FAILs on 32-bit SPARC: FAIL: libffi.closures/single_entry_structs2.c -W -Wall -Wno-psabi -O0 execution test The issue has been reported, analyzed and fixed upstream: Several tests FAIL on 32-bit Solaris/SPARC https://github.com/libffi/libffi/issues/841 Therefore this patch imports the fix into the GCC tree. Tested on sparc-sun-solaris2.11. 2024-07-01 Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE> libffi: PR libffi/115681 * src/sparc/ffi.c (ffi_call_int): Copy structure arguments to maintain call-by-value semantics.
Diffstat (limited to 'libffi')
-rw-r--r--libffi/src/sparc/ffi.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/libffi/src/sparc/ffi.c b/libffi/src/sparc/ffi.c
index 9e406d0..cf819ee 100644
--- a/libffi/src/sparc/ffi.c
+++ b/libffi/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);
}