This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] x86_64 libffi fix
Hello,
> On Thu, Mar 20, 2003 at 02:11:59PM +0100, Zdenek Dvorak wrote:
> > ! ffi_closure_raw_SYSV (closure, args)
> > ! ffi_raw_closure *closure;
> > ! void *args;
>
> Might I suggest defining this function as regparm(1) and
> getting args from __builtin_dwarf_cfa ()? Then you don't
> need the pushes nor the pop+ret.
here is the updated patch.
Zdenek
Index: include/ffi.h.in
===================================================================
RCS file: /cvs/gcc/gcc/libffi/include/ffi.h.in,v
retrieving revision 1.20.2.3
diff -c -3 -p -r1.20.2.3 ffi.h.in
*** include/ffi.h.in 31 Jan 2003 21:50:21 -0000 1.20.2.3
--- include/ffi.h.in 20 Mar 2003 23:32:15 -0000
*************** extern "C" {
*** 170,175 ****
--- 170,182 ----
#endif
#endif
+ #ifdef X86_64
+ #if defined (__i386__)
+ #undef X86_64
+ #define X86
+ #endif
+ #endif
+
#ifndef LIBFFI_ASM
/* ---- Generic type definitions ----------------------------------------- */
Index: src/x86/ffi.c
===================================================================
RCS file: /cvs/gcc/gcc/libffi/src/x86/ffi.c,v
retrieving revision 1.8.12.1
diff -c -3 -p -r1.8.12.1 ffi.c
*** src/x86/ffi.c 7 Dec 2002 16:41:45 -0000 1.8.12.1
--- src/x86/ffi.c 20 Mar 2003 23:32:15 -0000
*************** void ffi_call(/* at dependent@*/ ffi_cif *c
*** 214,248 ****
static void ffi_prep_incoming_args_SYSV (char *stack, void **ret,
void** args, ffi_cif* cif);
! static void ffi_closure_SYSV ();
! static void ffi_closure_raw_SYSV ();
! /* This function is jumped to by the trampoline, on entry, %ecx (a
! * caller-save register) holds the address of the closure.
! * Clearly, this requires __GNUC__, so perhaps we should translate this
! * into an assembly file if this is to be distributed with ffi.
! */
static void
! ffi_closure_SYSV ()
{
// this is our return value storage
long double res;
// our various things...
- void *args;
ffi_cif *cif;
void **arg_area;
- ffi_closure *closure;
unsigned short rtype;
void *resp = (void*)&res;
- /* grab the trampoline context pointer */
- asm ("movl %%ecx,%0" : "=r" (closure));
-
cif = closure->cif;
arg_area = (void**) alloca (cif->nargs * sizeof (void*));
- asm ("leal 8(%%ebp),%0" : "=q" (args));
/* this call will initialize ARG_AREA, such that each
* element in that array points to the corresponding
--- 214,242 ----
static void ffi_prep_incoming_args_SYSV (char *stack, void **ret,
void** args, ffi_cif* cif);
! static void ffi_closure_SYSV (ffi_closure *)
! __attribute__ ((regparm(1)));
! static void ffi_closure_raw_SYSV (ffi_raw_closure *)
! __attribute__ ((regparm(1)));
! /* This function is jumped to by the trampoline */
static void
! ffi_closure_SYSV (closure)
! ffi_closure *closure;
{
// this is our return value storage
long double res;
// our various things...
ffi_cif *cif;
void **arg_area;
unsigned short rtype;
void *resp = (void*)&res;
+ void *args = __builtin_dwarf_cfa ();
cif = closure->cif;
arg_area = (void**) alloca (cif->nargs * sizeof (void*));
/* this call will initialize ARG_AREA, such that each
* element in that array points to the corresponding
*************** ffi_prep_incoming_args_SYSV(char *stack,
*** 330,340 ****
({ unsigned char *__tramp = (unsigned char*)(TRAMP); \
unsigned int __fun = (unsigned int)(FUN); \
unsigned int __ctx = (unsigned int)(CTX); \
! unsigned int __dis = __fun - ((unsigned int) __tramp + 10); \
! *(unsigned char*) &__tramp[0] = 0xb9; \
! *(unsigned int*) &__tramp[1] = __ctx; \
! *(unsigned char*) &__tramp[5] = 0xe9; \
! *(unsigned int*) &__tramp[6] = __dis; \
})
--- 324,334 ----
({ unsigned char *__tramp = (unsigned char*)(TRAMP); \
unsigned int __fun = (unsigned int)(FUN); \
unsigned int __ctx = (unsigned int)(CTX); \
! unsigned int __dis = __fun - ((unsigned int) __tramp + FFI_TRAMPOLINE_SIZE); \
! *(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 */ \
})
*************** ffi_prep_closure (ffi_closure* closure,
*** 364,393 ****
#if !FFI_NO_RAW_API
static void
! ffi_closure_raw_SYSV ()
{
// this is our return value storage
long double res;
// our various things...
- void *args;
ffi_raw *raw_args;
ffi_cif *cif;
- ffi_raw_closure *closure;
unsigned short rtype;
void *resp = (void*)&res;
- /* grab the trampoline context pointer */
- asm ("movl %%ecx,%0" : "=r" (closure));
-
- /* take the argument pointer */
- asm ("leal 8(%%ebp),%0" : "=q" (args));
-
/* get the cif */
cif = closure->cif;
/* the SYSV/X86 abi matches the RAW API exactly, well.. almost */
! raw_args = (ffi_raw*) args;
(closure->fun) (cif, resp, raw_args, closure->user_data);
--- 358,380 ----
#if !FFI_NO_RAW_API
static void
! ffi_closure_raw_SYSV (closure)
! ffi_raw_closure *closure;
{
// this is our return value storage
long double res;
// our various things...
ffi_raw *raw_args;
ffi_cif *cif;
unsigned short rtype;
void *resp = (void*)&res;
/* get the cif */
cif = closure->cif;
/* the SYSV/X86 abi matches the RAW API exactly, well.. almost */
! raw_args = (ffi_raw*) __builtin_dwarf_cfa ();
(closure->fun) (cif, resp, raw_args, closure->user_data);