Q: wrapper for malloc - possible?

Jakub Jelinek jakub@redhat.com
Fri Aug 10 02:55:00 GMT 2001


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



More information about the Binutils mailing list