public inbox for libffi-discuss@sourceware.org
 help / color / mirror / Atom feed
* Re: libffi err_bad_abi excecution test fix
       [not found] <4AA05E04.5060503@simpson.demon.co.uk>
@ 2009-09-05 11:23 ` Andrew Haley
  2009-09-11 12:22   ` Anthony Green
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Haley @ 2009-09-05 11:23 UTC (permalink / raw)
  To: libffi-discuss; +Cc: Duncan Simpson

Forwarding upstream for consideration.

Andrew.

Duncan Simpson wrote:
> I believe the patch below fixes the err_bad_abi execution tests on all
> platforms. I have actually verified this on the x86_64 platform for
> both 32 and 64 bit binaries. I do not have access to verify that my
> fixes for other architectures are correct.
> 
> Please Cc: comments to me because I do not subscribe to the
> gcc-patches mailing list. I receive far too much email already.
> 
> Duncan Simpson (-:
> 
> 
> --- libffi/ChangeLog.dist    2009-09-02 00:30:05.958626045 +0100
> +++ libffi/ChangeLog    2009-09-04 00:48:32.986127555 +0100
> @@ -1,3 +1,24 @@
> +2009-08-03  Duncan Simpson <dps@simpson.demon.co.uk>
> +
> +    * src/prep_cif.c: In ffi_prep_cif return FFI_BAD_ABI is the abi
> +    parameter is not valid.
> +    * src/x86/libffi64.c: In ffi_prep_closure_loc return FFI_BAD_ABI
> +    if cif->abi is not a valid abi (tested on x86_64)
> +    * src/alpha/ffi.c: ditto (not tested)
> +    * src/arm/ffi.c: ditto (not tested)
> +    * src/cris/ffi.c: ditto (not tested)
> +    * src/frv/ffi.c: ditto (not tested)
> +    * src/ia64/ffi.c: In ffi_prep_cloure_loc return FFI_BAD_ABI
> +    instead of failing an assertion (not tested).
> +    * src/m66k/ffi.c: ditto (not tested)
> +    * src/mips/ffi.c: ditto (not tested)
> +    * src/pa/ffi.c: ditto (not tested)
> +    * src/powerpc/ffi.c: ditto (not tested)
> +    * src/s390/ffi.c: ditto (not tested)
> +    * src/sh/ffi.c: ditto (not tested)
> +    * src/sh64/ffi.c: ditto (not tested)
> +    * src/sparc/ffi.c: ditto (not tested)
> +
>  2009-08-24  Ralf Wildenhues  <Ralf.Wildenhues@gmx.de>
> 
>      * configure.ac (AC_PREREQ): Bump to 2.64.
> --- libffi/src/mips/ffi.c.dist    2009-08-29 01:26:58.686124378 +0100
> +++ libffi/src/mips/ffi.c    2009-09-02 18:05:16.990135433 +0100
> @@ -574,9 +574,13 @@
>    char *clear_location = (char *) codeloc;
> 
>  #if defined(FFI_MIPS_O32)
> +  if (cif->abi != FFI_O32 && cif->abi != FFI_O32_SOFT_FLOAT)
> +      return FFI_BAD_ABI;
>    FFI_ASSERT(cif->abi == FFI_O32 || cif->abi == FFI_O32_SOFT_FLOAT);
>    fn = ffi_closure_O32;
>  #else /* FFI_MIPS_N32 */
> +  if (cif->abi != FFI_N32 && cif->abi != FFI_N64)
> +      return FFI_BAD_ABI;
>    FFI_ASSERT(cif->abi == FFI_N32 || cif->abi == FFI_N64);
>    fn = ffi_closure_N32;
>  #endif /* FFI_MIPS_O32 */
> --- libffi/src/sparc/ffi.c.dist    2009-08-29 01:26:59.110636528 +0100
> +++ libffi/src/sparc/ffi.c    2009-09-02 18:16:50.266131344 +0100
> @@ -447,6 +447,8 @@
>  #ifdef SPARC64
>    /* Trampoline address is equal to the closure address.  We take
> advantage
>       of that to reduce the trampoline size by 8 bytes. */
> +  if (cif->abi != FFI_V9)
> +    return FFI_BAD_ABIl
>    FFI_ASSERT (cif->abi == FFI_V9);
>    fn = (unsigned long) ffi_closure_v9;
>    tramp[0] = 0x83414000;    /* rd    %pc, %g1    */
> @@ -456,6 +458,8 @@
>    *((unsigned long *) &tramp[4]) = fn;
>  #else
>    unsigned long ctx = (unsigned long) codeloc;
> +  if (cif->abi != FFI_V8)
> +    return FFI_BAD_ABIl
>    FFI_ASSERT (cif->abi == FFI_V8);
>    fn = (unsigned long) ffi_closure_v8;
>    tramp[0] = 0x03000000 | fn >> 10;    /* sethi %hi(fn), %g1    */
> --- libffi/src/sh/ffi.c.dist    2009-08-29 01:26:59.206126820 +0100
> +++ libffi/src/sh/ffi.c    2009-09-02 18:15:30.382640181 +0100
> @@ -463,6 +463,8 @@
>    unsigned int *tramp;
>    unsigned int insn;
> 
> +  if (cif->abi != FFI_GCC_SYSV)
> +    return FFI_BAD_ABI;
>    FFI_ASSERT (cif->abi == FFI_GCC_SYSV);
> 
>    tramp = (unsigned int *) &closure->tramp[0];
> --- libffi/src/pa/ffi.c.dist    2009-08-29 01:26:58.534630514 +0100
> +++ libffi/src/pa/ffi.c    2009-09-02 18:06:35.230132463 +0100
> @@ -626,6 +626,8 @@
>    UINT32 *tmp;
>  #endif
> 
> +  if (cif->abi != FFI_PA32)
> +      return FFI_BAD_ABI;
>    FFI_ASSERT (cif->abi == FFI_PA32);
> 
>    /* Make a small trampoline that will branch to our
> --- libffi/src/s390/ffi.c.dist    2009-08-29 01:26:58.438636691 +0100
> +++ libffi/src/s390/ffi.c    2009-09-02 18:12:54.014145749 +0100
> @@ -750,6 +750,8 @@
>                void *user_data,
>                void *codeloc)
>  {
> +  if (cif->abi != FFI_SYSV)
> +    return FFI_BAD_ABI;
>    FFI_ASSERT (cif->abi == FFI_SYSV);
> 
>  #ifndef __s390x__
> --- libffi/src/alpha/ffi.c.dist    2009-09-04 00:06:11.686634778 +0100
> +++ libffi/src/alpha/ffi.c    2009-09-04 00:06:21.262635864 +0100
> @@ -177,6 +177,8 @@
>                void *codeloc)
>  {
>    unsigned int *tramp;
> +  if (cif->abi<=FFI_FIRST_ABI || cif->abi > FFI_DEFAULT_ABI)
> +    return FFI_BAD_ABI;
> 
>    tramp = (unsigned int *) &closure->tramp[0];
>    tramp[0] = 0x47fb0401;    /* mov $27,$1        */
> --- libffi/src/frv/ffi.c.dist    2009-09-04 00:10:17.254128944 +0100
> +++ libffi/src/frv/ffi.c    2009-09-04 00:13:07.638635251 +0100
> @@ -259,6 +259,8 @@
>    register void *got __asm__("gr15");
>  #endif
>    int i;
> +  if (cif->abi != FFI_EABI)
> +    return FFI_BAD_ABI;
> 
>    fn = (unsigned long) ffi_closure_eabi;
> 
> --- libffi/src/prep_cif.c.dist    2009-09-04 00:38:46.514149189 +0100
> +++ libffi/src/prep_cif.c    2009-09-04 00:47:32.930636373 +0100
> @@ -92,6 +92,8 @@
>    unsigned int i;
>    ffi_type **ptr;
> 
> +  if (abi <= FFI_FIRST_ABI || abi > FFI_DEFAULT_ABI)
> +    return FFI_BAD_ABI;
>    FFI_ASSERT(cif != NULL);
>    FFI_ASSERT((abi > FFI_FIRST_ABI) && (abi <= FFI_DEFAULT_ABI));
> 
> --- libffi/src/powerpc/ffi.c.dist    2009-08-29 01:26:57.814627263 +0100
> +++ libffi/src/powerpc/ffi.c    2009-09-02 18:08:40.154128013 +0100
> @@ -948,6 +948,8 @@
>  #ifdef POWERPC64
>    void **tramp = (void **) &closure->tramp[0];
> 
> +  if (cif->abi != FFI_LINUX64)
> +    return FFI_BAD_ABI;
>    FFI_ASSERT (cif->abi == FFI_LINUX64);
>    /* Copy function address and TOC from ffi_closure_LINUX64.  */
>    memcpy (tramp, (char *) ffi_closure_LINUX64, 16);
> @@ -955,6 +957,8 @@
>  #else
>    unsigned int *tramp;
> 
> +  if (cif->abi != FFI_GCC_SYSV && cif->abi != FFI_SYSV)
> +    return FFI_BAD_ABI;
>    FFI_ASSERT (cif->abi == FFI_GCC_SYSV || cif->abi == FFI_SYSV);
> 
>    tramp = (unsigned int *) &closure->tramp[0];
> --- libffi/src/powerpc/ffi_darwin.c.dist    2009-08-29
> 01:26:57.822630703 +0100
> +++ libffi/src/powerpc/ffi_darwin.c    2009-09-02 18:10:20.642135172 +0100
> @@ -581,8 +581,7 @@
> 
>      default:
> 
> -      FFI_ASSERT(0);
> -      break;
> +      return FFI_BAD_ABI;
>      }
>    return FFI_OK;
>  }
> --- libffi/src/sh64/ffi.c.dist    2009-08-29 01:26:57.954649606 +0100
> +++ libffi/src/sh64/ffi.c    2009-09-02 18:14:30.966136362 +0100
> @@ -302,6 +302,8 @@
>  {
>    unsigned int *tramp;
> 
> +  if (cif->abi == FFI_GCC_SYSV)
> +    return FFI_BAD_ABI;
>    FFI_ASSERT (cif->abi == FFI_GCC_SYSV);
> 
>    tramp = (unsigned int *) &closure->tramp[0];
> --- libffi/src/arm/ffi.c.dist    2009-08-29 01:26:57.658650933 +0100
> +++ libffi/src/arm/ffi.c    2009-09-02 17:57:59.422131055 +0100
> @@ -295,6 +295,8 @@
>                void *user_data,
>                void *codeloc)
>  {
> +  if (cif->abi != FFI_SYSV)
> +    return FFI_BAD_ABI;
>    FFI_ASSERT (cif->abi == FFI_SYSV);
> 
>    FFI_INIT_TRAMPOLINE (&closure->tramp[0], \
> --- libffi/src/m68k/ffi.c.dist    2009-08-29 01:26:58.354638462 +0100
> +++ libffi/src/m68k/ffi.c    2009-09-02 18:03:11.070637441 +0100
> @@ -255,6 +255,8 @@
>                void *user_data,
>                void *codeloc)
>  {
> +  if (cif->abi != FFI_SYSV)
> +      return FFI_BAD_ABI;
>    FFI_ASSERT (cif->abi == FFI_SYSV);
> 
>    *(unsigned short *)closure->tramp = 0x207c;
> --- libffi/src/x86/ffi64.c.dist    2009-08-29 01:26:58.182641857 +0100
> +++ libffi/src/x86/ffi64.c    2009-09-03 23:45:40.134139291 +0100
> @@ -442,6 +442,8 @@
>                void *codeloc)
>  {
>    volatile unsigned short *tramp;
> +  if (cif->abi<=FFI_FIRST_ABI || cif->abi > FFI_DEFAULT_ABI)
> +    return FFI_BAD_ABI;
> 
>    tramp = (volatile unsigned short *) &closure->tramp[0];
> 
> --- libffi/src/ia64/ffi.c.dist    2009-08-29 01:26:58.582632324 +0100
> +++ libffi/src/ia64/ffi.c    2009-09-02 18:01:49.994135712 +0100
> @@ -425,6 +425,8 @@
>    struct ffi_ia64_trampoline_struct *tramp;
>    struct ia64_fd *fd;
> 
> +  if (cif->abi != FFI_UNIX)
> +      return FFI_BAD_ABI;
>    FFI_ASSERT (cif->abi == FFI_UNIX);
> 
>    tramp = (struct ffi_ia64_trampoline_struct *)closure->tramp;
> --- libffi/src/cris/ffi.c.dist    2009-08-29 01:26:58.482635236 +0100
> +++ libffi/src/cris/ffi.c    2009-09-02 17:58:13.890132060 +0100
> @@ -368,6 +368,8 @@
>                void *codeloc)
>  {
>    void *innerfn = ffi_prep_closure_inner;
> +  if (cif->abi != FFI_SYSV)
> +    return FFI_BAD_ABI;
>    FFI_ASSERT (cif->abi == FFI_SYSV);
>    closure->cif  = cif;
>    closure->user_data = user_data;

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: libffi err_bad_abi excecution test fix
  2009-09-05 11:23 ` libffi err_bad_abi excecution test fix Andrew Haley
@ 2009-09-11 12:22   ` Anthony Green
  2009-09-11 13:00     ` Timothy Wall
  0 siblings, 1 reply; 3+ messages in thread
From: Anthony Green @ 2009-09-11 12:22 UTC (permalink / raw)
  To: Duncan Simpson; +Cc: Andrew Haley, libffi-discuss

Andrew Haley wrote:
> Forwarding upstream for consideration.
>
> Andrew.
>
> Duncan Simpson wrote:
>   
>> I believe the patch below fixes the err_bad_abi execution tests on all
>> platforms. I have actually verified this on the x86_64 platform for
>> both 32 and 64 bit binaries. I do not have access to verify that my
>> fixes for other architectures are correct.
>>     
Thanks for this patch, Duncan.  I think we can remove a couple more 
FFI_ASSERTs at the bottom as well.  Let me tweak this and I'll apply to 
both repositories.

AG


>> Please Cc: comments to me because I do not subscribe to the
>> gcc-patches mailing list. I receive far too much email already.
>>
>> Duncan Simpson (-:
>>
>>
>> --- libffi/ChangeLog.dist    2009-09-02 00:30:05.958626045 +0100
>> +++ libffi/ChangeLog    2009-09-04 00:48:32.986127555 +0100
>> @@ -1,3 +1,24 @@
>> +2009-08-03  Duncan Simpson <dps@simpson.demon.co.uk>
>> +
>> +    * src/prep_cif.c: In ffi_prep_cif return FFI_BAD_ABI is the abi
>> +    parameter is not valid.
>> +    * src/x86/libffi64.c: In ffi_prep_closure_loc return FFI_BAD_ABI
>> +    if cif->abi is not a valid abi (tested on x86_64)
>> +    * src/alpha/ffi.c: ditto (not tested)
>> +    * src/arm/ffi.c: ditto (not tested)
>> +    * src/cris/ffi.c: ditto (not tested)
>> +    * src/frv/ffi.c: ditto (not tested)
>> +    * src/ia64/ffi.c: In ffi_prep_cloure_loc return FFI_BAD_ABI
>> +    instead of failing an assertion (not tested).
>> +    * src/m66k/ffi.c: ditto (not tested)
>> +    * src/mips/ffi.c: ditto (not tested)
>> +    * src/pa/ffi.c: ditto (not tested)
>> +    * src/powerpc/ffi.c: ditto (not tested)
>> +    * src/s390/ffi.c: ditto (not tested)
>> +    * src/sh/ffi.c: ditto (not tested)
>> +    * src/sh64/ffi.c: ditto (not tested)
>> +    * src/sparc/ffi.c: ditto (not tested)
>> +
>>  2009-08-24  Ralf Wildenhues  <Ralf.Wildenhues@gmx.de>
>>
>>      * configure.ac (AC_PREREQ): Bump to 2.64.
>> --- libffi/src/mips/ffi.c.dist    2009-08-29 01:26:58.686124378 +0100
>> +++ libffi/src/mips/ffi.c    2009-09-02 18:05:16.990135433 +0100
>> @@ -574,9 +574,13 @@
>>    char *clear_location = (char *) codeloc;
>>
>>  #if defined(FFI_MIPS_O32)
>> +  if (cif->abi != FFI_O32 && cif->abi != FFI_O32_SOFT_FLOAT)
>> +      return FFI_BAD_ABI;
>>    FFI_ASSERT(cif->abi == FFI_O32 || cif->abi == FFI_O32_SOFT_FLOAT);
>>    fn = ffi_closure_O32;
>>  #else /* FFI_MIPS_N32 */
>> +  if (cif->abi != FFI_N32 && cif->abi != FFI_N64)
>> +      return FFI_BAD_ABI;
>>    FFI_ASSERT(cif->abi == FFI_N32 || cif->abi == FFI_N64);
>>    fn = ffi_closure_N32;
>>  #endif /* FFI_MIPS_O32 */
>> --- libffi/src/sparc/ffi.c.dist    2009-08-29 01:26:59.110636528 +0100
>> +++ libffi/src/sparc/ffi.c    2009-09-02 18:16:50.266131344 +0100
>> @@ -447,6 +447,8 @@
>>  #ifdef SPARC64
>>    /* Trampoline address is equal to the closure address.  We take
>> advantage
>>       of that to reduce the trampoline size by 8 bytes. */
>> +  if (cif->abi != FFI_V9)
>> +    return FFI_BAD_ABIl
>>    FFI_ASSERT (cif->abi == FFI_V9);
>>    fn = (unsigned long) ffi_closure_v9;
>>    tramp[0] = 0x83414000;    /* rd    %pc, %g1    */
>> @@ -456,6 +458,8 @@
>>    *((unsigned long *) &tramp[4]) = fn;
>>  #else
>>    unsigned long ctx = (unsigned long) codeloc;
>> +  if (cif->abi != FFI_V8)
>> +    return FFI_BAD_ABIl
>>    FFI_ASSERT (cif->abi == FFI_V8);
>>    fn = (unsigned long) ffi_closure_v8;
>>    tramp[0] = 0x03000000 | fn >> 10;    /* sethi %hi(fn), %g1    */
>> --- libffi/src/sh/ffi.c.dist    2009-08-29 01:26:59.206126820 +0100
>> +++ libffi/src/sh/ffi.c    2009-09-02 18:15:30.382640181 +0100
>> @@ -463,6 +463,8 @@
>>    unsigned int *tramp;
>>    unsigned int insn;
>>
>> +  if (cif->abi != FFI_GCC_SYSV)
>> +    return FFI_BAD_ABI;
>>    FFI_ASSERT (cif->abi == FFI_GCC_SYSV);
>>
>>    tramp = (unsigned int *) &closure->tramp[0];
>> --- libffi/src/pa/ffi.c.dist    2009-08-29 01:26:58.534630514 +0100
>> +++ libffi/src/pa/ffi.c    2009-09-02 18:06:35.230132463 +0100
>> @@ -626,6 +626,8 @@
>>    UINT32 *tmp;
>>  #endif
>>
>> +  if (cif->abi != FFI_PA32)
>> +      return FFI_BAD_ABI;
>>    FFI_ASSERT (cif->abi == FFI_PA32);
>>
>>    /* Make a small trampoline that will branch to our
>> --- libffi/src/s390/ffi.c.dist    2009-08-29 01:26:58.438636691 +0100
>> +++ libffi/src/s390/ffi.c    2009-09-02 18:12:54.014145749 +0100
>> @@ -750,6 +750,8 @@
>>                void *user_data,
>>                void *codeloc)
>>  {
>> +  if (cif->abi != FFI_SYSV)
>> +    return FFI_BAD_ABI;
>>    FFI_ASSERT (cif->abi == FFI_SYSV);
>>
>>  #ifndef __s390x__
>> --- libffi/src/alpha/ffi.c.dist    2009-09-04 00:06:11.686634778 +0100
>> +++ libffi/src/alpha/ffi.c    2009-09-04 00:06:21.262635864 +0100
>> @@ -177,6 +177,8 @@
>>                void *codeloc)
>>  {
>>    unsigned int *tramp;
>> +  if (cif->abi<=FFI_FIRST_ABI || cif->abi > FFI_DEFAULT_ABI)
>> +    return FFI_BAD_ABI;
>>
>>    tramp = (unsigned int *) &closure->tramp[0];
>>    tramp[0] = 0x47fb0401;    /* mov $27,$1        */
>> --- libffi/src/frv/ffi.c.dist    2009-09-04 00:10:17.254128944 +0100
>> +++ libffi/src/frv/ffi.c    2009-09-04 00:13:07.638635251 +0100
>> @@ -259,6 +259,8 @@
>>    register void *got __asm__("gr15");
>>  #endif
>>    int i;
>> +  if (cif->abi != FFI_EABI)
>> +    return FFI_BAD_ABI;
>>
>>    fn = (unsigned long) ffi_closure_eabi;
>>
>> --- libffi/src/prep_cif.c.dist    2009-09-04 00:38:46.514149189 +0100
>> +++ libffi/src/prep_cif.c    2009-09-04 00:47:32.930636373 +0100
>> @@ -92,6 +92,8 @@
>>    unsigned int i;
>>    ffi_type **ptr;
>>
>> +  if (abi <= FFI_FIRST_ABI || abi > FFI_DEFAULT_ABI)
>> +    return FFI_BAD_ABI;
>>    FFI_ASSERT(cif != NULL);
>>    FFI_ASSERT((abi > FFI_FIRST_ABI) && (abi <= FFI_DEFAULT_ABI));
>>
>> --- libffi/src/powerpc/ffi.c.dist    2009-08-29 01:26:57.814627263 +0100
>> +++ libffi/src/powerpc/ffi.c    2009-09-02 18:08:40.154128013 +0100
>> @@ -948,6 +948,8 @@
>>  #ifdef POWERPC64
>>    void **tramp = (void **) &closure->tramp[0];
>>
>> +  if (cif->abi != FFI_LINUX64)
>> +    return FFI_BAD_ABI;
>>    FFI_ASSERT (cif->abi == FFI_LINUX64);
>>    /* Copy function address and TOC from ffi_closure_LINUX64.  */
>>    memcpy (tramp, (char *) ffi_closure_LINUX64, 16);
>> @@ -955,6 +957,8 @@
>>  #else
>>    unsigned int *tramp;
>>
>> +  if (cif->abi != FFI_GCC_SYSV && cif->abi != FFI_SYSV)
>> +    return FFI_BAD_ABI;
>>    FFI_ASSERT (cif->abi == FFI_GCC_SYSV || cif->abi == FFI_SYSV);
>>
>>    tramp = (unsigned int *) &closure->tramp[0];
>> --- libffi/src/powerpc/ffi_darwin.c.dist    2009-08-29
>> 01:26:57.822630703 +0100
>> +++ libffi/src/powerpc/ffi_darwin.c    2009-09-02 18:10:20.642135172 +0100
>> @@ -581,8 +581,7 @@
>>
>>      default:
>>
>> -      FFI_ASSERT(0);
>> -      break;
>> +      return FFI_BAD_ABI;
>>      }
>>    return FFI_OK;
>>  }
>> --- libffi/src/sh64/ffi.c.dist    2009-08-29 01:26:57.954649606 +0100
>> +++ libffi/src/sh64/ffi.c    2009-09-02 18:14:30.966136362 +0100
>> @@ -302,6 +302,8 @@
>>  {
>>    unsigned int *tramp;
>>
>> +  if (cif->abi == FFI_GCC_SYSV)
>> +    return FFI_BAD_ABI;
>>    FFI_ASSERT (cif->abi == FFI_GCC_SYSV);
>>
>>    tramp = (unsigned int *) &closure->tramp[0];
>> --- libffi/src/arm/ffi.c.dist    2009-08-29 01:26:57.658650933 +0100
>> +++ libffi/src/arm/ffi.c    2009-09-02 17:57:59.422131055 +0100
>> @@ -295,6 +295,8 @@
>>                void *user_data,
>>                void *codeloc)
>>  {
>> +  if (cif->abi != FFI_SYSV)
>> +    return FFI_BAD_ABI;
>>    FFI_ASSERT (cif->abi == FFI_SYSV);
>>
>>    FFI_INIT_TRAMPOLINE (&closure->tramp[0], \
>> --- libffi/src/m68k/ffi.c.dist    2009-08-29 01:26:58.354638462 +0100
>> +++ libffi/src/m68k/ffi.c    2009-09-02 18:03:11.070637441 +0100
>> @@ -255,6 +255,8 @@
>>                void *user_data,
>>                void *codeloc)
>>  {
>> +  if (cif->abi != FFI_SYSV)
>> +      return FFI_BAD_ABI;
>>    FFI_ASSERT (cif->abi == FFI_SYSV);
>>
>>    *(unsigned short *)closure->tramp = 0x207c;
>> --- libffi/src/x86/ffi64.c.dist    2009-08-29 01:26:58.182641857 +0100
>> +++ libffi/src/x86/ffi64.c    2009-09-03 23:45:40.134139291 +0100
>> @@ -442,6 +442,8 @@
>>                void *codeloc)
>>  {
>>    volatile unsigned short *tramp;
>> +  if (cif->abi<=FFI_FIRST_ABI || cif->abi > FFI_DEFAULT_ABI)
>> +    return FFI_BAD_ABI;
>>
>>    tramp = (volatile unsigned short *) &closure->tramp[0];
>>
>> --- libffi/src/ia64/ffi.c.dist    2009-08-29 01:26:58.582632324 +0100
>> +++ libffi/src/ia64/ffi.c    2009-09-02 18:01:49.994135712 +0100
>> @@ -425,6 +425,8 @@
>>    struct ffi_ia64_trampoline_struct *tramp;
>>    struct ia64_fd *fd;
>>
>> +  if (cif->abi != FFI_UNIX)
>> +      return FFI_BAD_ABI;
>>    FFI_ASSERT (cif->abi == FFI_UNIX);
>>
>>    tramp = (struct ffi_ia64_trampoline_struct *)closure->tramp;
>> --- libffi/src/cris/ffi.c.dist    2009-08-29 01:26:58.482635236 +0100
>> +++ libffi/src/cris/ffi.c    2009-09-02 17:58:13.890132060 +0100
>> @@ -368,6 +368,8 @@
>>                void *codeloc)
>>  {
>>    void *innerfn = ffi_prep_closure_inner;
>> +  if (cif->abi != FFI_SYSV)
>> +    return FFI_BAD_ABI;
>>    FFI_ASSERT (cif->abi == FFI_SYSV);
>>    closure->cif  = cif;
>>    closure->user_data = user_data;
>>     
>
>   

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: libffi err_bad_abi excecution test fix
  2009-09-11 12:22   ` Anthony Green
@ 2009-09-11 13:00     ` Timothy Wall
  0 siblings, 0 replies; 3+ messages in thread
From: Timothy Wall @ 2009-09-11 13:00 UTC (permalink / raw)
  To: Anthony Green; +Cc: Duncan Simpson, Andrew Haley, libffi-discuss

One small note:

Many targets assign FFI_LAST_ABI to FFI_DEFAULT_ABI+1, apparently  
having copied code from a target where FFI_DEFAULT_ABI was the highest- 
valued ABI defined.   When the default ABI is not the last enum,  
FFI_LAST_ABI will have an incorrect value (this is currently the case  
for X86_WIN32).

Targets with multiple active ABIs should be double-checked to ensure  
FFI_LAST_ABI will always have the correct value, and FFI_LAST_ABI used  
instead of FFI_DEFAULT_ABI when checking the abi valid range.

On Sep 11, 2009, at 8:25 AM, Anthony Green wrote:

> Andrew Haley wrote:
>> Forwarding upstream for consideration.
>>
>> Andrew.
>>
>> Duncan Simpson wrote:
>>
>>> I believe the patch below fixes the err_bad_abi execution tests on  
>>> all
>>> platforms. I have actually verified this on the x86_64 platform for
>>> both 32 and 64 bit binaries. I do not have access to verify that my
>>> fixes for other architectures are correct.
>>>
> Thanks for this patch, Duncan.  I think we can remove a couple more  
> FFI_ASSERTs at the bottom as well.  Let me tweak this and I'll apply  
> to both repositories.
>
> AG
>
>
>>> Please Cc: comments to me because I do not subscribe to the
>>> gcc-patches mailing list. I receive far too much email already.
>>>
>>> Duncan Simpson (-:
>>>
>>>
>>> --- libffi/ChangeLog.dist    2009-09-02 00:30:05.958626045 +0100
>>> +++ libffi/ChangeLog    2009-09-04 00:48:32.986127555 +0100
>>> @@ -1,3 +1,24 @@
>>> +2009-08-03  Duncan Simpson <dps@simpson.demon.co.uk>
>>> +
>>> +    * src/prep_cif.c: In ffi_prep_cif return FFI_BAD_ABI is the abi
>>> +    parameter is not valid.
>>> +    * src/x86/libffi64.c: In ffi_prep_closure_loc return  
>>> FFI_BAD_ABI
>>> +    if cif->abi is not a valid abi (tested on x86_64)
>>> +    * src/alpha/ffi.c: ditto (not tested)
>>> +    * src/arm/ffi.c: ditto (not tested)
>>> +    * src/cris/ffi.c: ditto (not tested)
>>> +    * src/frv/ffi.c: ditto (not tested)
>>> +    * src/ia64/ffi.c: In ffi_prep_cloure_loc return FFI_BAD_ABI
>>> +    instead of failing an assertion (not tested).
>>> +    * src/m66k/ffi.c: ditto (not tested)
>>> +    * src/mips/ffi.c: ditto (not tested)
>>> +    * src/pa/ffi.c: ditto (not tested)
>>> +    * src/powerpc/ffi.c: ditto (not tested)
>>> +    * src/s390/ffi.c: ditto (not tested)
>>> +    * src/sh/ffi.c: ditto (not tested)
>>> +    * src/sh64/ffi.c: ditto (not tested)
>>> +    * src/sparc/ffi.c: ditto (not tested)
>>> +
>>> 2009-08-24  Ralf Wildenhues  <Ralf.Wildenhues@gmx.de>
>>>
>>>    * configure.ac (AC_PREREQ): Bump to 2.64.
>>> --- libffi/src/mips/ffi.c.dist    2009-08-29 01:26:58.686124378  
>>> +0100
>>> +++ libffi/src/mips/ffi.c    2009-09-02 18:05:16.990135433 +0100
>>> @@ -574,9 +574,13 @@
>>>  char *clear_location = (char *) codeloc;
>>>
>>> #if defined(FFI_MIPS_O32)
>>> +  if (cif->abi != FFI_O32 && cif->abi != FFI_O32_SOFT_FLOAT)
>>> +      return FFI_BAD_ABI;
>>>  FFI_ASSERT(cif->abi == FFI_O32 || cif->abi == FFI_O32_SOFT_FLOAT);
>>>  fn = ffi_closure_O32;
>>> #else /* FFI_MIPS_N32 */
>>> +  if (cif->abi != FFI_N32 && cif->abi != FFI_N64)
>>> +      return FFI_BAD_ABI;
>>>  FFI_ASSERT(cif->abi == FFI_N32 || cif->abi == FFI_N64);
>>>  fn = ffi_closure_N32;
>>> #endif /* FFI_MIPS_O32 */
>>> --- libffi/src/sparc/ffi.c.dist    2009-08-29 01:26:59.110636528  
>>> +0100
>>> +++ libffi/src/sparc/ffi.c    2009-09-02 18:16:50.266131344 +0100
>>> @@ -447,6 +447,8 @@
>>> #ifdef SPARC64
>>>  /* Trampoline address is equal to the closure address.  We take
>>> advantage
>>>     of that to reduce the trampoline size by 8 bytes. */
>>> +  if (cif->abi != FFI_V9)
>>> +    return FFI_BAD_ABIl
>>>  FFI_ASSERT (cif->abi == FFI_V9);
>>>  fn = (unsigned long) ffi_closure_v9;
>>>  tramp[0] = 0x83414000;    /* rd    %pc, %g1    */
>>> @@ -456,6 +458,8 @@
>>>  *((unsigned long *) &tramp[4]) = fn;
>>> #else
>>>  unsigned long ctx = (unsigned long) codeloc;
>>> +  if (cif->abi != FFI_V8)
>>> +    return FFI_BAD_ABIl
>>>  FFI_ASSERT (cif->abi == FFI_V8);
>>>  fn = (unsigned long) ffi_closure_v8;
>>>  tramp[0] = 0x03000000 | fn >> 10;    /* sethi %hi(fn), %g1    */
>>> --- libffi/src/sh/ffi.c.dist    2009-08-29 01:26:59.206126820 +0100
>>> +++ libffi/src/sh/ffi.c    2009-09-02 18:15:30.382640181 +0100
>>> @@ -463,6 +463,8 @@
>>>  unsigned int *tramp;
>>>  unsigned int insn;
>>>
>>> +  if (cif->abi != FFI_GCC_SYSV)
>>> +    return FFI_BAD_ABI;
>>>  FFI_ASSERT (cif->abi == FFI_GCC_SYSV);
>>>
>>>  tramp = (unsigned int *) &closure->tramp[0];
>>> --- libffi/src/pa/ffi.c.dist    2009-08-29 01:26:58.534630514 +0100
>>> +++ libffi/src/pa/ffi.c    2009-09-02 18:06:35.230132463 +0100
>>> @@ -626,6 +626,8 @@
>>>  UINT32 *tmp;
>>> #endif
>>>
>>> +  if (cif->abi != FFI_PA32)
>>> +      return FFI_BAD_ABI;
>>>  FFI_ASSERT (cif->abi == FFI_PA32);
>>>
>>>  /* Make a small trampoline that will branch to our
>>> --- libffi/src/s390/ffi.c.dist    2009-08-29 01:26:58.438636691  
>>> +0100
>>> +++ libffi/src/s390/ffi.c    2009-09-02 18:12:54.014145749 +0100
>>> @@ -750,6 +750,8 @@
>>>              void *user_data,
>>>              void *codeloc)
>>> {
>>> +  if (cif->abi != FFI_SYSV)
>>> +    return FFI_BAD_ABI;
>>>  FFI_ASSERT (cif->abi == FFI_SYSV);
>>>
>>> #ifndef __s390x__
>>> --- libffi/src/alpha/ffi.c.dist    2009-09-04 00:06:11.686634778  
>>> +0100
>>> +++ libffi/src/alpha/ffi.c    2009-09-04 00:06:21.262635864 +0100
>>> @@ -177,6 +177,8 @@
>>>              void *codeloc)
>>> {
>>>  unsigned int *tramp;
>>> +  if (cif->abi<=FFI_FIRST_ABI || cif->abi > FFI_DEFAULT_ABI)
>>> +    return FFI_BAD_ABI;
>>>
>>>  tramp = (unsigned int *) &closure->tramp[0];
>>>  tramp[0] = 0x47fb0401;    /* mov $27,$1        */
>>> --- libffi/src/frv/ffi.c.dist    2009-09-04 00:10:17.254128944 +0100
>>> +++ libffi/src/frv/ffi.c    2009-09-04 00:13:07.638635251 +0100
>>> @@ -259,6 +259,8 @@
>>>  register void *got __asm__("gr15");
>>> #endif
>>>  int i;
>>> +  if (cif->abi != FFI_EABI)
>>> +    return FFI_BAD_ABI;
>>>
>>>  fn = (unsigned long) ffi_closure_eabi;
>>>
>>> --- libffi/src/prep_cif.c.dist    2009-09-04 00:38:46.514149189  
>>> +0100
>>> +++ libffi/src/prep_cif.c    2009-09-04 00:47:32.930636373 +0100
>>> @@ -92,6 +92,8 @@
>>>  unsigned int i;
>>>  ffi_type **ptr;
>>>
>>> +  if (abi <= FFI_FIRST_ABI || abi > FFI_DEFAULT_ABI)
>>> +    return FFI_BAD_ABI;
>>>  FFI_ASSERT(cif != NULL);
>>>  FFI_ASSERT((abi > FFI_FIRST_ABI) && (abi <= FFI_DEFAULT_ABI));
>>>
>>> --- libffi/src/powerpc/ffi.c.dist    2009-08-29 01:26:57.814627263  
>>> +0100
>>> +++ libffi/src/powerpc/ffi.c    2009-09-02 18:08:40.154128013 +0100
>>> @@ -948,6 +948,8 @@
>>> #ifdef POWERPC64
>>>  void **tramp = (void **) &closure->tramp[0];
>>>
>>> +  if (cif->abi != FFI_LINUX64)
>>> +    return FFI_BAD_ABI;
>>>  FFI_ASSERT (cif->abi == FFI_LINUX64);
>>>  /* Copy function address and TOC from ffi_closure_LINUX64.  */
>>>  memcpy (tramp, (char *) ffi_closure_LINUX64, 16);
>>> @@ -955,6 +957,8 @@
>>> #else
>>>  unsigned int *tramp;
>>>
>>> +  if (cif->abi != FFI_GCC_SYSV && cif->abi != FFI_SYSV)
>>> +    return FFI_BAD_ABI;
>>>  FFI_ASSERT (cif->abi == FFI_GCC_SYSV || cif->abi == FFI_SYSV);
>>>
>>>  tramp = (unsigned int *) &closure->tramp[0];
>>> --- libffi/src/powerpc/ffi_darwin.c.dist    2009-08-29
>>> 01:26:57.822630703 +0100
>>> +++ libffi/src/powerpc/ffi_darwin.c    2009-09-02  
>>> 18:10:20.642135172 +0100
>>> @@ -581,8 +581,7 @@
>>>
>>>    default:
>>>
>>> -      FFI_ASSERT(0);
>>> -      break;
>>> +      return FFI_BAD_ABI;
>>>    }
>>>  return FFI_OK;
>>> }
>>> --- libffi/src/sh64/ffi.c.dist    2009-08-29 01:26:57.954649606  
>>> +0100
>>> +++ libffi/src/sh64/ffi.c    2009-09-02 18:14:30.966136362 +0100
>>> @@ -302,6 +302,8 @@
>>> {
>>>  unsigned int *tramp;
>>>
>>> +  if (cif->abi == FFI_GCC_SYSV)
>>> +    return FFI_BAD_ABI;
>>>  FFI_ASSERT (cif->abi == FFI_GCC_SYSV);
>>>
>>>  tramp = (unsigned int *) &closure->tramp[0];
>>> --- libffi/src/arm/ffi.c.dist    2009-08-29 01:26:57.658650933 +0100
>>> +++ libffi/src/arm/ffi.c    2009-09-02 17:57:59.422131055 +0100
>>> @@ -295,6 +295,8 @@
>>>              void *user_data,
>>>              void *codeloc)
>>> {
>>> +  if (cif->abi != FFI_SYSV)
>>> +    return FFI_BAD_ABI;
>>>  FFI_ASSERT (cif->abi == FFI_SYSV);
>>>
>>>  FFI_INIT_TRAMPOLINE (&closure->tramp[0], \
>>> --- libffi/src/m68k/ffi.c.dist    2009-08-29 01:26:58.354638462  
>>> +0100
>>> +++ libffi/src/m68k/ffi.c    2009-09-02 18:03:11.070637441 +0100
>>> @@ -255,6 +255,8 @@
>>>              void *user_data,
>>>              void *codeloc)
>>> {
>>> +  if (cif->abi != FFI_SYSV)
>>> +      return FFI_BAD_ABI;
>>>  FFI_ASSERT (cif->abi == FFI_SYSV);
>>>
>>>  *(unsigned short *)closure->tramp = 0x207c;
>>> --- libffi/src/x86/ffi64.c.dist    2009-08-29 01:26:58.182641857  
>>> +0100
>>> +++ libffi/src/x86/ffi64.c    2009-09-03 23:45:40.134139291 +0100
>>> @@ -442,6 +442,8 @@
>>>              void *codeloc)
>>> {
>>>  volatile unsigned short *tramp;
>>> +  if (cif->abi<=FFI_FIRST_ABI || cif->abi > FFI_DEFAULT_ABI)
>>> +    return FFI_BAD_ABI;
>>>
>>>  tramp = (volatile unsigned short *) &closure->tramp[0];
>>>
>>> --- libffi/src/ia64/ffi.c.dist    2009-08-29 01:26:58.582632324  
>>> +0100
>>> +++ libffi/src/ia64/ffi.c    2009-09-02 18:01:49.994135712 +0100
>>> @@ -425,6 +425,8 @@
>>>  struct ffi_ia64_trampoline_struct *tramp;
>>>  struct ia64_fd *fd;
>>>
>>> +  if (cif->abi != FFI_UNIX)
>>> +      return FFI_BAD_ABI;
>>>  FFI_ASSERT (cif->abi == FFI_UNIX);
>>>
>>>  tramp = (struct ffi_ia64_trampoline_struct *)closure->tramp;
>>> --- libffi/src/cris/ffi.c.dist    2009-08-29 01:26:58.482635236  
>>> +0100
>>> +++ libffi/src/cris/ffi.c    2009-09-02 17:58:13.890132060 +0100
>>> @@ -368,6 +368,8 @@
>>>              void *codeloc)
>>> {
>>>  void *innerfn = ffi_prep_closure_inner;
>>> +  if (cif->abi != FFI_SYSV)
>>> +    return FFI_BAD_ABI;
>>>  FFI_ASSERT (cif->abi == FFI_SYSV);
>>>  closure->cif  = cif;
>>>  closure->user_data = user_data;
>>>
>>
>>
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-09-11 13:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <4AA05E04.5060503@simpson.demon.co.uk>
2009-09-05 11:23 ` libffi err_bad_abi excecution test fix Andrew Haley
2009-09-11 12:22   ` Anthony Green
2009-09-11 13:00     ` Timothy Wall

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).