title: LD_PRELOAD malloc to shm_open
body: <p>I'm trying to intercept <code>malloc</code> call using <code>LD_PRELOAD</code>. I want to move all memory allocation to shared memory by changing <code>malloc</code> to <code>shm_open</code> followed by <code>mmap</code>. How can I do it?</p>
  
  <p>LD_PRELOAD of <code>malloc</code> works fine. I can intercept every <code>malloc</code> call. However, calling <code>shm_open</code> in intercepted <code>malloc</code> fails because <code>shm_open</code> requires linking of <code>librt</code> which links to <code>libdl</code> that <code>dlsym</code> 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 <code>malloc</code>. But <code>librt</code> cannot be linked dynamically.</p>