How to ensure linker always uses two level namespaces?

We have two dynamic libraries (with different names) that bring in duplicate symbols. What we are seeing is, that when a dyld_stub is generated in the assembly code, the wrong dylibs implementation is called. Is there a way to prevent this (ie. some way to disable lazy symbol binding)?

Replies

By default, the linker generates binaries that use two level namespaces. The problem is that while the linker tool is running, there is one global namespace, and the linker uses the first implementation it finds (in the order of files on the command line). So if you have two libraries on the command line that both implement the same symbol, the linker will use the one from the library earlier on the command line.

If the command line order is not fine grain enough (for instance there are multiple duplicate symbols and you want some from one library and some from the other), then you will need to create fake dylibs (or .tbd) which just export the symbols you want to use from each dylib, then link with the fake dylibs.