This is the mail archive of the
libffi-discuss@sourceware.org
mailing list for the libffi project.
Re: libffi merge
Dave Korn wrote:
> Andrew Haley wrote:
>> Dave Korn wrote:
>
>>> Refs: http://gcc.gnu.org/ml/gcc-patches/2009-05/msg01473.html
>>> http://gcc.gnu.org/ml/gcc-patches/2009-05/msg01476.html
>> OK, I backed out that patch. I'm awaiting some explanation of what on Earth
>> is going on. I'm guessing that Timothy Wall changed the version upstream but
>> not the version in gcc, and then you changed the version in gcc but not the
>> version upstream. So, we have a two sets of changes, and I can't tell which
>> is supposed to go where.
>
> The relevant bit from those links was this:
>
>> There is currently one difference between our win32.S and upstream libffi
>> win32.S, where upstream adds a new entrypoint, _ffi_closure_STDCALL.
>>
>> Would it help if I added that function and EH annotations for it to my patch?
>
> i.e. I already merged (the only difference between) win32.s from libffi->gcc
> for you, and thought that you'd just copy the gcc version back across
> wholesale when updating libffi. Sorry for having been AFK for so long, I have
> a lot of outside stuff going on this week/weekend.
OK, so the gcc version of win32.s should be copied to libffi, but the
other two files, src/x86/ffi.c and src/x86/ffitarget.h should be copied
from libffi to gcc.
Patch the first: libffi -> gcc.
Andrew.
2009-06-05 Andrew Haley <aph@redhat.com>
* src/x86/ffitarget.h, src/x86/ffi.c: Merge stdcall changes from
libffi.
--- /home/aph/gcc/trunk/libffi/src/x86/ffi.c 2009-06-04 18:07:09.000000000 +0100
+++ ./src/x86/ffi.c 2008-04-03 19:57:34.000000000 +0100
@@ -1,5 +1,5 @@
/* -----------------------------------------------------------------------
- ffi.c - Copyright (c) 1996, 1998, 1999, 2001, 2007 Red Hat, Inc.
+ ffi.c - Copyright (c) 1996, 1998, 1999, 2001, 2007, 2008 Red Hat, Inc.
Copyright (c) 2002 Ranjit Mathew
Copyright (c) 2002 Bo Thorsen
Copyright (c) 2002 Roger Sayle
@@ -236,6 +236,10 @@
__attribute__ ((regparm(1)));
void FFI_HIDDEN ffi_closure_raw_SYSV (ffi_raw_closure *)
__attribute__ ((regparm(1)));
+#ifdef X86_WIN32
+void FFI_HIDDEN ffi_closure_STDCALL (ffi_closure *)
+ __attribute__ ((regparm(1)));
+#endif
/* This function is jumped to by the trampoline */
@@ -245,7 +249,7 @@
void **respp;
void *args;
{
- // our various things...
+ /* our various things... */
ffi_cif *cif;
void **arg_area;
@@ -311,13 +315,26 @@
({ unsigned char *__tramp = (unsigned char*)(TRAMP); \
unsigned int __fun = (unsigned int)(FUN); \
unsigned int __ctx = (unsigned int)(CTX); \
- unsigned int __dis = __fun - (__ctx + FFI_TRAMPOLINE_SIZE); \
+ unsigned int __dis = __fun - (__ctx + 10); \
*(unsigned char*) &__tramp[0] = 0xb8; \
*(unsigned int*) &__tramp[1] = __ctx; /* movl __ctx, %eax */ \
*(unsigned char *) &__tramp[5] = 0xe9; \
*(unsigned int*) &__tramp[6] = __dis; /* jmp __fun */ \
})
+#define FFI_INIT_TRAMPOLINE_STDCALL(TRAMP,FUN,CTX,SIZE) \
+({ unsigned char *__tramp = (unsigned char*)(TRAMP); \
+ unsigned int __fun = (unsigned int)(FUN); \
+ unsigned int __ctx = (unsigned int)(CTX); \
+ unsigned int __dis = __fun - (__ctx + 10); \
+ unsigned short __size = (unsigned short)(SIZE); \
+ *(unsigned char*) &__tramp[0] = 0xb8; \
+ *(unsigned int*) &__tramp[1] = __ctx; /* movl __ctx, %eax */ \
+ *(unsigned char *) &__tramp[5] = 0xe8; \
+ *(unsigned int*) &__tramp[6] = __dis; /* call __fun */ \
+ *(unsigned char *) &__tramp[10] = 0xc2; \
+ *(unsigned short*) &__tramp[11] = __size; /* ret __size */ \
+ })
/* the cif must already be prep'ed */
@@ -328,11 +345,24 @@
void *user_data,
void *codeloc)
{
- FFI_ASSERT (cif->abi == FFI_SYSV);
-
- FFI_INIT_TRAMPOLINE (&closure->tramp[0], \
- &ffi_closure_SYSV, \
- codeloc);
+ if (cif->abi == FFI_SYSV)
+ {
+ FFI_INIT_TRAMPOLINE (&closure->tramp[0],
+ &ffi_closure_SYSV,
+ (void*)codeloc);
+ }
+#ifdef X86_WIN32
+ else if (cif->abi == FFI_STDCALL)
+ {
+ FFI_INIT_TRAMPOLINE_STDCALL (&closure->tramp[0],
+ &ffi_closure_STDCALL,
+ (void*)codeloc, cif->bytes);
+ }
+#endif
+ else
+ {
+ return FFI_BAD_ABI;
+ }
closure->cif = cif;
closure->user_data = user_data;
@@ -354,7 +384,9 @@
{
int i;
- FFI_ASSERT (cif->abi == FFI_SYSV);
+ if (cif->abi != FFI_SYSV) {
+ return FFI_BAD_ABI;
+ }
// we currently don't support certain kinds of arguments for raw
// closures. This should be implemented by a separate assembly language
--- /home/aph/gcc/trunk/libffi/src/x86/ffitarget.h 2009-06-04 18:07:09.000000000 +0100
+++ ./src/x86/ffitarget.h 2008-02-15 01:24:06.000000000 +0000
@@ -78,7 +78,11 @@
#define FFI_TRAMPOLINE_SIZE 24
#define FFI_NATIVE_RAW_API 0
#else
+#ifdef X86_WIN32
+#define FFI_TRAMPOLINE_SIZE 13
+#else
#define FFI_TRAMPOLINE_SIZE 10
+#endif
#define FFI_NATIVE_RAW_API 1 /* x86 has native raw api support */
#endif