Monday, June 8, 2020

Apple Linker Magic & Swift Runtime

Milen Dzhumerov (tweet):

This article explores how apps link differently against the runtime depending on the deployment target.

[…]

How can you link against the same dylib, which has a single install name, but any linked binaries record different dylib install names?

[…]

ld64 sources are published by Apple, so we can see how the linker actually works. The code can be found in macho_dylib_file.cpp inside the method File<A>::addSymbol(). It defines the magic format as $ld$ <action> $ <condition> $ <symbol-name>.

Mark Rowe:

The various $ld$ magic symbols are used heavily by Apple’s system frameworks to maintain backwards compatibility while moving symbols between frameworks. If you look at the various .tbd files in the Xcode SDKs you’ll see all sorts of shenanigans along these lines.

Greg Parker:

Example: class NSObject moved from CoreFoundation to libobjc in macOS 10.8. libobjc has $ld$hide symbols for old OS versions (“NSObject is here, but it used to be somewhere else”). CF has $ld$add symbols for old OS versions (“NSObject is elsewhere, but it used to be here”).

Comments RSS · Twitter

Leave a Comment