I am attempting to wrap a glibc symbol with my own definition of that symbol. For functions that glibc exposes this has so far been as easy as defining a __wrap_function_name
in my source code and then adding Wl,--wrap=external_function_name
to the linker flags of my build system's linking steps. In practice this then would look something like:
extern "C" void __wrap_external_function_name(void) { my_internal function();}
However I have recently attempted the same on a variable that glibc exposes, in this case __signgam. I again defined the linker flags for its wrapper, but I am not sure how and if it is even possible to define the wrapper for a variable. I attempted __wrap__signgam = signgam
, but that had no effect. In fact the symbol table when exposed with objdump -T binary | grep signgam
had the following content, showing that even though the wrap function is defined, the original symbol remains untouched:
0000000000000000 DO *UND* 0000000000000000 GLIBC_2.23 __signgam0000000000000000 DO *UND* 0000000000000000 GLIBC_2.2.5 signgam0000000001509d24 g DO .bss 0000000000000004 Base __wrap___signgam
Is there a canonical way to wrap these dynamic objects?