Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Equivalent of GCC ld's --wrap

Hi

I need to find an equivalent to using gcc ld's --wrap option, e.g. with gcc
if I call ld with -Wl,--wrap,malloc, calls to malloc will instead be directed to _wrapmalloc. If I want to call the original malloc I can explicitly call _realmalloc.

With cctools ld (aka Apple's ld), there is no --wrap option. I can get halfway by using the "-idefinition:indirect" option using mangled symbol names, so can happily redirect malloc/whatever to my own function. However, I'm stuggling to find a solution so that I can call the original function.

Anyone got any ideas?

thanks

twoohnine

iBook G3, Mac OS X (10.4.7), gcc 4.0.1, ld cctools-622.3.obj~2

Posted on Aug 28, 2006 6:58 AM

Reply
Question marked as Best reply

Posted on Aug 28, 2006 10:37 AM

Instead of messing with (essentially) aliasing one function to another, why not just write the function you want with the name already being used? That is, write a malloc() that does whatever wrapping, and write a _realmalloc() that is just a simple wrapper that calls the "real" malloc()? You can use dlsym() to access the malloc() function in a linked library instead of the one in the thing calling it (i.e., avoid infinite recursion).
2 replies
Question marked as Best reply

Aug 28, 2006 10:37 AM in response to twoohnine

Instead of messing with (essentially) aliasing one function to another, why not just write the function you want with the name already being used? That is, write a malloc() that does whatever wrapping, and write a _realmalloc() that is just a simple wrapper that calls the "real" malloc()? You can use dlsym() to access the malloc() function in a linked library instead of the one in the thing calling it (i.e., avoid infinite recursion).

Equivalent of GCC ld's --wrap

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.