Commit afee53738a995e23bd2f89fd0f7b30b380566106

Anthony Green 2014-03-25T16:12:35

Merge pull request #106 from joshtriplett/darwin-award [3.1 blocker] Update OS X build system to include win32.S on 32-bit

diff --git a/Makefile.am b/Makefile.am
index e2011e7..7ab945f 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 3169c43..00b4317 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)
@@ -439,11 +441,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/generate-darwin-source-and-headers.py b/generate-darwin-source-and-headers.py
index 05b7128..964e861 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"
diff --git a/src/x86/win32.S b/src/x86/win32.S
index b455982..d71c8b8 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
@@ -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