Bug #7485

ruby cannot build on mingw32 or FreeBSD 8 due to missing __sync_val_compare_and_swap

Added by Eric Hodel over 1 year ago. Updated over 1 year ago.

[ruby-core:50424]
Status:Closed
Priority:Normal
Assignee:Eric Hodel
Category:build
Target version:2.0.0
ruby -v:trunk Backport:

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.

configure.in.mingw32_gcc_builtins.patch Magnifier (517 Bytes) Eric Hodel, 12/01/2012 07:38 AM


Related issues

Related to ruby-trunk - Feature #7427: Update Rubygems Closed 11/24/2012

Associated revisions

Revision 38386
Added by Eric Hodel over 1 year ago

  • configure.in (HAVEGCCATOMICBUILTINS): Set -march=i486 to enable _syncvalcompareandswap. Patch by KOSAKI Motohiro. [ruby-trunk - Bug #7485]

History

#1 Updated by Nobuyoshi Nakada over 1 year ago

_syncorandfetch wasn't available in Apple derivative gcc.

#2 Updated by Shyouhei Urabe over 1 year ago

@nobu Why do we have to bother old broken compiler?

#3 Updated by Motohiro KOSAKI over 1 year ago

I guess -march=i486 enable _syncvalcompareand_swap.

#4 Updated by Nobuyoshi Nakada over 1 year ago

Hmmm, if it can help, should add it by the default on mingw32?

#5 Updated by Luis Lavena over 1 year ago

Hello,

I just tested several native compilers on Windows 7 (without your patch) here are the results for those that define HAVEGCCATOMIC_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 HAVEGCCATOMIC_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 HAVEGCCATOMIC_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 HAVEGCCATOMIC_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 HAVEGCCATOMIC_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.

#6 Updated by Jon Forums over 1 year 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 gccatomic.c
C:\Users\Jon\AppData\Local\Temp\ccK9GPwk.o:gcc
atomic.c:(.text+0x2e): undefined reference
to `_syncvalcompareandswap4'
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 gccatomic.c
C:\Users\Jon\AppData\Local\Temp\ccpeH4Vt.o:gcc
atomic.c:(.text+0x2e): undefined reference
to `_syncvalcompareandswap4'
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.

#7 Updated by Eric Hodel over 1 year 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

#8 Updated by Eric Hodel over 1 year 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
_syncvalcompareandswap4'
*** 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

#9 Updated by Motohiro KOSAKI over 1 year 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 @@ ASCASE(["$targetos"],
[])

-ASCASE(["$targetcpu-$targetos"], [[i[3-6]86-linux*]], [
+AS
CASE(["$targetcpu-$targetos"], [[i[3-6]86-*]], [
ACCACHECHECK([for _syncvalcompareandswap], [rbcvgccco
ACTRYLINK([unsigned long atomic_var;],
[

#10 Updated by Eric Hodel over 1 year ago

This patch works, thanks!

#11 Updated by Motohiro KOSAKI over 1 year ago

  • Status changed from Open to Assigned
  • Assignee changed from Nobuyoshi Nakada to Eric Hodel

@drbrain, 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.

#12 Updated by Eric Hodel over 1 year ago

I have confirmed it fixes mingw32 as well, I will commit it after lunch. Thanks for the patch!

#13 Updated by Eric Hodel over 1 year 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 (HAVEGCCATOMICBUILTINS): Set -march=i486 to enable _syncvalcompareandswap. Patch by KOSAKI Motohiro. [ruby-trunk - Bug #7485]

#14 Updated by Eric Hodel over 1 year ago

Please check my ChangeLog message for accuracy.

#15 Updated by Motohiro KOSAKI over 1 year ago

Please check my ChangeLog message for accuracy.

Looks correct. thank you!

Also available in: Atom PDF