Segmentation Faults with Ruby 1.8.4 in Fink 10.4 tree with GCC 4

Posted by Marcus Crafter Thu, 23 Nov 2006 14:53:35 GMT

Last night I finally decided to move my Fink installation over from 10.4-transitional which is no longer updated (since August) to the official 10.4 tree.

Rather than attempt to bring all my pre-compiled software across with me I decided to rebuild everything again from source with the latest GCC compiler bundled with XCode, and besides, it was a cold night and I wanted to make sure my Powerbook kept warm.

The first thing I wanted to get built was Ruby, but interestingly after it was built and installed I started getting quite strange errors when attempting to install gems:

Marcus-Crafters-PowerBook-G4-17:~ crafterm$ sudo gem install rake
Successfully installed rake-0.7.1
Installing ri documentation for rake-0.7.1...
/sw/lib/ruby/1.8/irb/slex.rb:211: [BUG] Segmentation fault
ruby 1.8.4 (2005-12-24) [powerpc-darwin]

Abort trap
Marcus-Crafters-PowerBook-G4-17:~ crafterm$ sudo gem install rake
Successfully installed rake-0.7.1
Installing ri documentation for rake-0.7.1...
/sw/lib/ruby/1.8/rdoc/parsers/parse_rb.rb:377: [BUG] Segmentation fault
ruby 1.8.4 (2005-12-24) [powerpc-darwin]

Abort trap
Marcus-Crafters-PowerBook-G4-17:~ crafterm$

Googling around I saw that a few people have seen this before but I didn't see any hard and fast solution.

After my heartbeat settled down from the initial thought of having no up to date Ruby nor Rails environment installed on my notebook, I spoke with one of the C legends here in the office and he thought that it might be to do with the GCC optimiser, in particular the strict-aliasing between GCC 3 and GCC 4.

So, in the /sw/fink/dists/unstable/main/finkinfo/languages/ruby18.info file, I removed -Os from the CFLAGS directive:

  # Compile Phase.
  SetCPPFLAGS: -I%p/lib/system-openssl/include
- SetCFLAGS: -g -Os
+ SetCFLAGS: -g
  SetLDFLAGS: -L%p/lib/system-openssl/lib
  ConfigureParams: --program-suffix=1.8 --mandir='${prefix}/share/man' --enable-shared --with-default-kcode=none --with-dbm-type=gdbm_compat --with-bundled-md5 --with-bundled-rmd160 --with-bundled-sha1

and thankfully, everything start to work as expected again. I'm now a happy camper, but it looks like Ruby 1.8.4 has a few GCC 4.0ism's in it that need some ironing out. Time for Purify :)

Tags , ,  | 6 comments

Comments

  1. Avatar David N. Welton said about 9 hours later:

    Coming from the world of Tcl, Ruby has always seemed just a little less stable. I've managed to segfault it as well in the past. OTOH, it's open source, and certainly fixable when things do go wrong, so I'm not complaining.

  2. Avatar Mariano Kamp said about 11 hours later:

    Hmmh, never ran into that problem.

    I hoped that your approach would also work for my problem, but unfortunately it didn't.

    Anyway I learned that the optimization makes a huge difference performance wise.

    My benchmark is a program that is quite CPU intensive and it ran 4 seconds with -O2 and 6 seconds without any -O. Wow. 50% gain through -O2.

  3. Avatar Mariano Kamp said about 11 hours later:

    One more thing.

    You told me that your IRB is screwed.

    How did you compile that? Mine was broken too, but that was because I didn't include readline while configuring.

    Like this:

    ./configure --prefix=/usr/local --enable-pthread --with-readline-dir=/usr/local

  4. Avatar Marcus Crafter said 3 days later:

    Hi Mariano,

    Looks like the optimization does make a big difference - will also take a look at the issue you sent around too.

    It wasn't IRB that was screwed, but ri - it doesn't seem to work at all due to broken 'require' paths - but I haven't really used it in the past so it's a minor thing for me. IRB works fine now.

    Haven't done any performance testing or checking whether other optimization levels yield different results but will look into this during the week.

    Cheers,

    Marcus

  5. Avatar John Tangney said 2 months later:

    Marcus,

    I did the canonical fink install ruby and fink install rubygems-rb18. Then I tried the equally hackneyed sudo gem install rails and immediately got a Segmentation fault:

    /sw/lib/ruby/1.8/rubygems/remote_installer.rb:161: [BUG] Segmentation fault

    Various other Gems commands fail in other places with a seg fault.

    I saw this in the rails18.info file you mentioned:

    With gcc 4.0.0 build 5026 from XCode 2.1 Ruby will randomly core dump and with gcc 4.0.1 from XCode 2.2.1, Ruby will randomly have internal errors. Hence, gcc 3.3 is always used to compile Ruby.

    Mine is indeed that latest gcc 4.0.1.

    I went ahead and made your change to the .info file anyway and then did a fink rebuild ruby. I'm waiting to see what happens...

  6. Avatar Tones said 3 months later:

    I was having the same problem and this bugfix seems to have completely solved it. Thanks!!

Comments are disabled