# Looking for minimalist ruby

**URL:** <https://www.ruby-forum.com/t/looking-for-minimalist-ruby/107494>\
**Category:** Ruby\
**Created:** [June 22, 2007, 8:27am UTC](https://www.ruby-forum.com/t/looking-for-minimalist-ruby/107494 "2007-06-22T08:27:34Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![soliton](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/cc9497/32.png) [@soliton](https://www.ruby-forum.com/u/soliton)\
**Post date:** [June 22, 2007, 8:27am UTC](https://www.ruby-forum.com/t/looking-for-minimalist-ruby/107494/1 "2007-06-22T08:27:34Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![soliton](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/cc9497/32.png) [@soliton](https://www.ruby-forum.com/u/soliton)\
**Post date:** [June 22, 2007, 8:45am UTC](https://www.ruby-forum.com/t/looking-for-minimalist-ruby/107494/2 "2007-06-22T08:45:36Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![soliton](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/cc9497/32.png) [@soliton](https://www.ruby-forum.com/u/soliton)\
**Post date:** [June 22, 2007, 4:13pm UTC](https://www.ruby-forum.com/t/looking-for-minimalist-ruby/107494/3 "2007-06-22T16:13:43Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![soliton](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/cc9497/32.png) [@soliton](https://www.ruby-forum.com/u/soliton)\
**Post date:** [June 22, 2007, 5:26pm UTC](https://www.ruby-forum.com/t/looking-for-minimalist-ruby/107494/4 "2007-06-22T17:26:49Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![soliton](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/cc9497/32.png) [@soliton](https://www.ruby-forum.com/u/soliton)\
**Post date:** [June 23, 2007, 2:16am UTC](https://www.ruby-forum.com/t/looking-for-minimalist-ruby/107494/5 "2007-06-23T02:16:54Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![soliton](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/cc9497/32.png) [@soliton](https://www.ruby-forum.com/u/soliton)\
**Post date:** [June 23, 2007, 6:13am UTC](https://www.ruby-forum.com/t/looking-for-minimalist-ruby/107494/6 "2007-06-23T06:13:12Z")

</div>

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 © 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.

---

<div class="post-metadata">

**Author:** ![soliton](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/cc9497/32.png) [@soliton](https://www.ruby-forum.com/u/soliton)\
**Post date:** [June 23, 2007, 12:21am UTC](https://www.ruby-forum.com/t/looking-for-minimalist-ruby/107494/7 "2007-06-23T00:21:48Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![soliton](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/cc9497/32.png) [@soliton](https://www.ruby-forum.com/u/soliton)\
**Post date:** [June 23, 2007, 12:11pm UTC](https://www.ruby-forum.com/t/looking-for-minimalist-ruby/107494/8 "2007-06-23T12:11:40Z")

</div>

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)?

---

<div class="post-metadata">

**Author:** ![soliton](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/cc9497/32.png) [@soliton](https://www.ruby-forum.com/u/soliton)\
**Post date:** [June 23, 2007, 5:43pm UTC](https://www.ruby-forum.com/t/looking-for-minimalist-ruby/107494/9 "2007-06-23T17:43:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![soliton](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/cc9497/32.png) [@soliton](https://www.ruby-forum.com/u/soliton)\
**Post date:** [June 23, 2007, 7:58pm UTC](https://www.ruby-forum.com/t/looking-for-minimalist-ruby/107494/10 "2007-06-23T19:58:21Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![soliton](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/cc9497/32.png) [@soliton](https://www.ruby-forum.com/u/soliton)\
**Post date:** [June 23, 2007, 8:51pm UTC](https://www.ruby-forum.com/t/looking-for-minimalist-ruby/107494/11 "2007-06-23T20:51:36Z")

</div>

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. 🙂

---

<div class="post-metadata">

**Author:** ![soliton](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/cc9497/32.png) [@soliton](https://www.ruby-forum.com/u/soliton)\
**Post date:** [June 23, 2007, 12:03pm UTC](https://www.ruby-forum.com/t/looking-for-minimalist-ruby/107494/12 "2007-06-23T12:03:38Z")

</div>

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?
