{"id":264,"date":"2021-10-07T13:29:55","date_gmt":"2021-10-07T11:29:55","guid":{"rendered":"https:\/\/threedots.ovh\/blog\/?p=264"},"modified":"2021-10-07T13:36:01","modified_gmt":"2021-10-07T11:36:01","slug":"what-is-the-minimum-number-of-libraries-to-run-a-hello-world-on-ios-simulator","status":"publish","type":"post","link":"https:\/\/threedots.ovh\/blog\/2021\/10\/what-is-the-minimum-number-of-libraries-to-run-a-hello-world-on-ios-simulator\/","title":{"rendered":"What is the minimum number of libraries to run a &#8220;hello world&#8221; on iOS Simulator?"},"content":{"rendered":"\n<p>For iOS simulators, dyld_sim is used as the dynamic linker. How small can the list of dependencies be to run a &#8220;hello world&#8221; in such an environment?<\/p>\n\n\n\n<p>When a binary that uses the simulator is loaded, dyld uses DYLD_ROOT_PATH to be able to locate usr\/lib\/dyld_sim, which is a build of dyld compiled for the iOS-sim platform target.<\/p>\n\n\n\n<p>We can note that file system namespaces are not used within the iOS Simulator, which shares the same file system view as the host instead of using a chroot.<\/p>\n\n\n\n<p>What happens if we do not specify the DYLD_ROOT_PATH variable for the dynamic linker to use the right search folder as a reference? Turns out, we get an error early.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>% cat hello.c\n#include &lt;stdio.h&gt;\n\nint main(int argc, char** argv) {\n\tputs(\"hello\");\n}\n% xcrun --sdk iphonesimulator clang hello.c -arch arm64 -o hellosim\n% .\/hellosim \ndyld&#91;2512]: DYLD_ROOT_PATH not set for simulator program\nzsh: abort      .\/hellosim<\/code><\/pre>\n\n\n\n<p>Let&#8217;s add the path and see what happens:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>% DYLD_ROOT_PATH=\/Users\/test\/devlab\/fakeroot .\/hellosim \nhello<\/code><\/pre>\n\n\n\n<p>And the minimal set of libraries that it took to get there:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>% find *\nusr\nusr\/lib\nusr\/lib\/libSystem.B.dylib\nusr\/lib\/system\nusr\/lib\/system\/libsystem_trace.dylib\nusr\/lib\/system\/libsystem_c.dylib\nusr\/lib\/system\/libcommonCrypto.dylib\nusr\/lib\/system\/libsystem_containermanager.dylib\nusr\/lib\/system\/libsystem_sim_platform_host.dylib\nusr\/lib\/system\/libxpc.dylib\nusr\/lib\/system\/libsystem_notify.dylib\nusr\/lib\/system\/libsystem_configuration.dylib\nusr\/lib\/system\/libsystem_malloc.dylib\nusr\/lib\/system\/libcorecrypto.dylib\nusr\/lib\/system\/libsystem_networkextension.dylib\nusr\/lib\/system\/libsystem_featureflags.dylib\nusr\/lib\/system\/libsystem_sim_platform.dylib\nusr\/lib\/system\/libsystem_sim_kernel.dylib\nusr\/lib\/system\/libsystem_coreservices.dylib\nusr\/lib\/system\/libcopyfile.dylib\nusr\/lib\/system\/libunwind.dylib\nusr\/lib\/system\/libdyld.dylib\nusr\/lib\/system\/libremovefile.dylib\nusr\/lib\/system\/libsystem_collections.dylib\nusr\/lib\/system\/libsystem_product_info_filter.dylib\nusr\/lib\/system\/libsystem_sim_kernel_host.dylib\nusr\/lib\/system\/libsystem_darwin.dylib\nusr\/lib\/system\/libsystem_sim_pthread_host.dylib\nusr\/lib\/system\/libsystem_sim_pthread.dylib\nusr\/lib\/system\/libcache.dylib\nusr\/lib\/system\/libmacho.dylib\nusr\/lib\/system\/libdispatch.dylib\nusr\/lib\/system\/libsystem_info.dylib\nusr\/lib\/system\/libsystem_sandbox.dylib\nusr\/lib\/system\/libsystem_blocks.dylib\nusr\/lib\/system\/libsystem_dnssd.dylib\nusr\/lib\/system\/libcompiler_rt.dylib\nusr\/lib\/system\/libsystem_m.dylib\nusr\/lib\/system\/libsystem_asl.dylib\nusr\/lib\/dyld_sim\nusr\/lib\/libobjc.A.dylib\nusr\/lib\/libc++.1.dylib\nusr\/lib\/libc++abi.dylib<\/code><\/pre>\n\n\n\n<p>&#8230; that&#8217;s 40 Mach-Os, one of which is dyld_sim itself.<\/p>\n\n\n\n<p>We can note the huge number of dynamic libraries used even for a &#8220;Hello world&#8221; sample program. Use of a high number of dynamic libraries is a characteristic of modern Apple operating systems.<\/p>\n\n\n\n<p>And unlike when trying to target the iOS platform, we can run outside of the sandbox in Full Security on that environment (which is however not very representative of a device).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>For iOS simulators, dyld_sim is used as the dynamic linker. How small can the list of dependencies be to run a &#8220;hello world&#8221; in such an environment? When a binary that uses the simulator is loaded, dyld uses DYLD_ROOT_PATH to be able to locate usr\/lib\/dyld_sim, which is a build of dyld compiled for the iOS-sim&hellip;&nbsp;<a href=\"https:\/\/threedots.ovh\/blog\/2021\/10\/what-is-the-minimum-number-of-libraries-to-run-a-hello-world-on-ios-simulator\/\" rel=\"bookmark\">Read More &raquo;<span class=\"screen-reader-text\">What is the minimum number of libraries to run a &#8220;hello world&#8221; on iOS Simulator?<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"neve_meta_sidebar":"","neve_meta_container":"","neve_meta_enable_content_width":"","neve_meta_content_width":0,"neve_meta_title_alignment":"","neve_meta_author_avatar":"","neve_post_elements_order":"","neve_meta_disable_header":"","neve_meta_disable_footer":"","neve_meta_disable_title":"","footnotes":""},"categories":[1],"tags":[],"class_list":["post-264","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/threedots.ovh\/blog\/wp-json\/wp\/v2\/posts\/264","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/threedots.ovh\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/threedots.ovh\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/threedots.ovh\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/threedots.ovh\/blog\/wp-json\/wp\/v2\/comments?post=264"}],"version-history":[{"count":2,"href":"https:\/\/threedots.ovh\/blog\/wp-json\/wp\/v2\/posts\/264\/revisions"}],"predecessor-version":[{"id":266,"href":"https:\/\/threedots.ovh\/blog\/wp-json\/wp\/v2\/posts\/264\/revisions\/266"}],"wp:attachment":[{"href":"https:\/\/threedots.ovh\/blog\/wp-json\/wp\/v2\/media?parent=264"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/threedots.ovh\/blog\/wp-json\/wp\/v2\/categories?post=264"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/threedots.ovh\/blog\/wp-json\/wp\/v2\/tags?post=264"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}