This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Q: wrapper for malloc - possible?


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]