2

I'd like to experiment with Google's tcmalloc on Linux... I have a huge project here, with hundreds of qmake generated Makefile's... I'd like to find a way to get gcc to globally link against tcmalloc (like it does with libc)... Is this possible? Or will I have to edit every Makefile?

(I'd prefer not to edit all the pro files as there are hundreds of them)

(Also, we've already tried the LD_PRELOAD method and it's not working quite right)...

dicroce
  • 45,396
  • 28
  • 101
  • 140
  • Can't you just edit qmake's .pro files? – liori Oct 22 '09 at 21:54
  • 1
    Can you give more info about LD_PRELOAD not working correctly? What exactly are you experiencing when you try to use LD_PRELOAD? – R Samuel Klatchko Oct 22 '09 at 22:04
  • 1
    Well, it looked like only part of the application was using tcmalloc... Vast swaths of it's allocs were NOT going to tcmalloc... I tried to use ltrace to verify this but ltrace crashed fairly quickly (BTW, ltrace showed only calls into qt, and tcmalloc also only generated a report showing qt code... however, a lot more things are calling malloc in this app)... – dicroce Oct 22 '09 at 22:06
  • http://stackoverflow.com/questions/1553435/tcmalloc-how-can-i-get-my-malloc-calls-overridden-when-compiling-statically – slf Oct 22 '09 at 22:07
  • -nostdlibs is interesting, but I would need some way to globally do this or else I'm back to editing hundreds of makefiles or .pro files... – dicroce Oct 22 '09 at 22:12

2 Answers2

4

How do your makefiles access the compiler (gcc/g++/cc/c++)?

If it's just by name (g++), and not by explicit path (/usr/bin/g++), you can simply create a replacement g++ in whatever directory you prefer, and prepend that directory to your path.

E.g.: Create a   ~/mytmpgccdir/g++   file:

#!/bin/tcsh -f
exec /usr/bin/g++ -Lfoo -lfoo $*:q

Adding whatever extras (-Lfoo -lfoo) you like, either before or after the other arguments ($*:q).

Then pre-pend it to your path and make normally.

#tcsh version
% set path = ( ~/mytmpgccdir/  $path:q )
% make clean
% make

p.s. If it is by explicit name, you may be able to override it on the command line. Something like:   make all GCC=~/mytmpgccdir/gcc

p.p.s If you do use LD_PRELOAD, you might want a script like this to setenv LD_PRELOAD before running your program. Otherwise it's easy to wind up LD_PRELOAD'ing on every command like /bin/ls, make, g++, etc.

Mr.Ree
  • 8,320
  • 27
  • 30
2

First, check the qmake documentation. There is an easy way to specify (in a .pro file) that a certain library should always be linked in.

Also, since you are just experimenting, simply use LD_PRELOAD - no recompilation necessary:

LD_PRELOAD="/usr/lib/foo/libtcmalloc.so" ./your_program

You do not have to have linked "your_program" against google's tcmalloc library.