For an extremely light version of ASAN, I would like to intercept calls to malloc, free, calloc and others. I'm doing this because for my use-case, even ASAN is too slow.
My approach would be creating an LD_PRELOAD library which replaces e.g. malloc(), performs checks and then calls the 'real malloc'. To be able to call the 'real malloc', one would use dlsym to obtain a pointer to that function. For malloc, free and realloc that works fine.
But: calloc is a problem. That is because dlsym() uses calloc underneath. Now in theory I could just use the 'real malloc' with a memset, but I'm afraid that that would affect timing (by becoming considerably slower) too much - calloc does some clever things underneath.
So my question is: how can I replace calloc without causing an infinite loop with the first dlsym() I execute?