Globally use Google malloc?

I would like to experiment with Google tcmalloc on Linux ... I have a huge project here where hundreds of qmakes were creating Makefiles ... I would like to find a way to get gcc to link globally to tcmalloc (as it does with libc) ... Is it possible this is? Or do I have to edit every Makefile?

(I would rather not edit all pro files as there are hundreds of them)

(Also, we've already tried the LD_PRELOAD method and it doesn't work correctly) ...

+2


source to share


2 answers


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

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

For example: Create ~ / mytmpgccdir / g ++ File:

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

      

Add any additional functions ( -Lfoo -lfoo ) you like before or after other arguments ( $ *: q ).



Then put it back on your path first and do fine.

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

      

ps If it's an explicit name, you can override it on the command line. Something like: do all GCC = ~ / mytmpgccdir / gcc

pps If you are using LD_PRELOAD you may need a script to set this LD_PRELOAD before running your program. Otherwise, it's easy to enable LD_PRELOAD for every command like / bin / ls, make, g ++, etc.

+4


source


Check the qmake documentation first. There is an easy way to indicate (in the .pro file) that a particular library should always be linked.

Also, since you're just experimenting, just use LD_PRELOAD - no recompilation required:



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

You don't need to link "your_program" with google's tcmalloc library.

+2


source







All Articles