M. Edward (Ed) Borasky
6/23/2007 6:50:00 PM
Alex Young wrote:
> M. Edward (Ed) Borasky wrote:
>> Andrew Thompson wrote:
>>> Alex Young wrote:
>>>> I get this:
>>>>
>>>> gcc -Os -fomit-frame-pointer -DRUBY_EXPORT -rdynamic
>>>> -Wl,-export-dynamic -L. main.o libruby-static.a -ldl -lcrypt
>>>> -lm -o
>>>> miniruby
>>>> ./lib/fileutils.rb:1206: [BUG] Segmentation fault
>>>> ruby 1.8.6 (2007-03-13) [i686-linux]
>>>>
>>>> make: *** [.rbconfig.time] Aborted
>>>>
>>>> when I use those options.
>>> I think ruby *really* doesn't like to be built with optimizations. I
>>> believe the garbage collector in particular has problems with it.
>>>
>>> Andrew
>>>
>>>
>>
>> This combination just compiled successfully on my Gentoo box:
>>
>>
>> znmeb@DreamGate ~/ruby-test/ruby-1.8.6-p36 $ set|grep CFLAGS
>> CFLAGS='-Os -march=athlon-tbird -fomit-frame-pointer'
>> znmeb@DreamGate ~/ruby-test/ruby-1.8.6-p36 $ gcc --version
>> gcc (GCC) 4.1.2 (Gentoo 4.1.2)
>> Copyright (C) 2006 Free Software Foundation, Inc.
>> This is free software; see the source for copying conditions. There
>> is NO
>> warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
>> PURPOSE.
>>
>> Ruby 1.8.6-p36, gcc 4.1.2 and CFLAGS='-Os -march=athlon-tbird
>> -fomit-frame-pointer'
>>
>> I doubt if the Athlon TBird piece is why mine worked and yours didn't.
>>
> Me too. Mine's an Ubuntu Dapper install on a P4, gcc version 4.0.3
> (Ubuntu 4.0.3-1ubuntu5).
>
> Out of interest, what executable size do you get with that, before and
> after stripping?
>
"-Os":
$ export CFLAGS='-Os -fomit-frame-pointer -march=athlon-tbird'
$ ./configure --enable-pthread # required on my system because I have a
threaded Tcl/Tk
$ make
...
$ ls -l ruby
-rwxr-xr-x 1 znmeb users 637415 Jun 23 11:03 ruby
$ size ruby
text data bss dec hex filename
542399 3048 63928 609375 94c5f ruby
$ strip ruby
$ ls -l ruby
-rwxr-xr-x 1 znmeb users 548636 Jun 23 11:08 ruby
$ size ruby
text data bss dec hex filename
542399 3048 63928 609375 94c5f ruby
"-O2":
$ make clean
$ export CFLAGS='-O2 -fomit-frame-pointer -march=athlon-tbird'
$ ./configure --enable-pthread
$ make
...
$ ls -l ruby
-rwxr-xr-x 1 znmeb users 778524 Jun 23 11:40 ruby
$ size ruby
text data bss dec hex filename
683954 3028 63928 750910 b753e ruby
$ strip ruby
$ ls -l ruby
-rwxr-xr-x 1 znmeb users 690172 Jun 23 11:41 ruby
$ size ruby
text data bss dec hex filename
683954 3028 63928 750910 b753e ruby
So it looks like -O2 is a good bit larger than -Os. What I don't know is
the speed penalty, or what yours will do if you substitute
"-march=pentium4" for my "-march=athlon-tbird". My recollection is that
one of the gimmicks that enables -Os to generate smaller code is
elimination of 4-byte and 8-byte alignment adjustments whenever
possible, which would be a severe performance hit on floating-point work
but probably not in a Ruby interpreter.
I don't plan to benchmark any of this, mostly because I'm interested in
the other extreme -- waste as much RAM as you need and try all the
compiler optimizations to make the inner interpreter as fast as
possible. :)