How libgmalloc work with two level namespaces?
Asked Answered
G

1

8

I want to write my own malloc/free functions with debug purposes, documentation says I have to use DYLD_FORCE_FLAT_NAMESPACE together with DYLD_INSERT_LIBRARIES. But at the same time libgmalloc article clearly states:

libgmalloc is available in /usr/lib/libgmalloc.dylib.  To use it, set this environment variable:
       set DYLD_INSERT_LIBRARIES to /usr/lib/libgmalloc.dylib
 Note:  it is no longer necessary to set DYLD_FORCE_FLAT_NAMESPACE.

The question is: how to remove the necessity in DYLD_FORCE_FLAT_NAMESPACE ? malloc from my own library is not used if I don't force the namespace flatness.

Germin answered 4/12, 2013 at 22:14 Comment(0)
L
12

You need to use dyld interposing. This consists of generating a special __interpose section in the __DATA segment of your dynamic library containing pairs of replacement / replaced function addresses. The private dyld-interposing.h header from the dyld source contains a handy macro to help with this, along with an example usage.

Limiting answered 21/12, 2013 at 8:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.