I'm trying to intercept malloc
call using LD_PRELOAD
. I want to move all memory allocation to shared memory by changing malloc
to shm_open
followed by mmap
. How can I do it?
LD_PRELOAD of malloc
works fine. I can intercept every malloc
call. However, calling shm_open
in intercepted malloc
fails because shm_open
requires linking of librt
which links to libdl
that dlsym
in LD_PRELOAD requires. There is a recursive interposition. I thought about creating a static library of wrapped shared memory allocation. Then call it from intercepted malloc
. But librt
cannot be linked dynamically.