Well I couldn't find very nice short phrase for my question title, but here is what I mean:
I have a library that interposes some syscalls like open(2).
I use this method for interposing. I add it to DYLD_INSERT_LIBRARIES in order to achieve my goal.
The library that contains the interposing code is a.dylib.
I need to link a library b.dylib to a.dylib because it contains some functions that a.dylib needs.
The issue is a.dylib interposes functions in b.dylib too which I don't want.
I am not an expert with linking. Is there any way to prevent this behaviour and what's the reason behind this happening?
UPDATE:
This is how b.dylib is built:
clang -dynamiclib -fPIC -Wextra -Wall -pedantic -Wl,-single_module <object files> -o b.dylib -install_name <path>
This is how a.dylib is built:
clang -dynamiclib -fPIC -Wextra -Wall -pedantic -Wl,-single_module <object files> -o a.dylib -install_name <path> b.dylib
Only a.dylib is added to the end of DYLD_INSERT_LIBRARIES.
You say
a.dylibdepends onb.dylibbutb.dylibdoes not depend ona.dyliband that you want no calls inb.dylibto ever be interposed. You gaveopenas an example of an interposed function.The example I gave was that
a.dylibneeds to callprocessFilethat is defined inb.dyliband it opens files. You don't want theopencall inb.dylibto be interposed ever (whethera.dylibis loaded or not).The only way I know to pull this off is for
processFileto dynamically load the C library instead of lettinglddo it automatically.There are two problems with this approach. The first is that each function that needs to call
openwill need one additionalifstatement to execute the code to resolve the symbol.The other is that you need to know ahead of time the filename of the C library to load. And if there's a problem resolving the symbol, then you have to deal with a situation that most programs don't have to deal with; at least at a later time.
The code will look something like this:
UPDATE
If you do not specify the full pathname to the C library,
dlopencould open an unexpected file.