From 4836f05059eb299d911557967ee61271899474fe Mon Sep 17 00:00:00 2001 From: Timothy Wall Date: Mon, 13 Jan 2014 02:23:08 -0500 Subject: [PATCH] don't align arguments in stdcall --- native/libffi/src/x86/ffi.c | 3 ++ .../testsuite/libffi.call/align_stdcall.c | 42 +++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100755 native/libffi/testsuite/libffi.call/align_stdcall.c diff --git a/native/libffi/src/x86/ffi.c b/native/libffi/src/x86/ffi.c index c44f4f0f20..9d19791271 100644 --- a/native/libffi/src/x86/ffi.c +++ b/native/libffi/src/x86/ffi.c @@ -305,6 +305,9 @@ ffi_status ffi_prep_cif_machdep(ffi_cif *cif) for (ptr = cif->arg_types, i = cif->nargs; i > 0; i--, ptr++) { +#ifdef X86_WIN32 + if (cif->abi != FFI_STDCALL) +#endif if (((*ptr)->alignment - 1) & cif->bytes) cif->bytes = ALIGN(cif->bytes, (*ptr)->alignment); cif->bytes += ALIGN((*ptr)->size, FFI_SIZEOF_ARG); diff --git a/native/libffi/testsuite/libffi.call/align_stdcall.c b/native/libffi/testsuite/libffi.call/align_stdcall.c new file mode 100755 index 0000000000..ed3511b113 --- /dev/null +++ b/native/libffi/testsuite/libffi.call/align_stdcall.c @@ -0,0 +1,42 @@ +/* Area: ffi_call + Purpose: Check stdcall for argument alignment (always 4) on X86_WIN32 systems. + Limitations: none. + PR: none. + Originator: (from many_win32.c) */ + +/* { dg-do run { target i?86-*-cygwin* i?86-*-mingw* } } */ + +#include "ffitest.h" +#include + +static float __attribute__((stdcall)) stdcall_align(int i1, + double f2, + int i3, + double f4) +{ + return i1+f2+i3+f4; +} + +int main (void) +{ + ffi_cif cif; + ffi_type *args[4] = {&ffi_type_int, &ffi_type_double, &ffi_type_int, &ffi_type_double}; + float fa[2] = {1,2}; + int ia[2] = {1,2}; + void *values[4] = {&ia[0], &fa[0], &ia[1], &fa[1]}; + float f, ff; + + /* Initialize the cif */ + CHECK(ffi_prep_cif(&cif, FFI_STDCALL, 4, + &ffi_type_float, args) == FFI_OK); + + ff = stdcall_align(ia[0], fa[0], ia[1], fa[1]); + + ffi_call(&cif, FFI_FN(stdcall_align), &f, values); + + if (f - ff < FLT_EPSILON) + printf("stdcall many arg tests ok!\n"); + else + CHECK(0); + exit(0); +}