raindrops RubyGem user+dev discussion/patches/pulls/bugs/help
 help / Atom feed
* Compilation on Solaris/SmartOS
@ 2013-08-27 11:02 Jonathan del Strother
  2013-08-27 19:40 ` Eric Wong
  0 siblings, 1 reply; 5+ messages in thread
From: Jonathan del Strother @ 2013-08-27 11:02 UTC (permalink / raw)
  To: raindrops

Hi,
I was having trouble using Raindrops on our i386 SmartOS servers.  The gem
would compile fine, but bomb out at runtime :

ruby -rraindrops -e "Raindrops.new(1).incr(0)"
ld.so.1: ruby: fatal: relocation error: file
/..../gems/raindrops-0.10.0/lib/raindrops_ext.so: symbol
__sync_add_and_fetch_4: referenced symbol not found

I was able to fix this with march=native - I added something like this to
extconf.rb -

if CONFIG["arch"]=~/solaris/
  $CPPFLAGS += " -march=native"
end

I'm not familiar enough with building the atomic libs to say whether it's
definitely the correct fix, but it seems to work, and the ruby-atomic gem
needed something similar :
https://github.com/headius/ruby-atomic/blob/master/ext/extconf.rb.   Any
thoughts?


^ permalink raw reply	[flat|threaded] 5+ messages in thread

* Re: Compilation on Solaris/SmartOS
  2013-08-27 11:02 Compilation on Solaris/SmartOS Jonathan del Strother
@ 2013-08-27 19:40 ` Eric Wong
  2013-08-28  9:16   ` Jonathan del Strother
  0 siblings, 1 reply; 5+ messages in thread
From: Eric Wong @ 2013-08-27 19:40 UTC (permalink / raw)
  To: raindrops

Jonathan del Strother <maillist@steelskies.com> wrote:
> Hi,
> I was having trouble using Raindrops on our i386 SmartOS servers.  The gem
> would compile fine, but bomb out at runtime :
> 
> ruby -rraindrops -e "Raindrops.new(1).incr(0)"
> ld.so.1: ruby: fatal: relocation error: file
> /..../gems/raindrops-0.10.0/lib/raindrops_ext.so: symbol
> __sync_add_and_fetch_4: referenced symbol not found
> 
> I was able to fix this with march=native - I added something like this to
> extconf.rb -
> 
> if CONFIG["arch"]=~/solaris/
>   $CPPFLAGS += " -march=native"
> end

$CPPFLAGS is an odd choice, $CFLAGS is more correct from a pedantic
standpoint even though normal builds do both preprocessing and
compilation in the same invokation.

So perhaps the following (can you test?):

if CONFIG["arch"]=~/solaris/
  $CFLAGS += " -march=native"
end

> I'm not familiar enough with building the atomic libs to say whether it's
> definitely the correct fix, but it seems to work, and the ruby-atomic gem
> needed something similar :
> https://github.com/headius/ruby-atomic/blob/master/ext/extconf.rb.   Any
> thoughts?

How does Ruby 2.0.0 / trunk build?  That also uses __sync_* and I can't
find -march=native anywhere.


^ permalink raw reply	[flat|threaded] 5+ messages in thread

* Re: Compilation on Solaris/SmartOS
  2013-08-27 19:40 ` Eric Wong
@ 2013-08-28  9:16   ` Jonathan del Strother
  2013-08-28 10:13     ` Eric Wong
  0 siblings, 1 reply; 5+ messages in thread
From: Jonathan del Strother @ 2013-08-28  9:16 UTC (permalink / raw)
  To: raindrops

>  > I'm not familiar enough with building the atomic libs to say whether
> it's
> > definitely the correct fix, but it seems to work, and the ruby-atomic gem
> > needed something similar :
> > https://github.com/headius/ruby-atomic/blob/master/ext/extconf.rb.   Any
> > thoughts?
>
> How does Ruby 2.0.0 / trunk build?  That also uses __sync_* and I can't
> find -march=native anywhere.
>

Ruby 2 appears to build & run fine... I'm not sure what I'd need to execute
to ensure I run a __sync_* instruction, but messed around with threads &
mutexes without problems.


Interestingly, when I build raindrops with my regular ruby 1.9.3 install,
the generated makefile includes "ARCH_FLAG = -m32", but when I build
raindrops with ruby 2 / trunk, I get "ARCH_FLAGS = -march=i486".  When
built with that flag, Raindrops works fine.


^ permalink raw reply	[flat|threaded] 5+ messages in thread

