GCC: --wrap option
GNU linker provides an --wrap option which can help developer replace symbols easily.
In man ld:
1 | --wrap=symbol |
One of user scenario is when developer is trying to analyze heap usage with customized malloc and free(i.e. using memory pool):
1 | void * __wrap_malloc (size_t size) |
Then link with option --wrap,malloc --wrap,free --wrap,realloc --wrap,calloc. If user want to mix customized malloc and system malloc, they can call __real_malloc when they want to call the system malloc.