public inbox for libffi-discuss@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Fixed compilation on mingw-w64 after recent ABI change.
@ 2010-11-04 14:23 Jacek Caban
  2010-11-10 12:12 ` Jacek Caban
  0 siblings, 1 reply; 4+ messages in thread
From: Jacek Caban @ 2010-11-04 14:23 UTC (permalink / raw)
  To: libffi-discuss

[-- Attachment #1: Type: text/plain, Size: 283 bytes --]

Hi,

mingw-w64 ABI has been recently changed to use nonunderscored symbol names 
(for compatibility with MSVC). The attached patch fixes libffi compilation 
with recent mingw-w64. For backward compatibility, I've added a configure 
check for underscored symbols.

Thanks,
     Jacek

[-- Attachment #2: patch.diff --]
[-- Type: text/plain, Size: 2588 bytes --]

commit 96e8ff948be4c853a36510ee40171063e1610d2d
Author: Jacek Caban <jacek@codeweavers.com>
Date:   Thu Nov 4 15:00:56 2010 +0000

    Fixed compilation on mingw-w64 after recent ABI change.

diff --git a/configure.ac b/configure.ac
index 50f24bc..3380ca1 100644
--- a/configure.ac
+++ b/configure.ac
@@ -315,6 +315,21 @@ if test x$TARGET = xX86 || test x$TARGET = xX86_WIN32 || test x$TARGET = xX86_64
     fi
 fi
 
+if test x$TARGET = xX86_WIN64; then
+    AC_CACHE_CHECK([sumbols are underscored],
+       libffi_cv_symbol_underscore, [
+       libffi_cv_symbol_underscore=unknown
+       # Check if symbols are underscored
+       AC_TRY_LINK([int cvar;],
+		   [asm ("mov \$_cvar, %rax\n");],
+		   [libffi_cv_symbol_underscore=yes],
+		   [libffi_cv_symbol_underscore=no])
+    ])
+    if test "x$libffi_cv_symbol_underscore" = xyes; then
+        AC_DEFINE(SYMBOL_UNDERSCORE, 1, [Define if symbols are underscored.])
+    fi
+fi
+
 case "$target" in
      *-apple-darwin10* | *-*-freebsd* | *-*-openbsd* | *-pc-solaris*)
        AC_DEFINE(FFI_MMAP_EXEC_WRIT, 1,
diff --git a/src/x86/win64.S b/src/x86/win64.S
index 6e91818..fcdb270 100644
--- a/src/x86/win64.S
+++ b/src/x86/win64.S
@@ -232,10 +232,18 @@ ret_void$:
 ffi_call_win64 ENDP
 _TEXT	ENDS
 END
-#else        
+
+#else
+
+#ifdef SYMBOL_UNDERSCORE
+#define SYMBOL_NAME(name) _##name
+#else
+#define SYMBOL_NAME(name) name
+#endif
+
 .text
 
-.extern _ffi_closure_win64_inner
+.extern SYMBOL_NAME(ffi_closure_win64_inner)
 
 # ffi_closure_win64 will be called with these registers set:
 #    rax points to 'closure'
@@ -246,8 +254,8 @@ END
 # call ffi_closure_win64_inner for the actual work, then return the result.
 # 
 	.balign 16
-        .globl _ffi_closure_win64	
-_ffi_closure_win64:     
+        .globl SYMBOL_NAME(ffi_closure_win64)
+SYMBOL_NAME(ffi_closure_win64):
 	# copy register arguments onto stack
 	test	$1,%r11
 	jne	.Lfirst_is_float	
@@ -287,7 +295,7 @@ _ffi_closure_win64:
 	mov	%rax, %rcx	# context is first parameter
 	mov	%rsp, %rdx	# stack is second parameter
 	add	$48, %rdx	# point to start of arguments
-	mov	$_ffi_closure_win64_inner, %rax
+	mov	$SYMBOL_NAME(ffi_closure_win64_inner), %rax
 	callq	*%rax		# call the real closure function
 	add	$40, %rsp
 	movq	%rax, %xmm0	# If the closure returned a float,
@@ -296,8 +304,8 @@ _ffi_closure_win64:
 .ffi_closure_win64_end:
 
 	.balign 16
-        .globl	_ffi_call_win64
-_ffi_call_win64:        
+        .globl	SYMBOL_NAME(ffi_call_win64)
+SYMBOL_NAME(ffi_call_win64):
         # copy registers onto stack
 	mov	%r9,32(%rsp)
 	mov	%r8,24(%rsp)

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

* Re: [PATCH] Fixed compilation on mingw-w64 after recent ABI change.
  2010-11-04 14:23 [PATCH] Fixed compilation on mingw-w64 after recent ABI change Jacek Caban
@ 2010-11-10 12:12 ` Jacek Caban
  2010-11-13  7:12   ` Anthony Green
  0 siblings, 1 reply; 4+ messages in thread
From: Jacek Caban @ 2010-11-10 12:12 UTC (permalink / raw)
  To: libffi-discuss

On 11/4/10 3:22 PM, Jacek Caban wrote:
> Hi,
>
> mingw-w64 ABI has been recently changed to use nonunderscored symbol 
> names (for compatibility with MSVC). The attached patch fixes libffi 
> compilation with recent mingw-w64. For backward compatibility, I've added 
> a configure check for underscored symbols.

I've got no response in almost a week, is there something wrong with this 
patch?

Jacek

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

* Re: [PATCH] Fixed compilation on mingw-w64 after recent ABI change.
  2010-11-10 12:12 ` Jacek Caban
