Forum: Ruby Looking for minimalist ruby.

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
soliton (Guest)
on 2007-06-22 10:27
(Received via mailing list)
Does any body know if there is ruby binary not greater than 1MB? It
would be
better if smaller, because it would be implemented in space constraint
application like embedded linux system. TIA
Alex Y. (Guest)
on 2007-06-22 10:45
(Received via mailing list)
soliton wrote:
> Does any body know if there is ruby binary not greater than 1MB? It
> would be
> better if smaller, because it would be implemented in space constraint
> application like embedded linux system. TIA
>
$ cd ruby-1.8.6/
$ ./configure
...
$ make
...
$ ls -lh ruby
-rwxr-xr-x 1 alex alex 1.6M 2007-06-22 07:43 ruby
$ strip ruby
$ ls -lh ruby
-rwxr-xr-x 1 alex alex 657K 2007-06-22 07:41 ruby

Mind you, that's without any extensions.
M. Edward (Ed) Borasky (Guest)
on 2007-06-22 18:13
(Received via mailing list)
Alex Y. wrote:
> ...
> $ ls -lh ruby
> -rwxr-xr-x 1 alex alex 1.6M 2007-06-22 07:43 ruby
> $ strip ruby
> $ ls -lh ruby
> -rwxr-xr-x 1 alex alex 657K 2007-06-22 07:41 ruby
>
> Mind you, that's without any extensions.
>

There's another trick you can try -- before the ./configure, type

export CFLAGS="-Os -fomit-frame-pointer"

This will optimize for space rather than speed and eliminate frame
pointers.
Alex Y. (Guest)
on 2007-06-22 19:26
(Received via mailing list)
M. Edward (Ed) Borasky wrote:
>> $ make
> There's another trick you can try -- before the ./configure, type
>
> export CFLAGS="-Os -fomit-frame-pointer"
>
> This will optimize for space rather than speed and eliminate frame pointers.
>
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.
Andrew T. (Guest)
on 2007-06-23 02:21
Alex Y. 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
Nobuyoshi N. (Guest)
on 2007-06-23 04:16
(Received via mailing list)
Hi,

At Sat, 23 Jun 2007 00:26:13 +0900,
Alex Y. wrote in [ruby-talk:256583]:
> 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]

--disable-frame-address configuration option is necessary to
use -fomit-frame-pointer.
M. Edward (Ed) Borasky (Guest)
on 2007-06-23 08:13
(Received via mailing list)
Andrew T. wrote:
>>
>> 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.
Alex Y. (Guest)
on 2007-06-23 14:03
(Received via mailing list)
M. Edward (Ed) Borasky wrote:
>>> make: *** [.rbconfig.time] Aborted
>
> -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?
Alex Y. (Guest)
on 2007-06-23 14:11
(Received via mailing list)
Nobuyoshi N. wrote:
> --disable-frame-address configuration option is necessary to
> use -fomit-frame-pointer.
>
It's not just that...

$ export CFLAGS="-Os -fomit-frame-pointer --disable-frame-address"
$ ./configure
checking build system type... i686-pc-linux-gnu
checking host system type... i686-pc-linux-gnu
checking target system type... i686-pc-linux-gnu
checking for gcc... gcc
checking for C compiler default output file name...
configure: error: C compiler cannot create executables
See `config.log' for more details.

config.log led me to try this:

$ gcc -Os -fomit-frame-pointer --disable-frame-address test.c
cc1: error: unrecognised command line option "-fdisable-frame-address"

Is it just my build of GCC (4.0.3)?
darren kirby (Guest)
on 2007-06-23 19:43
(Received via mailing list)
quoth the Alex Y.:
> checking target system type... i686-pc-linux-gnu
> Is it just my build of GCC (4.0.3)?
Shouldn't that be:

$ export CFLAGS="-Os -fomit-frame-pointer"
$ ./configure --disable-frame-address

?

-d
M. Edward (Ed) Borasky (Guest)
on 2007-06-23 21:58
(Received via mailing list)
Alex Y. wrote:
>>
> checking for gcc... gcc
>
1. As far as I know, you don't need "-fdisable-frame-address". Mine is
working fine without it.
2. gcc 4.0.3 "should" work, but most versions of gcc 4.0 had some things
b0rk3d and 4.1 is in much better shape. I'm awaiting word from Gentoo
Central on when and how to upgrade to gcc 4.2 -- since almost everything
in Gentoo is compiled from source, a compiler change is a very big deal
in some cases.
M. Edward (Ed) Borasky (Guest)
on 2007-06-23 22:51
(Received via mailing list)
Alex Y. wrote:
>>>> ruby 1.8.6 (2007-03-13) [i686-linux]
>>
>> warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
> 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. :)
This topic is locked and can not be replied to.