As mentioned here, we can wrap a function using the -Wl,--wrap switch.
Consider the following program:
#include <stdio.h>
void __wrap_f()
{
puts("wrapped");
}
void f()
{
puts("original");
}
int main(void)
{
f();
}
The program was written to a.c and compiled as gcc -Wl,--wrap=f a.c. When I run the executable (using ./a.out), I get original as the output.
My expectation was that on invoking f(), the wrapped version would be called and the program would print wrapped. Please let me know what I am missing here.
GCC version: 9.1.0