tech-toolchain archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Mixing libc with a DEBUG | PROF jemalloc



Since jemalloc is used as the memory allocator, and since it has
profiling and debugging capacities, I wanted to use such a debug version
to trace memory allocation for programs.

The idea was to link the programs with the stub version of the library,
and then, when needed, to use LD_PRELOAD to load the debug version (I
have not read the RT dynamic linker src to see if LD_PRELOAD will load
whatever library and link with the symbols exported even if the library
is not declared in the executable; hence the link with the stub
version).

In src/external/bsd/jemalloc/lib, I have modified the options in
Makefile.inc (now unused since the bsd.mk includes the inc in the parent
directory only), simply adding some macro definitions and the path to
the libc header "extern.h" for jemalloc.c:


# in the .for loop
CPPFLAGS.${i}+=-I${JEMALLOC}/include -DJEMALLOC_PROTECT_NOSTD -DJEMALLOC_DEBUG -DJEMALLOC_PROF

# and for extern.h
CPPFLAGS.jemalloc.c+=-I${JEMALLOC}/../../../lib/libc/include

Then, adjusting the Makefile so that defining say a DEBUG_LIB, I can
include the Makefile.inc and then use its SRCS, it compiles. I can
indeed substitute the debugging version using
LD_PRELOAD, but then libc is using calling what is exported from the
jemalloc debugging version and it doesn't blend well at all.

Have someone already done something like this? Is a namemangling
required in order to make only the third party code use the debugging
version while letting the libc alone?

TIA for any tip.
-- 
        Thierry Laronde <tlaronde +AT+ polynum +dot+ com>
                     http://www.kergis.com/
                    http://kertex.kergis.com/
Key fingerprint = 0FF7 E906 FBAF FE95 FD89  250D 52B1 AE95 6006 F40C


Home | Main Index | Thread Index | Old Index