Re: Replacing malloc et al in programs.

Jörg Sonnenberger <[email protected]> Fri, 14 Nov 2025 11:57:17 +0100
Newsgroups gmane.os.netbsd.devel.userlevel
Message-ID <[email protected]>
Hello Anders,
you need to replace the full API list including the fork hooks.

Joerg

On 11/14/25 9:48 AM, Anders Magnusson wrote:
> Hi,
> 
> I just ended up in debugging a program (on NetBSD 10.1/i386) that error 
> out in strange ways.
> 
> A simple way to get something predictable is to link it static (to avoid 
> different placement of dynamic libs) and to link with Electric Fence (to 
> get a quick-catch of malloc bugs).
> 
> But; it fails to link anymore.  Command line:
> % gcc -static -O -L/usr/pkg/lib main.o run.o locate.o -o ragge -lefence
> ld: /usr/lib/libc.a(jemalloc.o): in function `malloc':
> jemalloc.c:(.text+0x3a4c): multiple definition of `malloc'; /usr/pkg/ 
> lib/libefence.a(efence.o):/pbulk/work/devel/electric-fence/work/ 
> electric-fence-2.1.13/efence.c:825: first defined here
> ld: /usr/lib/libc.a(jemalloc.o): in function `calloc':
> jemalloc.c:(.text+0x4a88): multiple definition of `calloc'; /usr/pkg/ 
> lib/libefence.a(efence.o):/pbulk/work/devel/electric-fence/work/ 
> electric-fence-2.1.13/efence.c:842: first defined here
> ....
> 
> This suggests that either jemalloc has been too deeply integrated into 
> libc (so that it cannot even be changed) or that there is some bug in ld?
> How is replacement of the malloc routines supposed to be done these days?
> 
> -- R