@ 2010-11-13  7:12   ` Anthony Green
  2010-11-13 14:26     ` Jacek Caban
  0 siblings, 1 reply; 4+ messages in thread
From: Anthony Green @ 2010-11-13  7:12 UTC (permalink / raw)
  To: Jacek Caban; +Cc: libffi-discuss

Jacek Caban <jacek@codeweavers.com> writes:

> On 11/4/10 3:22 PM, Jacek Caban wrote:
>> Hi,
>>
>> mingw-w64 ABI has been recently changed to use nonunderscored symbol
>> names (for compatibility with MSVC). The attached patch fixes libffi
>> compilation with recent mingw-w64. For backward compatibility, I've
>> added a configure check for underscored symbols.
>
> I've got no response in almost a week, is there something wrong with
> this patch?

libffi is a volunteer project for me, which means that contributors
often have to be patient.

The patch looks OK to me.  There's one spelling error ("sumbols").
FWIW, I prefer libtool's autoconf macro for underscore prefix tests.  It
compiles code and looks at the nm output to see if symbols are prefixed
or not.  Your test uses x86 assembly code, although I realize that your
#ifdef around the config test so that it will only be run on x86 hw.

Please resubmit with the spelling fix and a proper ChangeLog file entry
and I'll merge it in.  If you switch to the portable '_' test, I'd be
even happier, but it's not necessary.

Thanks for your patch, Jacek!

AG



>
> Jacek

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

* Re: [PATCH] Fixed compilation on mingw-w64 after recent ABI change.
  2010-11-13  7:12   ` Anthony Green
@ 2010-11-13 14:26     ` Jacek Caban
  0 siblings, 0 replies; 4+ messages in thread
From: Jacek Caban @ 2010-11-13 14:26 UTC (permalink / raw)
  To: Anthony Green; +Cc: libffi-discuss

