Bug #7485
closedruby cannot build on mingw32 or FreeBSD 8 due to missing __sync_val_compare_and_swap
Added by drbrain (Eric Hodel) almost 12 years ago. Updated almost 12 years ago.
Description
mingw32 GCC has the other atomic builtins but not this one. The attached patch checks for the GCC builtins used in ruby_atomic.h but not checked for by configure.
Files
configure.in.mingw32_gcc_builtins.patch (517 Bytes) configure.in.mingw32_gcc_builtins.patch | drbrain (Eric Hodel), 12/01/2012 07:38 AM |
Updated by nobu (Nobuyoshi Nakada) almost 12 years ago
__sync_or_and_fetch wasn't available in Apple derivative gcc.
Updated by shyouhei (Shyouhei Urabe) almost 12 years ago
@nobu (Nobuyoshi Nakada) Why do we have to bother old broken compiler?
Updated by kosaki (Motohiro KOSAKI) almost 12 years ago
I guess -march=i486 enable __sync_val_compare_and_swap.
Updated by nobu (Nobuyoshi Nakada) almost 12 years ago
Hmmm, if it can help, should add it by the default on mingw32?
Updated by luislavena (Luis Lavena) almost 12 years ago
Hello,
I just tested several native compilers on Windows 7 (without your patch) here are the results for those that define HAVE_GCC_ATOMIC_BUILTINS:
C:\Users\Luis\Code\ruby\ruby\build>gcc --version
gcc (tdm-1) 4.5.2
C:\Users\Luis\Code\ruby\ruby\build>cat .ext/include/i386-mingw32/ruby/config.h | grep ATOMIC
#define HAVE_GCC_ATOMIC_BUILTINS 1
C:\Users\Luis\Code\ruby\ruby\build>gcc --version
gcc (tdm-1) 4.6.1
C:\Users\Luis\Code\ruby\ruby\build>cat .ext/include/i386-mingw32/ruby/config.h | grep ATOMIC
#define HAVE_GCC_ATOMIC_BUILTINS 1
C:\Users\Luis\Code\ruby\ruby\build>gcc --version
gcc (rubenvb-4.7.2-release) 4.7.2
C:\Users\Luis\Code\ruby\ruby\build>cat .ext/include/i386-mingw32/ruby/config.h | grep ATOMIC
#define HAVE_GCC_ATOMIC_BUILTINS 1
In all scenarios it found the atomic builtins
On Windows XP (32bits), ATOMIC do get defined:
C:\Code\ruby\ruby\build>ver
Microsoft Windows XP [Version 5.1.2600]
C:\Code\ruby\ruby\build>gcc --version
gcc (rubenvb-4.7.2-release) 4.7.2
C:\Code\ruby\ruby\build>cat .ext\include\i386-mingw32\ruby\config.h | grep ATOMIC
#define HAVE_GCC_ATOMIC_BUILTINS 1
I was also able to compile Ruby without issues with "make all test"
I don't get the problem reported on this ticket on neither my systems.
I'm missing something?
Thank you.
Updated by jonforums (Jon Forums) almost 12 years ago
I agree with Luis' results and think we've just not fully debugged Eric's XP VM setup as in #7427.
With this snippet http://pastie.org/5460872 and Kosaki-san's feedback I see:
mingw-w64 32bit gcc 4.7.2¶
C:\sandbox>gcc --version
gcc (rubenvb-4.7.2-release) 4.7.2
C:\sandbox>gcc -Wall -o atomics.exe gcc_atomic.c
C:\sandbox>atomics.exe
Got 1
C:\sandbox>gcc -Wall -march=i386 -o atomics.exe gcc_atomic.c
C:\Users\Jon\AppData\Local\Temp\ccK9GPwk.o:gcc_atomic.c:(.text+0x2e): undefined reference
to `__sync_val_compare_and_swap_4'
collect2.exe: error: ld returned 1 exit status
mingw 32bit gcc 4.6.2¶
C:\sandbox>gcc --version
gcc (GCC) 4.6.2
C:\sandbox>gcc -Wall -o atomics.exe gcc_atomic.c
C:\Users\Jon\AppData\Local\Temp\ccpeH4Vt.o:gcc_atomic.c:(.text+0x2e): undefined reference
to `__sync_val_compare_and_swap_4'
collect2: ld returned 1 exit status
C:\sandbox>gcc -Wall -march={i486,i586,i686,native,core2} -o atomics.exe gcc_atomic.c
C:\Users\Jon\Documents\CDev\sandbox>atomics.exe
Got 1
Bottom line: even with these snippet results I see no build failures due to the current mingw32 build configuration.
Updated by drbrain (Eric Hodel) almost 12 years ago
- Subject changed from ruby cannot build on mingw32 due to missing __sync_val_compare_and_swap to ruby cannot build on mingw32 or FreeBSD 8 due to missing __sync_val_compare_and_swap
Updated by drbrain (Eric Hodel) almost 12 years ago
=begin
I'm also experiencing this on FreeBSD 8 with gcc 4.2.1:
$ gcc -v
Using built-in specs.
Target: i386-undermydesk-freebsd
Configured with: FreeBSD/i386 system compiler
Thread model: posix
gcc version 4.2.1 20070719 [FreeBSD]
$ make
linking miniruby
thread.o(.text+0x3f20): In function rb_threadptr_execute_interrupts': /data/home/drbrain/Work/svn/ruby/thread.c:1807: undefined reference to
__sync_val_compare_and_swap_4'
*** Error code 1
Stop in /data/home/drbrain/Work/svn/ruby.
So it seems to be an old GCC issue, not a mingw-specific issue.
Is ruby 2.0 abandoning gcc 4.2.x?
=end
Updated by kosaki (Motohiro KOSAKI) almost 12 years ago
Hi
Does following patch fix your issue?
diff --git a/configure.in b/configure.in
index c916cd5..4a34334 100644
--- a/configure.in
+++ b/configure.in
@@ -1534,7 +1534,7 @@ AS_CASE(["$target_os"],
[])
-AS_CASE(["$target_cpu-$target_os"], [[i[3-6]86-linux*]], [
+AS_CASE(["$target_cpu-$target_os"], [[i[3-6]86-*]], [
AC_CACHE_CHECK([for __sync_val_compare_and_swap], [rb_cv_gcc_co
AC_TRY_LINK([unsigned long atomic_var;],
[
Updated by drbrain (Eric Hodel) almost 12 years ago
This patch works, thanks!
Updated by kosaki (Motohiro KOSAKI) almost 12 years ago
- Status changed from Open to Assigned
- Assignee changed from nobu (Nobuyoshi Nakada) to drbrain (Eric Hodel)
@drbrain (Eric Hodel), could you please commit the patch instead of me? I have no test environment and I don't like commit w/o make test-all.
Updated by drbrain (Eric Hodel) almost 12 years ago
I have confirmed it fixes mingw32 as well, I will commit it after lunch. Thanks for the patch!
Updated by drbrain (Eric Hodel) almost 12 years ago
- Status changed from Assigned to Closed
- % Done changed from 0 to 100
This issue was solved with changeset r38386.
Eric, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.
- configure.in (HAVE_GCC_ATOMIC_BUILTINS): Set -march=i486 to enable
__sync_val_compare_and_swap. Patch by KOSAKI Motohiro.
[ruby-trunk - Bug #7485]
Updated by drbrain (Eric Hodel) almost 12 years ago
Please check my ChangeLog message for accuracy.
Updated by kosaki (Motohiro KOSAKI) almost 12 years ago
Please check my ChangeLog message for accuracy.
Looks correct. thank you!