Commit 2d9b3939751b3ef9739049509d353ade10b32a8f

Anthony Green 2013-01-09T21:14:54

Fix for closures with sunpro compiler

diff --git a/ChangeLog b/ChangeLog
index 289d195..ff76645 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2013-01-10  Anthony Green  <green@moxielogic.com>
+
+	* configure.ac: Put local.exp in the right place.
+	* configure: Rebuilt.
+
+	* src/x86/ffi.c: Update comment about regparm function attributes.
+	* src/x86/sysv.S (ffi_closure_SYSV): The SUNPRO compiler requires
+	that all function arguments be passed on the stack (no regparm
+	support).
+
 2013-01-08  Anthony Green  <green@moxielogic.com>
 
 	* configure.ac: Generate local.exp.  This sets CC_FOR_TARGET
diff --git a/configure b/configure
index 5876eb7..4a12b96 100755
--- a/configure
+++ b/configure
@@ -13068,10 +13068,10 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu
 
 if test "x$GCC" = "xyes"; then
   CFLAGS="$CFLAGS -fexceptions"
-  touch testsuite/local.exp
+  touch local.exp
 else
   cat > local.exp <<EOF
-set CC_FOR_TARGET $CC
+set CC_FOR_TARGET "$CC"
 EOF
 fi
 
diff --git a/configure.ac b/configure.ac
index 7ffb36c..13d5bc2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -40,10 +40,10 @@ AX_CC_MAXOPT
 AX_CFLAGS_WARN_ALL
 if test "x$GCC" = "xyes"; then
   CFLAGS="$CFLAGS -fexceptions"
-  touch testsuite/local.exp
+  touch local.exp
 else
   cat > local.exp <<EOF
-set CC_FOR_TARGET $CC  
+set CC_FOR_TARGET "$CC"
 EOF
 fi
 
diff --git a/src/x86/ffi.c b/src/x86/ffi.c
index 611e221..3f46693 100644
--- a/src/x86/ffi.c
+++ b/src/x86/ffi.c
@@ -424,7 +424,7 @@ void ffi_call(ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue)
 /** private members **/
 
 /* The following __attribute__((regparm(1))) decorations will have no effect
-   on MSVC - standard cdecl convention applies. */
+   on MSVC or SUNPRO_C -- standard conventions apply. */
 static void ffi_prep_incoming_args_SYSV (char *stack, void **ret,
                                          void** args, ffi_cif* cif);
 void FFI_HIDDEN ffi_closure_SYSV (ffi_closure *)
diff --git a/src/x86/sysv.S b/src/x86/sysv.S
index 69e7e8d..71502bb 100644
--- a/src/x86/sysv.S
+++ b/src/x86/sysv.S
@@ -182,9 +182,19 @@ ffi_closure_SYSV:
 	leal	-24(%ebp), %edx
 	movl	%edx, -12(%ebp)	/* resp */
 	leal	8(%ebp), %edx
+#ifdef __SUNPRO_C
+	/* The SUNPRO compiler doesn't support GCC's regparm function
+  	   attribute, so we have to pass all three arguments to
+	   ffi_closure_SYSV_inner on the stack.  */
+	movl	%edx, 8(%esp)	/* args = __builtin_dwarf_cfa () */
+	leal	-12(%ebp), %edx
+	movl	%edx, 4(%esp)	/* &resp */
+	movl    %eax, (%esp)    /* closure */
+#else
 	movl	%edx, 4(%esp)	/* args = __builtin_dwarf_cfa () */
 	leal	-12(%ebp), %edx
 	movl	%edx, (%esp)	/* &resp */
+#endif
 #if defined HAVE_HIDDEN_VISIBILITY_ATTRIBUTE || !defined __PIC__
 	call	ffi_closure_SYSV_inner
 #else