[-- Attachment #1: Type: text/plain, Size: 1362 bytes --]

On 11/13/10 8:11 AM, Anthony Green wrote:
> Jacek Caban<jacek@codeweavers.com>  writes:
>
>> On 11/4/10 3:22 PM, Jacek Caban wrote:
>>> Hi,
>>>
>>> mingw-w64 ABI has been recently changed to use nonunderscored symbol
>>> names (for compatibility with MSVC). The attached patch fixes libffi
>>> compilation with recent mingw-w64. For backward compatibility, I've
>>> added a configure check for underscored symbols.
>> I've got no response in almost a week, is there something wrong with
>> this patch?
> libffi is a volunteer project for me, which means that contributors
> often have to be patient.

I understand, I just wasn't sure if I should wait or did something wrong.

> The patch looks OK to me.  There's one spelling error ("sumbols").
> FWIW, I prefer libtool's autoconf macro for underscore prefix tests.  It
> compiles code and looks at the nm output to see if symbols are prefixed
> or not.  Your test uses x86 assembly code, although I realize that your
> #ifdef around the config test so that it will only be run on x86 hw.

I wasn't aware of the autoconf macro, it definitely make things look better.

> Please resubmit with the spelling fix and a proper ChangeLog file entry
> and I'll merge it in.  If you switch to the portable '_' test, I'd be
> even happier, but it's not necessary.

Fixed patch is attached.


Thanks for the review,

Jacek

[-- Attachment #2: patch.diff --]
[-- Type: text/plain, Size: 2706 bytes --]

commit a413fb475b6b64371a916c670b79404cc47813e6
Author: Jacek Caban <jacek@codeweavers.com>
Date:   Thu Nov 4 15:00:56 2010 +0000

    Fixed compilation on mingw-w64 after recent ABI change.

diff --git a/ChangeLog b/ChangeLog
index 5768c10..6232f46 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2010-11-13  Jacek Caban <jacek@codeweavers.com>
+	* configure.ac: Check for symbol underscores on mingw-w64.
+	* src/x86/win64.S: Correctly access extern symbols in respect to
+	underscores.
+
 2010-08-05  Dan Witte  <dwitte@mozilla.com>
 
         * Makefile.am: Pass FFI_DEBUG define to msvcc.sh for linking to the
diff --git a/configure.ac b/configure.ac
index 50f24bc..ac11a9a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -315,6 +315,13 @@ if test x$TARGET = xX86 || test x$TARGET = xX86_WIN32 || test x$TARGET = xX86_64
     fi
 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
+fi
+
 case "$target" in
      *-apple-darwin10* | *-*-freebsd* | *-*-openbsd* | *-pc-solaris*)
        AC_DEFINE(FFI_MMAP_EXEC_WRIT, 1,
diff --git a/src/x86/win64.S b/src/x86/win64.S
index 6e91818..fcdb270 100644
--- a/src/x86/win64.S
+++ b/src/x86/win64.S
@@ -232,10 +232,18 @@ ret_void$:
 ffi_call_win64 ENDP
 _TEXT	ENDS
 END
-#else        
+
+#else
+
+#ifdef SYMBOL_UNDERSCORE
+#define SYMBOL_NAME(name) _##name
+#else
+#define SYMBOL_NAME(name) name
+#endif
+
 .text
 
-.extern _ffi_closure_win64_inner
+.extern SYMBOL_NAME(ffi_closure_win64_inner)
 
 # ffi_closure_win64 will be called with these registers set:
 #    rax points to 'closure'
@@ -246,8 +254,8 @@ END
 # call ffi_closure_win64_inner for the actual work, then return the result.
 # 
 	.balign 16
-        .globl _ffi_closure_win64	
-_ffi_closure_win64:     
+        .globl SYMBOL_NAME(ffi_closure_win64)
+SYMBOL_NAME(ffi_closure_win64):
 	# copy register arguments onto stack
 	test	$1,%r11
 	jne	.Lfirst_is_float	
@@ -287,7 +295,7 @@ _ffi_closure_win64:
 	mov	%rax, %rcx	# context is first parameter
 	mov	%rsp, %rdx	# stack is second parameter
 	add	$48, %rdx	# point to start of arguments
-	mov	$_ffi_closure_win64_inner, %rax
+	mov	$SYMBOL_NAME(ffi_closure_win64_inner), %rax
 	callq	*%rax		# call the real closure function
 	add	$40, %rsp
 	movq	%rax, %xmm0	# If the closure returned a float,
@@ -296,8 +304,8 @@ _ffi_closure_win64:
 .ffi_closure_win64_end:
 
 	.balign 16
-        .globl	_ffi_call_win64
-_ffi_call_win64:        
+        .globl	SYMBOL_NAME(ffi_call_win64)
+SYMBOL_NAME(ffi_call_win64):
         # copy registers onto stack
 	mov	%r9,32(%rsp)
 	mov	%r8,24(%rsp)

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

end of thread, other threads:[~2010-11-13 14:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-11-04 14:23 [PATCH] Fixed compilation on mingw-w64 after recent ABI change Jacek Caban
2010-11-10 12:12 ` Jacek Caban
2010-11-13  7:12   ` Anthony Green
2010-11-13 14:26     ` Jacek Caban

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).