From f0f4138f90345d7d67dfa6783a7e1c7cc30d3c6f Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Sat, 22 Mar 2014 10:00:53 -0700 Subject: [PATCH 1/3] win32.S: Add handling for position-independent code on Darwin Newer versions of Darwin generate the necessary stub functions automatically and just need a call instruction, but accomodating older versions as well requires adding the stub. --- src/x86/win32.S | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/x86/win32.S b/src/x86/win32.S index b455982c..826a5a0f 100644 --- a/src/x86/win32.S +++ b/src/x86/win32.S @@ -691,6 +691,8 @@ USCORE_SYMBOL(ffi_closure_SYSV): movl %edx, (%esp) /* &resp */ #if defined(HAVE_HIDDEN_VISIBILITY_ATTRIBUTE) || !defined(__PIC__) call USCORE_SYMBOL(ffi_closure_SYSV_inner) +#elif defined(X86_DARWIN) + calll L_ffi_closure_SYSV_inner$stub #else movl %ebx, 8(%esp) call 1f @@ -970,6 +972,8 @@ USCORE_SYMBOL(ffi_closure_STDCALL): movl %edx, (%esp) /* &resp */ #if defined(HAVE_HIDDEN_VISIBILITY_ATTRIBUTE) || !defined(__PIC__) call USCORE_SYMBOL(ffi_closure_SYSV_inner) +#elif defined(X86_DARWIN) + calll L_ffi_closure_SYSV_inner$stub #else movl %ebx, 8(%esp) call 1f @@ -1070,6 +1074,13 @@ USCORE_SYMBOL(ffi_closure_STDCALL): .ffi_closure_STDCALL_end: .LFE5: +#if defined(X86_DARWIN) +.section __IMPORT,__jump_table,symbol_stubs,self_modifying_code+pure_instructions,5 +L_ffi_closure_SYSV_inner$stub: + .indirect_symbol _ffi_closure_SYSV_inner + hlt ; hlt ; hlt ; hlt ; hlt +#endif + #if defined(X86_WIN32) && !defined(__OS2__) .section .eh_frame,"w" #endif From be50b87a490e794362cb4a27ada2fbaab202adb8 Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Mon, 24 Mar 2014 21:44:13 -0700 Subject: [PATCH 2/3] Always use configure to detect whether global symbols need underscores 64-bit Windows already used this check; make it universal, and use it in place of an ifdef on X86_WIN32, to handle non-Windows platforms that use the underscore, such as Darwin. --- configure.ac | 8 +++----- src/x86/win32.S | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/configure.ac b/configure.ac index 3169c434..ffcdd49f 100644 --- a/configure.ac +++ b/configure.ac @@ -439,11 +439,9 @@ AC_ARG_ENABLE(pax_emutramp, [Define this if you want to enable pax emulated trampolines]) fi) -if test x$TARGET = xX86_WIN64; then - LT_SYS_SYMBOL_USCORE - if test "x$sys_symbol_underscore" = xyes; then - AC_DEFINE(SYMBOL_UNDERSCORE, 1, [Define if symbols are underscored.]) - fi +LT_SYS_SYMBOL_USCORE +if test "x$sys_symbol_underscore" = xyes; then + AC_DEFINE(SYMBOL_UNDERSCORE, 1, [Define if symbols are underscored.]) fi FFI_EXEC_TRAMPOLINE_TABLE=0 diff --git a/src/x86/win32.S b/src/x86/win32.S index 826a5a0f..d71c8b86 100644 --- a/src/x86/win32.S +++ b/src/x86/win32.S @@ -473,7 +473,7 @@ END #else -#if defined(X86_WIN32) +#if defined(SYMBOL_UNDERSCORE) #define USCORE_SYMBOL(x) _##x #else #define USCORE_SYMBOL(x) x From b2d610e028b5ce48d1ad7e5d0debc9c321d891b2 Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Fri, 21 Mar 2014 11:10:13 -0700 Subject: [PATCH 3/3] Compile win32.S on 32-bit Darwin as well --- Makefile.am | 3 +++ configure.ac | 2 ++ generate-darwin-source-and-headers.py | 4 ++-- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Makefile.am b/Makefile.am index e2011e7e..7ab945f2 100644 --- a/Makefile.am +++ b/Makefile.am @@ -138,6 +138,9 @@ nodist_libffi_la_SOURCES += src/x86/ffi.c src/x86/win64.S endif if X86_DARWIN nodist_libffi_la_SOURCES += src/x86/ffi.c src/x86/darwin.S src/x86/ffi64.c src/x86/darwin64.S +if X86_DARWIN32 +nodist_libffi_la_SOURCES += src/x86/win32.S +endif endif if SPARC nodist_libffi_la_SOURCES += src/sparc/ffi.c src/sparc/v8.S src/sparc/v9.S diff --git a/configure.ac b/configure.ac index ffcdd49f..00b43178 100644 --- a/configure.ac +++ b/configure.ac @@ -300,6 +300,8 @@ AM_CONDITIONAL(X86_FREEBSD, test x$TARGET = xX86_FREEBSD) AM_CONDITIONAL(X86_WIN32, test x$TARGET = xX86_WIN32) AM_CONDITIONAL(X86_WIN64, test x$TARGET = xX86_WIN64) AM_CONDITIONAL(X86_DARWIN, test x$TARGET = xX86_DARWIN) +AM_CONDITIONAL(X86_DARWIN32, test x$TARGET = xX86_DARWIN && test $ac_cv_sizeof_size_t = 4) +AM_CONDITIONAL(X86_DARWIN64, test x$TARGET = xX86_DARWIN && test $ac_cv_sizeof_size_t = 8) AM_CONDITIONAL(ALPHA, test x$TARGET = xALPHA) AM_CONDITIONAL(IA64, test x$TARGET = xIA64) AM_CONDITIONAL(M32R, test x$TARGET = xM32R) diff --git a/generate-darwin-source-and-headers.py b/generate-darwin-source-and-headers.py index 05b71287..964e861d 100644 --- a/generate-darwin-source-and-headers.py +++ b/generate-darwin-source-and-headers.py @@ -19,7 +19,7 @@ class simulator_platform(Platform): prefix = "#ifdef __i386__\n\n" suffix = "\n\n#endif" src_dir = 'x86' - src_files = ['darwin.S', 'ffi.c'] + src_files = ['darwin.S', 'win32.S', 'ffi.c'] class simulator64_platform(Platform): @@ -68,7 +68,7 @@ class desktop32_platform(Platform): triple = 'i386-apple-darwin10' version_min = '-mmacosx-version-min=10.6' src_dir = 'x86' - src_files = ['darwin.S', 'ffi.c'] + src_files = ['darwin.S', 'win32.S', 'ffi.c'] prefix = "#ifdef __i386__\n\n" suffix = "\n\n#endif"