I create a .dylib file and compile it:
#define _GNU_SOURCE
#include
#include
static void* (*real_malloc)(size_t);
void *mal
If you can recompile the executable being hooked, then I think a simpler solution is to recompile the executable with -force_flat_namespace:
➜ clang slow_leak.c -force_flat_namespace -o slow_leak
➜ DYLD_INSERT_LIBRARIES=malloc_hook.dylib ./slow_leak
leaking
in hooked malloc
More info. This is on OSX 10.12.2 MacOS Sierra.
A comment on HN (2 years later) mentioned DYLD_FORCE_FLAT_NAMESPACE=1 can help in cases where it's not feasible to recompile. I haven't tried it yet, so YMMV.