I recently cross-compiled Google's gperftools
, which includes the TCmalloc drop-in malloc/free replacement library and figured I'd provide a download link here to save others the trouble. TCmalloc is a very high-performance thread-friendly heap allocator that can do lock-less allocations on some platforms, though I am not sure if that is the case under our MIPS/uClibc platform. It can also sometimes lower overall heap usage and fragmentation. Further benefits to using gperftools/tcmalloc are its profiling and debugging capabilities. GCW build tarball download link
Extract in the same folder in which your gcw0-toolchain/ subfolder resides.Basic usage:
Link against whichever of the tcmalloc implementations provided best suits your purposes. If linking against the standard tcmalloc lib, add the following to your final linkage command:
-Wl,-R -Wl,. -ltcmalloc
NOTE: -ltcmalloc in the linkage command above should come after
all your other libraries you are linking against, or else tcmalloc's debugger/profiler capabilities might not detect all the stuff it should. The -R stuff above will cause the GCW's dynamic loader to look for libraries located in the same folder your binary is placed in. This means, of course, that when copying your newly-built program over to the GCW, you must also include in the same folder a copy of the correct .so dynamic library. As an example, if linking against standard tcmalloc (-ltcmalloc), you would include a copy of gcw0-toolchain/usr/mipsel-gcw0-linux-uclibc/sysroot/usr/lib/libtcmalloc.so.4 next to your executable. You can also link against other versions of tcmalloc that gperftools provides, by replacing -ltcmalloc with -ltcmalloc_debug or -ltcmalloc_and_profiler, etc etc.
Add the following to your GCC/G++ compilation flags for maximum compatibility with gperftools:
-fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free Quick and dirty usage:
If you want, you can try using the LD_PRELOAD trick to force loading any library provided, which with tcmalloc should override any usage of malloc/free in your program if it was linked dynamically to libc. It's not as effective and not recommended by Google, so I won't talk more about it here.Building gperftools yourself:
This is tricky if you are using the 2014-08-20 OpenDingux GCW toolchain, because it will barf when building the profiling stuff, complaining about missing symbols in siginfo.h. You will need a newer patched version of siginfo.h
from uClibc's official repo I am providing until a newer GCW toolchain comes out. You'll need to install autoconf, automake, and libtool on your host system. In the gperftools dir, run ./autogen.sh which creates some files along with a configure script. The script requires you to have the GCW toolchain in your path, so add the following to your ~/.bash_profile file, creating it if doesn't exist:
Load a new shell or run the command 'source ~/.bash_profile' in your current shell so the path change takes effect. Next, run the configure command with following parameters, assuming your toolchain is in /opt/gcw0-toolchain/
./configure CC=/opt/gcw0-toolchain/usr/bin/mipsel-gcw0-linux-uclibc-gcc CFLAGS="-O2" CXX=/opt/gcw0-toolchain/usr/bin/mipsel-gcw0-linux-uclibc-g++ CXXFLAGS="-O2" CPP=/opt/gcw0-toolchain/usr/bin/mipsel-gcw0-linux-uclibc-cpp CXXCPP=/opt/gcw0-toolchain/usr/bin/mipsel-gcw0-linux-uclibc-cpp --exec-prefix="/opt/gcw0-toolchain/usr/mipsel-gcw0-linux-uclibc/sysroot/usr" --prefix="/opt/gcw0-toolchain/usr/mipsel-gcw0-linux-uclibc/sysroot/usr" --host=mipsel-gcw0-linux-uclibc
After that, run 'make', then 'make install'.