Re: Mixing libc with a DEBUG | PROF jemalloc

[email protected]
Newsgroups gmane.os.netbsd.devel.toolchain
Message-ID <ZGPDLHrd18f/[email protected]>
Le Tue, May 16, 2023 at 11:21:32AM +0200, [email protected] a écrit :
> 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?
> 

${JEMALLOC}/lib/Makefile.inc is included from src/lib/libc/Makefile.

And I have a 10 beta src tree while my userland is still 9.3; it
probably doesn't help either to mix a 9.3 libc with a 10 jemalloc.

So I will instead compile a debugging libc, from the correct branch, and
use this one with LD_PRELOAD instead of trying to use a mix of libc with
jemalloc embedded and another jemalloc library.

Note: It seems to be what is done under FreeBSD, with the use of
MALLOC_PRODUCTION macro to switch between a normal (production) version,
and a debugging one.
-- 
        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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.