This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: "ld --wrapper" but without changing legacy executable, possible?
- From: Paul Brook <paul at codesourcery dot com>
- To: binutils at sourceware dot org
- Cc: "sean yang" <seanatpurdue at hotmail dot com>
- Date: Tue, 21 Mar 2006 01:23:23 +0000
- Subject: Re: "ld --wrapper" but without changing legacy executable, possible?
- References: <BAY105-F177F96A75851590BA49C7CC0D80@phx.gbl>
> //runtimewrapper.c
> ? ? ?1 #define _GNU_SOURCE
> ? ? ? 2 #include <stdio.h>
> ? ? ? 3 #include <dlfcn.h>
> ? ? ? 4 void* malloc(int size) {
> ? ? ? 5 ? ? printf("wrapped malloc\n");
> ? ? ? 6 ? ? void* (*real_malloc)(const char*, const char*) =
> ? ? ? 7 ? ? dlsym(RTLD_NEXT, "malloc");
> ? ? ? 8 ? ? return real_malloc(size);
> ? ? ? 9 }
>...
> But the problem of above approach is that " void* (*real_malloc)(const
> char*, const char*) = dlsym(RTLD_NEXT, "malloc");" is called each time the
> application want to use malloc(), which is the major source of overhead.
Unless I'm missing something the answer is "Don't do that then". ie. only call
dlsym the first time the wrapper is run.
Paul