* Re: Compilation on Solaris/SmartOS
  2013-08-28  9:16   ` Jonathan del Strother
@ 2013-08-28 10:13     ` Eric Wong
  2013-08-29  9:58       ` Jonathan del Strother
  0 siblings, 1 reply; 5+ messages in thread
From: Eric Wong @ 2013-08-28 10:13 UTC (permalink / raw)
  To: raindrops

Jonathan del Strother <maillist@steelskies.com> wrote:
> >  > I'm not familiar enough with building the atomic libs to say whether
> > it's
> > > definitely the correct fix, but it seems to work, and the ruby-atomic gem
> > > needed something similar :
> > > https://github.com/headius/ruby-atomic/blob/master/ext/extconf.rb.   Any
> > > thoughts?
> >
> > How does Ruby 2.0.0 / trunk build?  That also uses __sync_* and I can't
> > find -march=native anywhere.

Ah, it just used -march=i486 which is enough.  I missed your i386
mention in your first email, my mind just immediately associated
Solaris/SmartOS with SPARC :x

> Ruby 2 appears to build & run fine... I'm not sure what I'd need to execute
> to ensure I run a __sync_* instruction, but messed around with threads &
> mutexes without problems.

It's used pretty heavily (GC, signals, thread switches).  I haven't had
__sync_* fail me once it built.

> Interestingly, when I build raindrops with my regular ruby 1.9.3 install,
> the generated makefile includes "ARCH_FLAG = -m32", but when I build
> raindrops with ruby 2 / trunk, I get "ARCH_FLAGS = -march=i486".  When
> built with that flag, Raindrops works fine.

Ah, 2.0.0 adds -march=i486 in this way.  How about the following patch?
I just pushed it up to git://bogomips.org/raindrops.git

diff --git a/ext/raindrops/extconf.rb b/ext/raindrops/extconf.rb
index 447a90a..f012808 100644
--- a/ext/raindrops/extconf.rb
+++ b/ext/raindrops/extconf.rb
@@ -20,6 +20,7 @@ int main(int argc, char * const argv[]) {
         unsigned long i = 0;
         __sync_lock_test_and_set(&i, 0);
         __sync_lock_test_and_set(&i, 1);
+        __sync_bool_compare_and_swap(&i, 0, 1);
         __sync_add_and_fetch(&i, argc);
         __sync_sub_and_fetch(&i, argc);
         return 0;
@@ -30,7 +31,17 @@ SRC
     $defs.push(format("-DHAVE_GCC_ATOMIC_BUILTINS"))
     true
   else
-    false
+    # some compilers still target 386 by default, but we need at least 486
+    # to run atomic builtins.
+    prev_cflags = $CFLAGS
+    $CFLAGS += " -march=i486 "
+    if try_link(src)
+      $defs.push(format("-DHAVE_GCC_ATOMIC_BUILTINS"))
+      true
+    else
+      prev_cflags = $CFLAGS
+      false
+    end
   end
 end or have_header('atomic_ops.h') or abort <<-SRC
 

On a side note, I'm kind of curious about the reasoning for staying with
32-bit, though.  There's a lot more registers on x86_64

Ruby 1.9+ packs more short strings (up to 23 bytes vs 11 bytes on
32-bit), so you won't incur malloc/free for short strings.  With Ruby
2.0.0, you also get Flonum (avoids malloc for some Floats, like Fixnum
vs Bignum).


^ permalink raw reply	[flat|threaded] 5+ messages in thread

* Re: Compilation on Solaris/SmartOS
  2013-08-28 10:13     ` Eric Wong
@ 2013-08-29  9:58       ` Jonathan del Strother
  0 siblings, 0 replies; 5+ messages in thread
From: Jonathan del Strother @ 2013-08-29  9:58 UTC (permalink / raw)
  To: raindrops

>
> Ah, 2.0.0 adds -march=i486 in this way.  How about the following patch?
> I just pushed it up to git://bogomips.org/raindrops.git


Works great, thanks.



> On a side note, I'm kind of curious about the reasoning for staying with
> 32-bit, though.  There's a lot more registers on x86_64
>

It builds 32 bit by default, which I assumed was for a good reason.  We're
due to upgrade to Ruby 2 soon, I'll make sure we try out the 64 bit build.


^ permalink raw reply	[flat|threaded] 5+ messages in thread

end of thread, back to index

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-08-27 11:02 Compilation on Solaris/SmartOS Jonathan del Strother
2013-08-27 19:40 ` Eric Wong
2013-08-28  9:16   ` Jonathan del Strother
2013-08-28 10:13     ` Eric Wong
2013-08-29  9:58       ` Jonathan del Strother

raindrops RubyGem user+dev discussion/patches/pulls/bugs/help

Archives are clonable:
	git clone --mirror https://bogomips.org/raindrops-public
	git clone --mirror http://ou63pmih66umazou.onion/raindrops-public

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.lang.ruby.raindrops
	nntp://ou63pmih66umazou.onion/inbox.comp.lang.ruby.raindrops

 note: .onion URLs require Tor: https://www.torproject.org/
       or Tor2web: https://www.tor2web.org/

AGPL code for this site: git clone https://public-inbox.org/ public-inbox