This is the mail archive of the binutils@sourceware.org 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]
Other format: [Raw text]

Re: "ld --wrapper" but without changing legacy executable, possible?


> //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


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