My program uses several precompiled static libraries. I wrap malloc and free, but I want one of linked libraries to use 'real' malloc and free. As I run:
gcc [...] -W1, --wrap=malloc -W1, --wrap=free [used libraries]
all libraries would use wrapped functions.
Is partial linking a way here? What if I link this one library dynamically?
Thanks in advance, Jacek
You should be able to achieve this with some elf trickery on your binary static libraries.
Let's assume, that your library is called libbar.a. Then you can change all calls to malloc() to __real_malloc() with the help of objcopy:
objcopy libbar.a --redefine-sym malloc=__real_malloc --redefine-sym free=__real_free libbar2.a
Now, if you link the copied (modified) libbar2.a instead of libbar.a the original (not wrapped) malloc() and free() should be called.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With