Weak symbol aliases on OS X similar to those on Linux, or a closest equivalent? Weak symbol aliases on OS X similar to those on Linux, or a closest equivalent? c c

Weak symbol aliases on OS X similar to those on Linux, or a closest equivalent?


On OS X, calls made within the library are automatically direct calls and do not go through the dyld stub. The evidence to the fact is that if you want to be able to inject alternative functions to service a call, you'll need to use interposable to force indirect access to the symbols and force execution of the call through the dyld stubs. Otherwise, by default, local calls will be direct and will not incur the overhead of running through dyld.

Thus, your optimization on Linux is already the default behavior and the alias is not needed.

Still, if you want to do this just to make your platform compatible code simpler, you can still make the aliases. You just need to use "weak_import" or "weak" (if you want coalesced) as your attribute name.

extern typeof (_NAME) NAME __attribute(weak_import, alias("_NAME"));

Apple reference on Weak Linking: Marking Symbols for Weak Linking
Apple reference on Mach-O runtime binding : Scope and Treatment of Symbol Definitions