# Ruby & gprof and thread.so undefined reference to rb\_thread

**URL:** <https://www.ruby-forum.com/t/ruby-gprof-and-thread-so-undefined-reference-to-rb-thread/90364>\
**Category:** Ruby\
**Created:** [March 28, 2007, 4:39am UTC](https://www.ruby-forum.com/t/ruby-gprof-and-thread-so-undefined-reference-to-rb-thread/90364 "2007-03-28T04:39:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![amin1426](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/4da419/32.png) [@amin1426](https://www.ruby-forum.com/u/amin1426)\
**Post date:** [March 28, 2007, 4:39am UTC](https://www.ruby-forum.com/t/ruby-gprof-and-thread-so-undefined-reference-to-rb-thread/90364/1 "2007-03-28T04:39:48Z")

</div>

So I was sitting there glaring at the screen whilst my script went off  
and did lots and lots…  
…and started to think wonder how I could make it a little faster…

After all, I have thrown every trick in the  
[http://www.rubygarden.org:3000/Ruby/page/show/RubyOptimization](http://www.rubygarden.org:3000/Ruby/page/show/RubyOptimization)  
book at the Ruby level (indeed I wrote a most of that)

Now I started to wonder if I could tweak Ruby itself to run a little  
faster…

So profile first…

CFLAGS=‘-p -pg -O2’ LDFLAGS=‘-p -pg’ ./configure  
–program-suffix=-profile  
make CFLAGS=‘-p -pg -O2’ LDFLAGS=‘-p -pg’  
su  
make install CFLAGS=‘-p -pg -O2’ LDFLAGS=‘-p -pg’

It seems to work and run for the basic stuff, lets hit the Big Script…

Oh dear!  
undefined reference to rb\_thread\_critical in thread.so

Oh, dear.

Here’s the shortest bit that triggers it…

irb-profile -rthread  
/usr/local/lib/ruby/1.8/i686-linux/thread.so:  
/usr/local/lib/ruby/1.8/i686-linux/thread.so: undefined symbol:  
rb\_thread\_critical - /usr/local/lib/ruby/1.8/i686-linux/thread.so  
(LoadError)  
from /usr/local/lib/ruby/1.8/thread.rb:5  
from /usr/local/lib/ruby/1.8/irb/init.rb:252:in  
`require' from /usr/local/lib/ruby/1.8/irb/init.rb:252:in `load\_modules’  
from /usr/local/lib/ruby/1.8/irb/init.rb:250:in `each' from /usr/local/lib/ruby/1.8/irb/init.rb:250:in `load\_modules’  
from /usr/local/lib/ruby/1.8/irb/init.rb:21:in `setup' from /usr/local/lib/ruby/1.8/irb.rb:54:in `start’  
from /usr/local/bin/irb-profile:13

Anyone with any guesses what to do?

John C. Phone : (64)(3) 358 6639  
Tait Electronics Fax : (64)(3) 359 4632  
PO Box 1645 Christchurch Email : removed\_email\_address@domain.invalid  
New Zealand

---

<div class="post-metadata">

**Author:** ![amin1426](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/4da419/32.png) [@amin1426](https://www.ruby-forum.com/u/amin1426)\
**Post date:** [March 28, 2007, 5:09am UTC](https://www.ruby-forum.com/t/ruby-gprof-and-thread-so-undefined-reference-to-rb-thread/90364/2 "2007-03-28T05:09:53Z")

</div>

John C. wrote:

> Oh dear!  
> (LoadError)  
> /usr/local/lib/ruby/1.8/irb/init.rb:21:in `setup’  
> New Zealand

1. Recompile without the -O2 and see if it goes away. “Normally”, when  
one compiles for profiling, one uses “-g -pg” which forces _no_  
optimization.
2. If the recompiled (and stock Ruby) work, it’s a GCC problem. If the  
recompiled doesn’t work and the stock Ruby does, check your  
configuration parameters on your profiling build.

Incidentally, I’ve done a few tests with a profiling Ruby and I’ve never  
hit anything like this, but nothing I’ve done goes anywhere near  
threading.

By the way, what version of GCC are you using? And are you building the  
non-profiling Ruby from source too?

–  
M. Edward (Ed) Borasky, FBG, AB, PTA, PGS, MS, MNLP, NST, ACMC(P)  
[http://borasky-research.blogspot.com/](http://borasky-research.blogspot.com/)

If God had meant for carrots to be eaten cooked, He would have given  
rabbits fire.

---

<div class="post-metadata">

**Author:** ![amin1426](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/4da419/32.png) [@amin1426](https://www.ruby-forum.com/u/amin1426)\
**Post date:** [March 28, 2007, 5:38am UTC](https://www.ruby-forum.com/t/ruby-gprof-and-thread-so-undefined-reference-to-rb-thread/90364/3 "2007-03-28T05:38:54Z")

</div>

Thanks for your suggestions, alas, it didn’t resolve the issue.

On Wed, 28 Mar 2007, M. Edward (Ed) Borasky wrote:

> 1. Recompile without the -O2 and see if it goes away.

Alas not.

> 1. If the recompiled (and stock Ruby) work, it’s a GCC problem. If the  
> recompiled doesn’t work and the stock Ruby does, check your configuration  
> parameters on your profiling build.

Compiling without -pg works fine. Compiling with -pg and  
–disable-shared fails.

> By the way, what version of GCC are you using?  
> gcc-4.1.2 ubuntu edgy eft

> And are you building the non-profiling Ruby from source too?  
> Yip, works fine.

> If God had meant for carrots to be eaten cooked, He would have given rabbits  
> fire.

He gave us fire so we can eat carrots in the form of cooked rabbits?

Thanks!

John C. Phone : (64)(3) 358 6639  
Tait Electronics Fax : (64)(3) 359 4632  
PO Box 1645 Christchurch Email : removed\_email\_address@domain.invalid  
New Zealand

---

<div class="post-metadata">

**Author:** ![amin1426](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/4da419/32.png) [@amin1426](https://www.ruby-forum.com/u/amin1426)\
**Post date:** [March 28, 2007, 6:35am UTC](https://www.ruby-forum.com/t/ruby-gprof-and-thread-so-undefined-reference-to-rb-thread/90364/4 "2007-03-28T06:35:59Z")

</div>

John C. wrote:

> > configuration parameters on your profiling build.
> 
> Compiling without -pg works fine. Compiling with -pg and  
> –disable-shared fails.  
> I’m not familiar with “disable-shared”, but I suspect it builds static  
> libraries instead of shared ones. I think you _want_ shared libraries.  
> But if “-pg” is the problem, it’s probably GCC. I’ve got 4.1.2 on my  
> (Gentoo) systems and I’ve never seen a problem like this with “-pg”. The  
> only issue I’ve had at all is that both Ruby and Tcl/Tk have to be built  
> either with threads or without threads – you can’t mix them.

This works on my box:

# build profiling Ruby

mkdir profiling-ruby-build  
cd profiling-ruby-build  
CFLAGS=‘-g -pg’ …/ruby/configure --disable-install-doc --enable-pthread  
–prefix=/home/test/profiling-ruby  
make; make install

> He gave us fire so we can eat carrots in the form of cooked rabbits?
> 
> Thanks!
> 
> John C. Phone : (64)(3) 358 6639  
> Tait Electronics Fax : (64)(3) 359 4632  
> PO Box 1645 Christchurch Email : removed\_email\_address@domain.invalid  
> New Zealand

–  
M. Edward (Ed) Borasky, FBG, AB, PTA, PGS, MS, MNLP, NST, ACMC(P)  
[http://borasky-research.blogspot.com/](http://borasky-research.blogspot.com/)

If God had meant for carrots to be eaten cooked, He would have given  
rabbits fire.
