Add FFI_GNUW64 ABI for GNU 80-bit long double support
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
diff --git a/README.md b/README.md
index 3444839..f3a4f99 100644
--- a/README.md
+++ b/README.md
@@ -190,9 +190,11 @@ History
See the git log for details at http://github.com/libffi/libffi.
3.3 TBD
+ Default to Microsoft's 64 bit long double ABI with Visual C++.
+ GNU compiler uses 80 bits (128 in memory) FFI_GNUW64 ABI.
New API in support of GO closures.
Add RISC-V support.
- Many bug fixes.
+ Many bug fixes.
3.2.1 Nov-12-14
Build fix for non-iOS AArch64 targets.
diff --git a/src/x86/ffitarget.h b/src/x86/ffitarget.h
index 25e3f4f..3a0efa5 100644
--- a/src/x86/ffitarget.h
+++ b/src/x86/ffitarget.h
@@ -1,5 +1,5 @@
/* -----------------------------------------------------------------*-C-*-
- ffitarget.h - Copyright (c) 2012, 2014 Anthony Green
+ ffitarget.h - Copyright (c) 2012, 2014, 2018 Anthony Green
Copyright (c) 1996-2003, 2010 Red Hat, Inc.
Copyright (C) 2008 Free Software Foundation, Inc.
@@ -80,9 +80,14 @@ typedef signed long ffi_sarg;
typedef enum ffi_abi {
#if defined(X86_WIN64)
FFI_FIRST_ABI = 0,
- FFI_WIN64,
+ FFI_WIN64, /* sizeof(long double) == 8 - microsoft compilers */
+ FFI_GNUW64, /* sizeof(long double) == 16 - GNU compilers */
FFI_LAST_ABI,
+#ifdef __GNUC__
+ FFI_DEFAULT_ABI = FFI_GNUW64
+#else
FFI_DEFAULT_ABI = FFI_WIN64
+#endif
#elif defined(X86_64) || (defined (__x86_64__) && defined (X86_DARWIN))
FFI_FIRST_ABI = 1,
diff --git a/src/x86/ffiw64.c b/src/x86/ffiw64.c
index fd47c58..f787525 100644
--- a/src/x86/ffiw64.c
+++ b/src/x86/ffiw64.c
@@ -1,5 +1,6 @@
/* -----------------------------------------------------------------------
- ffiw64.c - Copyright (c) 2014 Red Hat, Inc.
+ ffiw64.c - Copyright (c) 2018 Anthony Green
+ Copyright (c) 2014 Red Hat, Inc.
x86 win64 Foreign Function Interface
@@ -52,8 +53,14 @@ EFI64(ffi_prep_cif_machdep)(ffi_cif *cif)
{
int flags, n;
- if (cif->abi != FFI_WIN64)
- return FFI_BAD_ABI;
+ switch (cif->abi)
+ {
+ case FFI_WIN64:
+ case FFI_GNUW64:
+ break;
+ default:
+ return FFI_BAD_ABI;
+ }
flags = cif->rtype->type;
switch (flags)
@@ -61,7 +68,9 @@ EFI64(ffi_prep_cif_machdep)(ffi_cif *cif)
default:
break;
case FFI_TYPE_LONGDOUBLE:
- flags = FFI_TYPE_STRUCT;
+ /* GCC returns long double values by reference, like a struct */
+ if (cif->abi == FFI_GNUW64)
+ flags = FFI_TYPE_STRUCT;
break;
case FFI_TYPE_COMPLEX:
flags = FFI_TYPE_STRUCT;
@@ -106,7 +115,7 @@ ffi_call_int (ffi_cif *cif, void (*fn)(void), void *rvalue,
size_t rsize;
struct win64_call_frame *frame;
- FFI_ASSERT(cif->abi == FFI_WIN64);
+ FFI_ASSERT(cif->abi == FFI_GNUW64 || cif->abi == FFI_WIN64);
flags = cif->flags;
rsize = 0;
@@ -196,8 +205,14 @@ EFI64(ffi_prep_closure_loc)(ffi_closure* closure,
};
char *tramp = closure->tramp;
- if (cif->abi != FFI_WIN64)
- return FFI_BAD_ABI;
+ switch (cif->abi)
+ {
+ case FFI_WIN64:
+ case FFI_GNUW64:
+ break;
+ default:
+ return FFI_BAD_ABI;
+ }
memcpy (tramp, trampoline, sizeof(trampoline));
*(UINT64 *)(tramp + 16) = (uintptr_t)ffi_closure_win64;
@@ -213,8 +228,14 @@ ffi_status
EFI64(ffi_prep_go_closure)(ffi_go_closure* closure, ffi_cif* cif,
void (*fun)(ffi_cif*, void*, void**, void*))
{
- if (cif->abi != FFI_WIN64)
- return FFI_BAD_ABI;
+ switch (cif->abi)
+ {
+ case FFI_WIN64:
+ case FFI_GNUW64:
+ break;
+ default:
+ return FFI_BAD_ABI;
+ }
closure->tramp = ffi_go_closure_win64;
closure->cif = cif;