This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
Re: Q: wrapper for malloc - possible?
- To: Heiko Nardmann <h dot nardmann at secunet dot de>
- Subject: Re: Q: wrapper for malloc - possible?
- From: Jakub Jelinek <jakub at redhat dot com>
- Date: Fri, 10 Aug 2001 11:57:45 +0200
- Cc: binutils at sources dot redhat dot com
- References: <01081010051202.13582@snsrv053>
- Reply-To: Jakub Jelinek <jakub at redhat dot com>
On Fri, Aug 10, 2001 at 10:05:12AM +0200, Heiko Nardmann wrote:
> I want to trace calls to malloc using the LD_PRELOAD mechanism.
> Is this possible?
You don't have to dlopen libc, dlsym(RTLD_NEXT, "malloc")
is better (because you can chain things).
But even dlsym might use calloc() if the program is linked with -lpthread,
so if you're interposing calloc too and need threads,
you can either set some flag before dlsym and clear it afterwards and if
that flag is set, return NULL from calloc (this is what recent
libmemusage.so does, it will work with current glibc, but might break
later), or you need to have some private implementation of malloc (perhaps
just using mmap) which you'll use during dlsym in progress.
Jakub