{"id":29177,"date":"2020-06-08T15:40:05","date_gmt":"2020-06-08T19:40:05","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=29177"},"modified":"2020-06-08T15:40:05","modified_gmt":"2020-06-08T19:40:05","slug":"apple-linker-magic-swift-runtime","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2020\/06\/08\/apple-linker-magic-swift-runtime\/","title":{"rendered":"Apple Linker Magic &#038; Swift Runtime"},"content":{"rendered":"<p><a href=\"https:\/\/milen.me\/writings\/apple-link-magic-swift-runtime\/\">Milen Dzhumerov<\/a> (<a href=\"https:\/\/twitter.com\/milend\/status\/1226905393038811136\">tweet<\/a>):<\/p>\n<blockquote cite=\"https:\/\/milen.me\/writings\/apple-link-magic-swift-runtime\/\"><p>This article explores how apps link <em>differently<\/em> against the runtime depending on the deployment target.<\/p><p>[&#8230;]<\/p><p>How can you link against the <em>same<\/em> dylib, which has a single install name, but any linked binaries record <em>different<\/em> dylib install names?<\/p><p>[&#8230;]<\/p><p><code>ld64<\/code> sources are published by Apple, so we can see how the linker actually works. The code can be found in <a href=\"https:\/\/github.com\/apple-opensource\/ld64\/blob\/master\/src\/ld\/parsers\/macho_dylib_file.cpp#L534\">macho_dylib_file.cpp<\/a> inside the method <code>File&lt;A&gt;::addSymbol()<\/code>. It defines the magic format as <code>$ld$ &lt;action&gt; $ &lt;condition&gt; $ &lt;symbol-name&gt;<\/code>.\n<\/p><\/blockquote>\n\n<p><a href=\"https:\/\/twitter.com\/bdash\/status\/1227162045130276864\">Mark Rowe<\/a>:<\/p>\n<blockquote cite=\"https:\/\/twitter.com\/bdash\/status\/1227162045130276864\">\n<p>The various <code>$ld$<\/code> magic symbols are used heavily by Apple&rsquo;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&rsquo;ll see all sorts of shenanigans along these lines.<\/p>\n<\/blockquote>\n\n<p><a href=\"https:\/\/twitter.com\/gparker\/status\/1227203149691150336\">Greg Parker<\/a>:<\/p>\n<blockquote cite=\"https:\/\/twitter.com\/gparker\/status\/1227203149691150336\"><p>Example: class <code>NSObject<\/code> moved from CoreFoundation to libobjc in macOS 10.8. libobjc has <code>$ld$hide<\/code> symbols for old OS versions (&ldquo;<code>NSObject<\/code> is here, but it used to be somewhere else&rdquo;). CF has <code>$ld$add<\/code> symbols for old OS versions (&ldquo;<code>NSObject<\/code> is elsewhere, but it used to be here&rdquo;).<\/p><\/blockquote>","protected":false},"excerpt":{"rendered":"<p>Milen Dzhumerov (tweet): This article explores how apps link differently against the runtime depending on the deployment target.[&#8230;]How can you link against the same dylib, which has a single install name, but any linked binaries record different dylib install names?[&#8230;]ld64 sources are published by Apple, so we can see how the linker actually works. The [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"2020-06-08T19:40:09Z","apple_news_api_id":"109203e8-7045-4cbc-b005-c28aa7984d7a","apple_news_api_modified_at":"2020-06-08T19:40:09Z","apple_news_api_revision":"AAAAAAAAAAD\/\/\/\/\/\/\/\/\/\/w==","apple_news_api_share_url":"https:\/\/apple.news\/AEJID6HBFTLywBcKKp5hNeg","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[4],"tags":[255,205,31,1667,30,1666,71,901,943],"class_list":["post-29177","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-compiler","tag-dyld","tag-ios","tag-ios-13","tag-mac","tag-macos-10-15","tag-programming","tag-swift-programming-language","tag-swift-runtime"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/29177","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=29177"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/29177\/revisions"}],"predecessor-version":[{"id":29178,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/29177\/revisions\/29178"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=29177"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=29177"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=29177"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}