├── APPLE_LICENSE ├── README.md ├── bin ├── expand.rb └── set-alt-dyld ├── configs ├── base.xcconfig ├── closured.xcconfig ├── dyld.xcconfig ├── libdyld.xcconfig ├── update_dyld_shared_cache.xcconfig └── update_dyld_sim_shared_cache.xcconfig ├── doc ├── ReleaseNotes.txt ├── man │ ├── man1 │ │ ├── closured.1 │ │ ├── dyld.1 │ │ ├── dyld_usage.1 │ │ └── update_dyld_shared_cache.1 │ └── man3 │ │ ├── dladdr.3 │ │ ├── dlclose.3 │ │ ├── dlerror.3 │ │ ├── dlopen.3 │ │ ├── dlopen_preflight.3 │ │ ├── dlsym.3 │ │ └── dyld.3 ├── rst │ ├── conf.py │ ├── dyld_usage.rst │ └── index.rst └── tracing │ ├── dyld.codes │ └── dyld.plist ├── dyld.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ │ └── IDEWorkspaceChecks.plist └── xcshareddata │ └── xcschemes │ ├── dsc_extractor.xcscheme │ ├── dyld_closure_util.xcscheme │ └── dyld_shared_cache_util.xcscheme ├── dyld3 ├── APIs.cpp ├── APIs.h ├── APIs_macOS.cpp ├── AllImages.cpp ├── AllImages.h ├── Array.h ├── BootArgs.cpp ├── BootArgs.h ├── Closure.cpp ├── Closure.h ├── ClosureBuilder.cpp ├── ClosureBuilder.h ├── ClosureFileSystem.h ├── ClosureFileSystemNull.cpp ├── ClosureFileSystemNull.h ├── ClosureFileSystemPhysical.cpp ├── ClosureFileSystemPhysical.h ├── ClosurePrinter.cpp ├── ClosurePrinter.h ├── ClosureWriter.cpp ├── ClosureWriter.h ├── CodeSigningTypes.h ├── Diagnostics.cpp ├── Diagnostics.h ├── JSON.h ├── JSONReader.h ├── JSONReader.mm ├── JSONWriter.h ├── Loading.cpp ├── Loading.h ├── Logging.cpp ├── Logging.h ├── MachOAnalyzer.cpp ├── MachOAnalyzer.h ├── MachOFile.cpp ├── MachOFile.h ├── MachOLoaded.cpp ├── MachOLoaded.h ├── Map.h ├── PathOverrides.cpp ├── PathOverrides.h ├── SharedCacheRuntime.cpp ├── SharedCacheRuntime.h ├── StartGlue.h ├── SupportedArchs.h ├── Tracing.cpp ├── Tracing.h ├── libdyldEntryVector.cpp ├── libdyldEntryVector.h └── shared-cache │ ├── AdjustDylibSegments.cpp │ ├── BuilderUtils.h │ ├── BuilderUtils.mm │ ├── CacheBuilder.cpp │ ├── CacheBuilder.h │ ├── DyldSharedCache.cpp │ ├── DyldSharedCache.h │ ├── FileAbstraction.hpp │ ├── FileUtils.cpp │ ├── FileUtils.h │ ├── MachOFileAbstraction.hpp │ ├── Manifest.h │ ├── Manifest.mm │ ├── ObjC1Abstraction.hpp │ ├── ObjC2Abstraction.hpp │ ├── OptimizerBranches.cpp │ ├── OptimizerLinkedit.cpp │ ├── OptimizerObjC.cpp │ ├── StringUtils.h │ ├── Trie.hpp │ ├── dyld_cache_format.h │ ├── dyld_closure_util.cpp │ ├── dyld_shared_cache_builder.mm │ ├── dyldinfo.cpp │ ├── make_ios_dyld_cache.cpp │ ├── mrm_shared_cache_builder.cpp │ ├── mrm_shared_cache_builder.h │ ├── multi_dyld_shared_cache_builder.mm │ ├── update_dyld_shared_cache.cpp │ ├── update_dyld_shared_cache_entitlements.plist │ └── update_dyld_sim_shared_cache.cpp ├── dyld_sim-entitlements.plist ├── include ├── dlfcn.h ├── mach-o │ ├── dyld-interposing.h │ ├── dyld.h │ ├── dyld_images.h │ ├── dyld_priv.h │ ├── dyld_process_info.h │ └── fixup-chains.h └── objc-shared-cache.h ├── interlinked-dylibs └── update_dyld_shared_cache_compat.cpp ├── launch-cache ├── Architectures.hpp ├── CacheFileAbstraction.hpp ├── CommonDigestSPI.h ├── FileAbstraction.hpp ├── MachOFileAbstraction.hpp ├── MachOTrie.hpp ├── dsc_extractor.cpp ├── dsc_extractor.h ├── dsc_iterator.cpp ├── dsc_iterator.h ├── dyld_cache_format.h └── dyld_shared_cache_util.cpp ├── src ├── ImageLoader.cpp ├── ImageLoader.h ├── ImageLoaderMachO.cpp ├── ImageLoaderMachO.h ├── ImageLoaderMachOClassic.cpp ├── ImageLoaderMachOClassic.h ├── ImageLoaderMachOCompressed.cpp ├── ImageLoaderMachOCompressed.h ├── ImageLoaderMegaDylib.cpp ├── ImageLoaderMegaDylib.h ├── dyld.exp ├── dyld.order ├── dyld2.cpp ├── dyld2.h ├── dyldAPIs.cpp ├── dyldAPIsInLibSystem.cpp ├── dyldExceptions.c ├── dyldInitialization.cpp ├── dyldLibSystemGlue.c ├── dyldLibSystemInterface.h ├── dyldLock.cpp ├── dyldLock.h ├── dyldNew.cpp ├── dyldStartup.s ├── dyldSyscallInterface.h ├── dyld_debugger.cpp ├── dyld_process_info.cpp ├── dyld_process_info_internal.h ├── dyld_process_info_notify.cpp ├── dyld_sim.exp ├── dyld_stub_binder.s ├── dyld_usage.cpp ├── glue.c ├── libdyld_data_symbols.dirty ├── libdyld_sim.exp ├── start_glue.s ├── stub_binding_helper.s ├── threadLocalHelpers.s └── threadLocalVariables.c ├── testing ├── README.txt ├── build_tests.py ├── get_task_allow_entitlement.plist ├── include │ ├── dyld_test.h │ └── test_support.h ├── nocr │ ├── execserver.defs │ ├── nocr.1 │ └── nocr.c ├── run_all_dyld_tests.py ├── task_for_pid_entitlement.plist └── test-cases │ ├── LC_DYLD_ENV-DYLD_LIBRARY_PATH.dtest │ ├── foo.c │ └── main.c │ ├── NSAddImage-basic.dtest │ ├── main.c │ └── zzz.c │ ├── NSAddImage-fail.dtest │ └── main.c │ ├── NSAddImage-loaded.dtest │ └── main.c │ ├── NSAddressOfSymbol-basic.dtest │ └── main.c │ ├── NSCreateObjectFileImageFromFile-basic.dtest │ ├── foo.c │ └── main.c │ ├── NSCreateObjectFileImageFromFile-stress.dtest │ ├── foo.c │ └── main.cpp │ ├── NSCreateObjectFileImageFromMemory-basic.dtest │ ├── foo.c │ └── main.c │ ├── NSLookupSymbolInImage-basic.dtest │ └── main.c │ ├── _dyld_for_each_objc_class-duplicates.dtest │ ├── linked1.m │ ├── linked2.m │ └── main.m │ ├── _dyld_for_each_objc_class-missing-weak-chained.dtest │ ├── lib1.m │ ├── lib2.m │ ├── main.mm │ └── missing.m │ ├── _dyld_for_each_objc_class-missing-weak.dtest │ ├── lib1.m │ ├── lib2.m │ ├── main.mm │ └── missing.m │ ├── _dyld_for_each_objc_class.dtest │ ├── linked1.m │ ├── linked2.m │ └── main.m │ ├── _dyld_for_each_objc_protocol.dtest │ ├── linked1.m │ ├── linked2.m │ └── main.m │ ├── _dyld_get_image_slide.dtest │ └── main.c │ ├── _dyld_get_objc_selector-chained.dtest │ └── main.m │ ├── _dyld_get_objc_selector-shared-cache.dtest │ └── main.c │ ├── _dyld_get_objc_selector.dtest │ └── main.m │ ├── _dyld_images_for_addresses.dtest │ ├── foo.c │ └── main.c │ ├── _dyld_is_memory_immutable-lock.dtest │ ├── foo.c │ └── main.c │ ├── _dyld_is_memory_immutable.dtest │ ├── bar.c │ ├── foo.c │ └── main.c │ ├── _dyld_register_for_bulk_image_loads.dtest │ ├── bar.c │ ├── baz.c │ ├── foo.c │ ├── main.cxx │ └── up.c │ ├── _dyld_register_for_image_loads.dtest │ ├── bar.c │ ├── baz.c │ ├── foo.c │ ├── main.cxx │ └── up.c │ ├── _dyld_register_func_for_add_image.dtest │ ├── foo.c │ └── main.cxx │ ├── _dyld_shared_cache_is_locally_built.dtest │ └── main.c │ ├── amfi-hardened-dlopen-leaf.dtest │ ├── main.c │ └── my.c │ ├── amfi-interpose.dtest │ ├── interposer.c │ └── main.c │ ├── bind-addend.dtest │ └── main.c │ ├── bind-rebase.dtest │ └── main.c │ ├── chained-fixups-many-binds.dtest │ ├── foo.c │ ├── foo.h │ ├── main.c │ └── uses.h │ ├── crt-vars-libSystem.dtest │ └── main.c │ ├── cwd-relative-load.dtest │ ├── foo.c │ └── main.c │ ├── dladdr-basic.dtest │ ├── main-no-syms.c │ └── main.c │ ├── dladdr-dylib.dtest │ ├── foo.c │ └── main.c │ ├── dlclose-static-terminator.dtest │ ├── foo.c │ └── main.c │ ├── dlopen-DYLD_LIBRARY_PATH.dtest │ ├── bar.c │ ├── foo.c │ └── main.c │ ├── dlopen-RTLD_LOCAL-coalesce.dtest │ ├── foo1.c │ ├── foo2.c │ ├── foo3.c │ └── main.c │ ├── dlopen-RTLD_LOCAL-hides.dtest │ ├── bar.c │ ├── foo.c │ └── main.c │ ├── dlopen-RTLD_NODELETE.dtest │ ├── bar.c │ ├── foo.c │ └── main.c │ ├── dlopen-RTLD_NOLOAD.dtest │ ├── foo.c │ ├── init-a.c │ ├── init-b.c │ ├── init-main.c │ └── main.c │ ├── dlopen-RTLD_NOW.dtest │ ├── bar.c │ ├── foo.c │ └── main.c │ ├── dlopen-atpath-restricted.dtest │ ├── bar.c │ ├── foo.c │ └── main.c │ ├── dlopen-bad-file.dtest │ ├── bad.txt │ └── main.c │ ├── dlopen-basic.dtest │ ├── foo.c │ └── main.c │ ├── dlopen-empty-data.dtest │ ├── foo.c │ └── main.c │ ├── dlopen-fail-cleanly.dtest │ ├── a.c │ ├── b.m │ ├── c.c │ └── main.c │ ├── dlopen-flat.dtest │ ├── bar.c │ ├── foo.c │ └── main.c │ ├── dlopen-framework-fallback.dtest │ └── main.c │ ├── dlopen-haswell.dtest │ ├── a.c │ └── main.c │ ├── dlopen-in-init.dtest │ ├── foo.c │ └── main.c │ ├── dlopen-in-init2.dtest │ ├── bar.c │ ├── baz.c │ ├── foo.c │ └── main.c │ ├── dlopen-in-init3.dtest │ ├── bar.c │ ├── baz.c │ ├── foo.c │ └── main.c │ ├── dlopen-indirect-groupNum.dtest │ ├── bar.c │ ├── baz.c │ ├── foo.c │ └── main.c │ ├── dlopen-intertwined.dtest │ ├── A.c │ ├── B.c │ ├── C.c │ ├── D.c │ ├── E.c │ ├── F.c │ ├── base.c │ └── main.c │ ├── dlopen-long-error-message.dtest │ └── main.c │ ├── dlopen-prebuilt-dlopen-closure.dtest │ └── main.c │ ├── dlopen-race.dtest │ ├── foo.c │ └── main.c │ ├── dlopen-realpath.dtest │ └── main.c │ ├── dlopen-recurse.dtest │ ├── bar.c │ ├── foo.c │ └── main.c │ ├── dlopen-rpath-from-dylib.dtest │ ├── bar.c │ ├── main.c │ └── test.c │ ├── dlopen-rpath-implicit.dtest │ ├── foo.c │ └── main.c │ ├── dlopen-rpath-prev-override.dtest │ ├── bad.c │ ├── dyn.c │ ├── foo.c │ ├── good.c │ └── main.c │ ├── dlopen-rpath-prev.dtest │ ├── foo.c │ ├── main.c │ ├── sub1.c │ └── sub2.c │ ├── dlopen-signing.dtest │ ├── dylib.c │ └── main.c │ ├── dlopen-symlink.dtest │ ├── foo.c │ └── main.c │ ├── dlsym-RTLD_DEFAULT.dtest │ ├── foo.c │ └── main.c │ ├── dlsym-RTLD_MAIN_ONLY.dtest │ ├── foo.c │ └── main.c │ ├── dlsym-RTLD_NEXT.dtest │ ├── foo.c │ └── main.c │ ├── dlsym-RTLD_SELF.dtest │ ├── foo.c │ └── main.c │ ├── dlsym-handle.dtest │ ├── bar.c │ ├── base.c │ ├── foo.c │ └── main.c │ ├── dlsym-in-interposed-malloc.dtest │ ├── interposer.c │ └── main.c │ ├── dlsym-re-export.dtest │ ├── foo.c │ ├── main.c │ ├── sub1.c │ └── sub2.c │ ├── dtrace.dtest │ ├── main.c │ └── main.d │ ├── dyld-insert-library-double.dtest │ ├── bar.c │ ├── foo.c │ └── main.cpp │ ├── dyld-insert-library-rpath.dtest │ ├── bar.c │ ├── baz.c │ ├── foo.c │ └── main.cpp │ ├── dyld_abort_payload.dtest │ ├── defSymbol.c │ ├── emptyMain.c │ ├── foo.c │ ├── main.c │ └── useSymbol.c │ ├── dyld_fork-locks.dest │ └── main.c │ ├── dyld_get_image_versions.dtest │ └── main.c │ ├── dyld_get_sdk_version.dtest │ ├── bad.txt │ └── main.c │ ├── dyld_has_inserted_or_interposing_libraries.dtest │ ├── foo.c │ ├── interposer.c │ └── main.c │ ├── dyld_image_path_containing_address.dtest │ └── main.c │ ├── dyld_need_closure.dtest │ ├── foo.c │ └── main.c │ ├── dyld_process_info.dtest │ ├── File │ ├── linksWithCF.c │ └── main.c │ ├── dyld_process_info_notify.dtest │ ├── foo.c │ ├── main.c │ └── target.c │ ├── dyld_process_info_unload.dtest │ ├── foo.c │ ├── main.c │ └── target.c │ ├── dyld_shared_cache_some_image_overridden.dtest │ ├── main.c │ ├── myzlib.c │ ├── reexported-myzlib.c │ └── reexporter.c │ ├── dyld_version_spis.dtest │ └── main.c │ ├── dylib-re-export-old-format.dtest │ ├── bar.c │ ├── foo.c │ └── main.c │ ├── dylib-re-export.dtest │ ├── bar.c │ ├── foo.c │ └── main.c │ ├── dylib-static-link.dtest │ ├── foo.c │ ├── missing.c │ └── present.c │ ├── dylib-static-weak-link.dtest │ ├── foo.c │ ├── missing.c │ └── present.c │ ├── env-DYLD_FALLBACK_FRAMEWORK_PATH.dtest │ ├── foo.c │ └── main.c │ ├── env-DYLD_FALLBACK_LIBRARY_PATH.dtest │ ├── foo.c │ └── main.c │ ├── env-DYLD_FORCE_PLATFORM.dtest │ └── main.c │ ├── env-DYLD_FRAMEWORK_PATH.dtest │ ├── foo.c │ └── main.c │ ├── env-DYLD_IMAGE_SUFFIX.dtest │ ├── bar.c │ ├── foo.c │ └── main.c │ ├── env-DYLD_LIBRARY_PATH-cache.dtest │ ├── main.c │ ├── myzlib.c │ ├── reexported-myzlib.c │ └── reexporter.c │ ├── env-DYLD_LIBRARY_PATH.dtest │ ├── foo.c │ └── main.c │ ├── env-DYLD_VERSIONED_FRAMEWORK_PATH.dtest │ ├── foo.c │ └── main.c │ ├── env-DYLD_VERSIONED_LIBRARY_PATH.dtest │ ├── foo.c │ └── main.c │ ├── flat-namespace-absolute-symbol.dtest │ ├── foo.s │ └── main.c │ ├── flat-namespace.dtest │ ├── foo.c │ └── main.c │ ├── image_infos-uuids.dtest │ ├── foo.c │ └── main.c │ ├── init-term-segments.dtest │ ├── foo.c │ └── main.c │ ├── interpose-malloc.dtest │ ├── foo.c │ ├── interposer.c │ └── main.c │ ├── interpose-resolver.dtest │ ├── foo.c │ ├── interposer.c │ └── main.c │ ├── interpose-then-dlopen.dtest │ ├── bar.c │ ├── foo.c │ ├── fooimpl.c │ ├── interposable.txt │ ├── interposer.c │ └── main.c │ ├── interpose-weak.dtest │ ├── foo.c │ ├── interposer.c │ └── main.c │ ├── launch-image-cache.dtest │ ├── foo1.c │ ├── foo10.c │ ├── foo11.c │ ├── foo12.c │ ├── foo13.c │ ├── foo14.c │ ├── foo15.c │ ├── foo16.c │ ├── foo17.c │ ├── foo18.c │ ├── foo19.c │ ├── foo2.c │ ├── foo20.c │ ├── foo21.c │ ├── foo22.c │ ├── foo23.c │ ├── foo24.c │ ├── foo25.c │ ├── foo26.c │ ├── foo27.c │ ├── foo28.c │ ├── foo29.c │ ├── foo3.c │ ├── foo30.c │ ├── foo31.c │ ├── foo32.c │ ├── foo4.c │ ├── foo5.c │ ├── foo6.c │ ├── foo7.c │ ├── foo8.c │ ├── foo9.c │ └── main.c │ ├── lazy-symbol-missing.dtest │ ├── foo.c │ ├── main-call.c │ ├── main.c │ └── runner.c │ ├── macOS-cache-rebuild.dtest │ └── main.c │ ├── missing-weak-def.dtest │ ├── bar-empty.c │ ├── bar.c │ └── main.c │ ├── no-shared-cache.dtest │ └── main.c │ ├── operator-new.dtest │ └── main.cxx │ ├── read-only-data.dtest │ ├── foo.c │ └── main.c │ ├── restrict-search.dtest │ ├── foo.c │ └── main.c │ ├── rpath-absolute.dtest │ ├── foo.c │ └── main.c │ ├── rpath-weak-missing.dtest │ ├── foo.c │ └── main.c │ ├── shared_cache_iterate.dtest │ └── main.c │ ├── shared_cache_optimized.dtest │ └── main.c │ ├── shared_cache_range.dtest │ └── main.c │ ├── static-terminators.dtest │ ├── base.c │ ├── foo.c │ └── main.c │ ├── symbol-resolver-basic.dtest │ ├── foo.c │ ├── foo2.c │ └── main.c │ ├── thread-local-atexit-macOS.dtest │ └── main.cpp │ ├── thread-local-atexit.dtest │ └── main.cpp │ ├── thread-local-cleanup.dtest │ ├── foo.c │ └── main.c │ ├── thread-local-destructors.dtest │ ├── foo.c │ └── main.cpp │ ├── thread-local-variables.dtest │ ├── foo.c │ └── main.c │ ├── unix-conformance.dtest │ └── main.c │ ├── weak-coalesce-inserted-dylibs.dtest │ ├── bar.cpp │ ├── foo.cpp │ └── main.cpp │ ├── weak-coalesce-unload.dtest │ ├── foo1.c │ ├── foo2.c │ ├── foo3.c │ └── main.c │ ├── weak-coalesce.dtest │ ├── Makefile │ ├── base.c │ ├── base.h │ ├── foo1.c │ ├── foo2.c │ ├── foo3.c │ └── main.c │ └── weak-dylib-re-export.dtest │ ├── bar.c │ ├── foo.c │ ├── main.c │ └── symbols.txt └── unit-tests ├── bin ├── build-results-filter.pl ├── exit-non-zero-pass.pl ├── exit-zero-pass.pl ├── fail-if-non-zero.pl ├── make-recursive.pl ├── pass-iff-exit-zero.pl └── result-filter.pl ├── build-and-run-iPhoneOS-unit-tests ├── build-iPhoneOS-unit-tests ├── include ├── common.makefile └── test.h ├── run-all-unit-tests └── test-cases ├── DYLD_LIBRARY_PATH-dyld_env ├── Makefile ├── foo.c └── main.c ├── NSAddImage-MATCH_BY_INSTALLNAME ├── Makefile ├── bar.c ├── foo.c └── main.c ├── NSAddImage-RETURN_ONLY_IF_LOADED ├── Makefile └── main.c ├── NSAddImage-leafname ├── Makefile ├── main.c └── zzz.c ├── NSAddressOfSymbol-NULL ├── Makefile └── main.c ├── absolute-symbol ├── Makefile ├── abs.s ├── foo.c └── main.c ├── addend ├── Makefile ├── foo.c └── main.c ├── all_image_infos-cache-slide ├── Makefile └── main.c ├── all_image_infos-duplicate ├── Makefile ├── foo.c └── main.c ├── all_image_infos-paths ├── Makefile ├── foo.c └── main.c ├── all_image_infos ├── Makefile ├── foo.c └── main.c ├── always-libSystem ├── Makefile └── main.c ├── big-jump-table ├── Makefile ├── foo.c ├── foo.h ├── funcs.c ├── main.c └── pointers.c ├── big-stack ├── Makefile └── main.c ├── branch-islands ├── Makefile ├── extra.c ├── main.c └── space.s ├── bundle-basic ├── Makefile ├── bundle.c └── main.c ├── bundle-dont-gc ├── Makefile ├── bar.c ├── foo.c └── main.c ├── bundle-memory-load-all-infos ├── Makefile ├── bundle.c └── main.c ├── bundle-memory-load-bad ├── Makefile ├── bundle.c └── main.c ├── bundle-memory-load-fat ├── Makefile ├── bundle.c └── main.c ├── bundle-memory-load-malloc ├── Makefile ├── bundle.c └── main.c ├── bundle-memory-load ├── Makefile ├── bundle.c └── main.c ├── bundle-multi-link ├── Makefile ├── bundle.c └── main.c ├── bundle-multi-load ├── Makefile ├── bundle.c └── main.c ├── bundle-name-ownership ├── Makefile ├── bundle.c └── main.c ├── bundle-private ├── Makefile ├── bundle.c └── main.c ├── bundle-reload ├── Makefile ├── bundle.cxx └── main.c ├── bundle-terminator ├── Makefile ├── bundle.cxx └── main.c ├── bundle-unlinkable ├── Makefile ├── bundle.c ├── lib.c └── main.c ├── bundle-unload-keep-mapped ├── Makefile ├── bundle.c └── main.c ├── bundle-v-dylib ├── Makefile ├── bar.c ├── foo.c └── main.c ├── bundle-weak ├── Makefile ├── bundle.cxx └── main.c ├── concurrent-dlopen-initializers ├── Makefile ├── foo.c └── main.c ├── coreSymbolication-notify ├── Makefile ├── bar.c ├── foo.c └── main.c ├── crt-apple ├── Makefile └── main.c ├── crt-argv-NULL ├── Makefile └── main.c ├── crt-custom ├── Makefile ├── main.c └── mystart.s ├── crt-libSystem ├── Makefile └── main.c ├── crt-result ├── Makefile ├── bad.c └── good.c ├── cxa_finalize ├── Makefile ├── foo.cxx └── main.c ├── deadlock ├── Makefile ├── bar.c ├── foo.c └── main.c ├── dladdr-stripped ├── Makefile └── main.c ├── dladdr ├── Makefile └── main.c ├── dlclose-basic ├── Makefile ├── foo.c └── main.c ├── dlclose-bundle-unload ├── Makefile ├── foo.c └── main.c ├── dlclose-dylib-dynamic-ref ├── Makefile ├── bar.c ├── baz.c ├── foo.c └── main.c ├── dlclose-dylib-ref-count ├── Makefile ├── bar.c ├── base.c ├── foo.c └── main.c ├── dlclose-dylib-terminators ├── Makefile ├── bar.cpp ├── baz.c ├── foo.cpp └── main.c ├── dlclose-dylib-unload ├── Makefile ├── bar.c ├── foo.c └── main.c ├── dlclose-order ├── Makefile ├── bar.cxx ├── base.c ├── base.h ├── baz.cxx ├── foo.c └── main.c ├── dlclose-terminator-dlclose ├── Makefile ├── bar.c ├── foo.c └── main.c ├── dlclose-unload-c++ ├── Makefile ├── bar.c ├── foo.c └── main.c ├── dlclose-unmap ├── Makefile ├── foo.c └── main.c ├── dlerror-clear ├── Makefile └── main.c ├── dlerror ├── Makefile └── main.c ├── dlopen-DYLD_FALLBACK_LIBRARY_PATH ├── Makefile ├── foo.c └── main.c ├── dlopen-DYLD_LIBRARY_PATH ├── Makefile ├── foo.c └── main.c ├── dlopen-LD_LIBRARY_PATH ├── Makefile ├── foo.c └── main.c ├── dlopen-NULL-RTLD_FIRST ├── Makefile ├── foo.c └── main.c ├── dlopen-RTLD_FIRST ├── Makefile ├── bar.c ├── base.c ├── foo.c └── main.c ├── dlopen-RTLD_GLOBAL ├── Makefile ├── bar.c ├── foo.c └── main.c ├── dlopen-RTLD_LOCAL-ignore ├── Makefile ├── bar.c ├── foo.c └── main.c ├── dlopen-RTLD_LOCAL-weak ├── Makefile ├── bar.c ├── foo.c └── main.c ├── dlopen-RTLD_LOCAL ├── Makefile ├── bar.c ├── foo.c └── main.c ├── dlopen-RTLD_NODELETE ├── Makefile ├── foo.c └── main.c ├── dlopen-RTLD_NOLOAD-fallback ├── Makefile ├── foo.c └── main.c ├── dlopen-RTLD_NOLOAD-in-initializer ├── Makefile ├── bar.c ├── base.c ├── baz.c ├── foo.c └── main.c ├── dlopen-RTLD_NOLOAD-symlink ├── Makefile ├── bar.c ├── foo.c └── main.c ├── dlopen-RTLD_NOLOAD ├── Makefile ├── foo.c └── main.c ├── dlopen-RTLD_NOW ├── Makefile ├── bundle.c ├── foo.c └── main.c ├── dlopen-basic ├── Makefile ├── foo.c └── main.c ├── dlopen-codesign-dynamic ├── Makefile ├── foo.c └── main.c ├── dlopen-codesign ├── Makefile ├── foo.c └── main.c ├── dlopen-dyld-locking ├── Makefile ├── bar.c ├── base.c ├── base.h ├── foo.c └── main.c ├── dlopen-error ├── Makefile ├── foo.c └── main.c ├── dlopen-executable ├── Makefile ├── foo.c └── main.c ├── dlopen-from-anonymous-code ├── Makefile ├── foo.c └── main.c ├── dlopen-in-initializer ├── Makefile ├── foo.c └── main.c ├── dlopen-init-dlopen-notify ├── Makefile ├── bar.c ├── foo.c ├── foo1.c ├── foo2.c └── main.cxx ├── dlopen-init-dlopen-up ├── Makefile ├── bar.c ├── foo.c └── main.c ├── dlopen-init-dlopen ├── Makefile ├── bar.c ├── foo.c └── main.c ├── dlopen-init-up ├── Makefile ├── bar.c ├── foo.c └── main.c ├── dlopen-initializer ├── Makefile ├── bar.c ├── foo.c └── main.c ├── dlopen-leak-threaded ├── Makefile └── main.c ├── dlopen-leak ├── Makefile ├── bar.c ├── foo.c └── main.c ├── dlopen-local-and-global ├── Makefile ├── bar.c ├── foo.c └── main.c ├── dlopen-multi ├── Makefile ├── foo.c └── main.c ├── dlopen-non-canonical-path ├── Makefile └── main.c ├── dlopen-notify-bind ├── Makefile ├── foo.c └── main.c ├── dlopen-sandbox ├── Makefile ├── base.sb ├── foo.c └── main.c ├── dlopen-search-leak ├── Makefile ├── foo.c └── main.c ├── dlopen-zero ├── Makefile └── main.c ├── dlopen_preflight-basic ├── Makefile ├── bar.c ├── foo.c └── main.c ├── dlopen_preflight-cycle ├── Makefile ├── bar.c ├── baz.c ├── foo.c └── main.c ├── dlopen_preflight-leak-image-deny-single ├── Makefile ├── foo.c └── main.c ├── dlopen_preflight-leak ├── Makefile ├── bar.c ├── foo.c └── main.c ├── dlsym-RTLD_DEFAULT ├── Makefile ├── foo.c └── main.c ├── dlsym-RTLD_MAIN_ONLY ├── Makefile ├── foo.c └── main.c ├── dlsym-RTLD_NEXT-missing ├── Makefile ├── foo1.c ├── foo2.c ├── foo3.c └── main.c ├── dlsym-RTLD_NEXT ├── Makefile ├── foo.c ├── main.c └── test.c ├── dlsym-RTLD_SELF ├── Makefile ├── foo.c ├── main.c └── test.c ├── dlsym-error ├── Makefile └── main.c ├── dlsym-indirect ├── Makefile ├── foo.c ├── foo1.c ├── foo2.c ├── foo3.c └── main.c ├── dtrace-static-probes ├── Makefile ├── foo.d └── main.c ├── dyld-func-lookup ├── Makefile ├── foo.c └── main.c ├── dyld-launched-prebound ├── Makefile └── main.c ├── dyld_is_memory_immutable ├── Makefile ├── bar.c ├── foo.c └── main.c ├── dyld_shared_cache_iterate_text ├── Makefile └── main.c ├── dynamic_cast-basic ├── Makefile ├── foo.cxx ├── foo.h ├── main.cxx └── realmain.cxx ├── env-DYLD_FALLBACK_LIBRARY_PATH ├── Makefile ├── compress.c └── main.c ├── executable-image-index ├── Makefile ├── foo.c └── main.c ├── fallback-non-unique-leaf-names ├── Makefile ├── bar.c ├── foo.c └── main.c ├── fallback-with-suid ├── Makefile ├── foo.c └── main.c ├── flat-data ├── Makefile ├── bar.c ├── getbar.c └── main.c ├── flat-insert ├── Makefile ├── foo.c └── main.c ├── flat-prebound ├── Makefile ├── bar.c ├── foo.c └── main.c ├── flat-private-extern ├── Makefile ├── bar.c ├── foo.c └── main.c ├── framework-DYLD_LIBRARY_PATH ├── Makefile ├── foo.c └── main.c ├── framework-fallback ├── Makefile └── main.c ├── ignore-bad-files ├── Makefile ├── foo.c └── main.c ├── image-count ├── Makefile ├── foo.c └── main.c ├── image-remove-crash ├── Makefile ├── foo.c └── main.c ├── image-remove-notification ├── Makefile ├── foo.c └── main.c ├── image-slide ├── Makefile ├── foo.c └── main.c ├── image-state-change ├── Makefile ├── bar.c ├── foo.c └── main.c ├── image-state-deny-OFI ├── Makefile ├── bar.c ├── foo.c └── main.c ├── image-state-deny-all_image_infos ├── Makefile ├── bar.c └── main.c ├── image-state-deny-cache-leak ├── Makefile ├── bar.c ├── foo.c └── main.c ├── image-state-deny-dlclose ├── Makefile ├── base.c ├── foo.c └── main.c ├── image-state-deny-leak ├── Makefile ├── bar.c ├── foo.c └── main.c ├── image-state-deny ├── Makefile ├── bar.c ├── foo.c └── main.c ├── image-state-dependents-initialized ├── Makefile ├── bar.c ├── foo.c └── main.c ├── image-suffix ├── Makefile ├── foo.c └── main.c ├── image_header_containing_address ├── Makefile ├── foo.c └── main.c ├── image_path_containing_address ├── Makefile ├── foo.c └── main.c ├── init-libSystem-first ├── Makefile ├── foo.c └── main.c ├── init-order ├── Makefile ├── base.c ├── base.h ├── foo1.c ├── foo2.c ├── foo3.c └── main.c ├── initializer-args ├── Makefile └── main.c ├── initializer-bounds-check ├── Makefile ├── bar.c ├── foo1.c ├── foo2.c └── main.c ├── insert-libraries-weak-symbols ├── Makefile ├── insert.c └── main.c ├── insert-libraries-with-initializer ├── Makefile ├── base.c ├── base.h ├── foo1.c ├── foo2.c ├── insert.c └── main.c ├── insert-libraries-with-suid ├── Makefile └── main.c ├── interpose-basic-prebound ├── Makefile ├── foo.c ├── main.c └── mystrdup.c ├── interpose-basic ├── Makefile ├── main.c ├── mystrdup.c └── wrap.c ├── interpose-chained ├── Makefile ├── foo.c ├── foo.h ├── foo1.c ├── foo2.c ├── foo3.c └── main.c ├── interpose-dlsym ├── Makefile ├── main.c └── myfree.c ├── interpose-dynamic-basic ├── Makefile └── main.c ├── interpose-dynamic-dlsym ├── Makefile ├── foo.c └── main.c ├── interpose-dynamic-lazy ├── Makefile ├── foo.c └── main.c ├── interpose-multiple ├── Makefile ├── base.c ├── base.h ├── foo1.c ├── foo2.c └── main.c ├── interpose-not-inserted ├── Makefile ├── main.c ├── mystrdup.c └── wrap.c ├── interpose-shared-cache ├── Makefile ├── main.c └── mymalloc.c ├── jump-table-dynamic-lookup ├── Makefile ├── foo.c ├── foo.h └── main.c ├── jump-table-race ├── Makefile ├── foo.c ├── foo.h └── main.c ├── lazy-binding-reg-params ├── Makefile ├── foo.c ├── foo.h └── main.c ├── lazy-dylib-init-order ├── Makefile ├── expected.out ├── foo.c └── main.c ├── lazy-dylib-missing-dylib ├── Makefile ├── foo.c └── main.c ├── lazy-dylib-missing-symbol ├── Makefile ├── foo.c └── main.c ├── lazy-pointer-binding ├── Makefile ├── foo.c └── main.c ├── lib-name-overload ├── Makefile ├── foo.c ├── foo2.c └── main.c ├── loader_path-dup ├── Makefile ├── bar.c ├── base.c ├── foo.c └── main.c ├── loader_path-symlink ├── Makefile ├── bar.c ├── foo.c └── main.c ├── loader_path ├── Makefile ├── bar.c ├── foo.c └── main.c ├── missing-symlink-framework-fallback-path ├── Foo.c ├── Makefile └── main.c ├── non-lazy-slide ├── Makefile ├── bar.c ├── foo.c └── main.c ├── non-lazy-weak ├── Makefile ├── bar.c ├── foo.c └── main.c ├── non-weak-library ├── Makefile ├── foo.c └── main.c ├── operator-new-dylib ├── Makefile ├── foo.cxx └── main.cxx ├── operator-new ├── Makefile └── main.cxx ├── partial-library-load ├── Makefile ├── bar.c ├── bundle.c ├── foo.c └── main.c ├── pie-basic ├── Makefile └── main.c ├── pie-big ├── Makefile └── main.c ├── pie-custom-stack ├── Makefile └── main.c ├── pie-dylib ├── Makefile ├── foo.c └── main.c ├── pie-text-reloc ├── Makefile └── main.c ├── prebased-performance ├── Makefile ├── foo.c └── main.c ├── progname ├── Makefile └── main.c ├── pthread-keys ├── Makefile └── main.c ├── re-export-dylib ├── Makefile ├── bar.c ├── foo.c └── main.c ├── re-export-framework ├── Makefile ├── bar.c ├── foo.c └── main.c ├── re-export-sub-framework ├── Makefile ├── bar.c ├── foo.c └── main.c ├── re-export-symbol-dylib ├── Makefile ├── bar.c ├── baz.c ├── baz.exp ├── foo.c ├── foo.exp ├── frob.c └── main.c ├── re-export-symbol ├── Makefile ├── bar.c ├── foo.c ├── foo.exp ├── foo2.exp ├── main1.c └── main2.c ├── read-only-import-shared-cache-coalesce ├── Makefile ├── foo.cxx └── main.c ├── read-only-import-shared-cache-dlopen-override ├── Makefile ├── main.c └── mymalloc.c ├── read-only-stubs ├── Makefile ├── bar.c ├── foo.c └── main.c ├── restrict-environ ├── Makefile └── main.c ├── restrict-executable_path ├── Makefile ├── foo.c └── main.c ├── rpath-DYLD_FALLBACK_LIBRARY_PATH ├── Makefile ├── foo.c └── main.c ├── rpath-DYLD_LIBRARY_PATH ├── Makefile ├── foo.c └── main.c ├── rpath-DYLD_ROOT_PATH ├── Makefile ├── foo.c └── main.c ├── rpath-LD_LIBRARY_PATH ├── Makefile ├── foo.c └── main.c ├── rpath-basic ├── Makefile ├── bar.c ├── foo.c └── main.c ├── rpath-dlopen-in-dylib ├── Makefile ├── bar.c ├── foo.c └── main.c ├── rpath-dlopen-indirect ├── Makefile ├── bar.c ├── foo.c └── main.c ├── rpath-dlopen-leak ├── Makefile ├── foo.c └── main.c ├── rpath-dlopen-rm-executable ├── Makefile ├── foo.c └── main.c ├── rpath-dlopen ├── Makefile ├── foo.c └── main.c ├── rpath-executable_path ├── Makefile ├── bar.c ├── foo.c └── main.c ├── rpath-indirect-suid ├── Makefile ├── bar.c ├── foo.c └── main.c ├── rpath-install-name ├── Makefile ├── bar.c ├── main.c └── stuff.c ├── rpath-introspection ├── Makefile ├── foo.c └── main.c ├── rpath-loader_path-dlopen ├── Makefile ├── bar.c ├── baz.c ├── foo.c └── main.c ├── rpath-loader_path ├── Makefile ├── foo.c └── main.c ├── rpath-nesting ├── Makefile ├── bar.c ├── baz.c ├── foo.c └── main.c ├── rpath-no-trailing-slash ├── Makefile ├── foo.c └── main.c ├── shared-cache-symlink ├── Makefile └── main.c ├── shared-region-overlap ├── Makefile └── main.c ├── suid-environ ├── Makefile └── main.c ├── suid-executable_path ├── Makefile ├── foo.c └── main.c ├── sym-link-load ├── Makefile ├── base.c ├── base.h ├── link.c ├── main.c └── test.c ├── symbol-resolver-basic ├── Makefile ├── foo.c ├── foo2.c └── main.c ├── symbol-resolver-interposed ├── Makefile ├── foo.c ├── foo.h ├── main.c └── myfoo.c ├── symbol-resolver-lazy-prebound ├── Makefile ├── bar.c ├── bar.o ├── foo.c └── main.c ├── symbol-resolver-pointer ├── Makefile ├── foo.c └── main.c ├── template ├── Makefile └── main.c ├── terminator-bounds-check ├── Makefile └── main.c ├── text-perm-alt-segment ├── Makefile ├── foo.c └── main.c ├── text-relocs-perms ├── Makefile ├── foo.c └── main.c ├── text-relocs ├── Makefile ├── bar.c ├── bind.c ├── main.c └── space.s ├── threaded-flat-lookup ├── Makefile ├── client.c ├── foo.c └── main.c ├── threaded-lazy-bind ├── Makefile ├── foo.c ├── gen.c └── main.c ├── tlv-basic ├── Makefile └── main.c ├── tlv-dylib ├── Makefile ├── foo.c └── main.c ├── tlv-initializer ├── Makefile ├── get.s └── main.c ├── tlv-terminators ├── Makefile ├── init.s └── main.c ├── trie-symbol-overrun ├── Makefile ├── foo.c └── main.c ├── unloadable-library-residue ├── Makefile ├── bar.c ├── foo.c └── main.c ├── upward-dylib-init-order ├── Makefile ├── b.c ├── c.c ├── common.c ├── common.h ├── main.c ├── u.c └── u2.c ├── upward-dylib ├── Makefile ├── down.c ├── down.h ├── main.c ├── main2.c ├── up.c └── up.h ├── weak-coalesce-c++ ├── Makefile ├── a.h ├── a1.cc ├── a2.cc └── main.cc ├── weak-coalesce-inserted ├── Makefile ├── base.c ├── base.h ├── foo1.c ├── foo2.c └── main.c ├── weak-coalesce-stubs ├── Makefile ├── bar.c ├── foo.c └── main.c ├── weak-coalesce ├── Makefile ├── base.c ├── base.h ├── foo1.c ├── foo2.c ├── foo3.c └── main.c ├── weak-external-reloc-flat ├── Makefile ├── bar.c ├── baz.c ├── foo.c └── main.c ├── weak-external-reloc ├── Makefile ├── bar.c ├── baz.c ├── foo.c ├── main.c └── realmain.c ├── weak-in-dylib ├── Makefile ├── foo.c └── main.c ├── weak-lazy-slidable ├── Makefile ├── bar.c ├── bar3.c ├── foo.c ├── main.c └── other.c ├── weak-library ├── Makefile ├── foo.c ├── foo.h └── main.c ├── weak-non-lazy ├── Makefile ├── bar.c ├── baz.c ├── foo.c ├── main.c └── realmain.c ├── weak-override ├── Makefile ├── foo.c └── main.c ├── weak-symbol-flat ├── Makefile ├── foo.c ├── foo.h └── main.c ├── weak-symbol ├── Makefile ├── foo.c ├── foo.h └── main.c ├── weak_import ├── Makefile ├── foo.c ├── foo.h └── main.c ├── zero-fill-segment ├── Makefile ├── foo.c ├── main.c └── zero.s └── zero-length-segment ├── Makefile ├── foo.c └── main.c /README.md: -------------------------------------------------------------------------------- 1 | Modifications to Apple's dyld project to fix Objective-C information when extracting dyld_shared_cache from macOS Big Sur to help Hopper generate readable pseudocode. 2 | 3 | Note: macOS Big Sur beta 9 changed the format of dyld_shared_cache. Currently this project only supports beta 1-8. 4 | 5 | ### Usage 6 | 7 | 1. Build `dyld_shared_cache_util` sheme, which will also build its dependency `dsc_extractor`. `dyld_shared_cache_util` is modified to look for `dsc_extractor` in the same directory. 8 | 2. `./dyld_shared_cache_util -extract ~/Developer/macOS\ Big\ Sur /System/Library/dyld/dyld_shared_cache_x86_64`. 9 | 3. Decompile the extracted libraries with Hopper. 10 | -------------------------------------------------------------------------------- /bin/set-alt-dyld: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl -w 2 | 3 | use strict; 4 | undef $/; 5 | 6 | if(@ARGV == 0) 7 | { 8 | print "Usage: $0 [ ...]\n"; 9 | exit 1; 10 | } 11 | 12 | my $arg; 13 | foreach $arg (@ARGV) 14 | { 15 | open IN, "<$arg" or die $!; 16 | my $in = ; 17 | close IN or die $!; 18 | 19 | if($in =~ s{/usr/lib/dyld}{/usr/local/dy}) 20 | { 21 | open OUT, ">$arg" or die $!; 22 | print OUT $in; 23 | close OUT or die $!; 24 | } 25 | else 26 | { 27 | print STDERR "ERROR: $arg\n"; 28 | exit 1; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /configs/base.xcconfig: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/antons/dyld-shared-cache-big-sur/abdd035bdfda33998cc80cd06b625cd99563ca33/configs/base.xcconfig -------------------------------------------------------------------------------- /configs/closured.xcconfig: -------------------------------------------------------------------------------- 1 | 2 | CODE_SIGN_ENTITLEMENTS[sdk=embedded*] = dyld3/closured/closured_entitlements.plist 3 | -------------------------------------------------------------------------------- /configs/dyld.xcconfig: -------------------------------------------------------------------------------- 1 | ALIGNMENT[arch=armv7s] = -Wl,-segalign,0x4000 2 | 3 | ENTRY[sdk=*simulator*] = -Wl,-e,_start_sim 4 | ENTRY[sdk=iphoneos*] = -Wl,-e,__dyld_start 5 | ENTRY[sdk=macosx*] = -Wl,-e,__dyld_start 6 | 7 | OTHER_CODE_SIGN_FLAGS[sdk=*simulator*] = --entitlements $(SRCROOT)/dyld_sim-entitlements.plist 8 | OTHER_CODE_SIGN_FLAGS[sdk=iphoneos*] = 9 | OTHER_CODE_SIGN_FLAGS[sdk=macosx*] = 10 | 11 | 12 | EXPORTED_SYMBOLS_FILE[sdk=*simulator*] = $(SRCROOT)/src/dyld_sim.exp 13 | EXPORTED_SYMBOLS_FILE[sdk=iphoneos*] = $(SRCROOT)/src/dyld.exp 14 | EXPORTED_SYMBOLS_FILE[sdk=macosx*] = $(SRCROOT)/src/dyld.exp 15 | 16 | PRODUCT_NAME[sdk=*simulator*] = dyld_sim 17 | PRODUCT_NAME[sdk=iphoneos*] = dyld 18 | PRODUCT_NAME[sdk=macosx*] = dyld 19 | 20 | INSTALL_PATH = /usr/lib 21 | 22 | //:configuration = Debug 23 | GCC_PREPROCESSOR_DEFINITIONS = DYLD_VERSION=$(RC_ProjectSourceVersion) BUILDING_DYLD=1 DEBUG=1 24 | 25 | //:configuration = Release 26 | GCC_PREPROCESSOR_DEFINITIONS = DYLD_VERSION=$(RC_ProjectSourceVersion) BUILDING_DYLD=1 27 | -------------------------------------------------------------------------------- /configs/update_dyld_shared_cache.xcconfig: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /configs/update_dyld_sim_shared_cache.xcconfig: -------------------------------------------------------------------------------- 1 | 2 | #include "/AppleInternal/XcodeConfig/PlatformSupportHost.xcconfig" 3 | 4 | 5 | //:configuration = Debug 6 | GCC_PREPROCESSOR_DEFINITIONS = BUILDING_CACHE_BUILDER=1 DEBUG=1 7 | 8 | //:configuration = Release 9 | GCC_PREPROCESSOR_DEFINITIONS = BUILDING_CACHE_BUILDER=1 10 | -------------------------------------------------------------------------------- /doc/man/man1/closured.1: -------------------------------------------------------------------------------- 1 | .Dd 3/1/17 2 | .Dt closured 1 3 | .Os Darwin 4 | .Sh NAME 5 | .Nm closured 6 | .Nd Daemon for building dyld closures. 7 | .Sh SYNOPSIS 8 | .Nm closured is a launchd managed daemon. 9 | .Sh DESCRIPTION 10 | .Nm closured is a launchd managed daemon. 11 | -------------------------------------------------------------------------------- /doc/man/man3/dlerror.3: -------------------------------------------------------------------------------- 1 | .Dd April 17, 2006 2 | .Dt DLERROR 3 3 | .Sh NAME 4 | .Nm dlerror 5 | .Nd get diagnostic information 6 | .Sh SYNOPSIS 7 | .In dlfcn.h 8 | .Ft const char* 9 | .Fn dlerror "void" 10 | .Sh DESCRIPTION 11 | .Fn dlerror 12 | returns a null-terminated character string describing the last error that 13 | occurred on this thread during a call to 14 | .Fn dlopen , 15 | .Fn dlopen_preflight , 16 | .Fn dlsym , 17 | or 18 | .Fn dlclose . 19 | If no such error has occurred, 20 | .Fn dlerror 21 | returns a null pointer. 22 | At each call to 23 | .Fn dlerror , 24 | the error indication is reset. Thus in the case of two calls 25 | to 26 | .Fn dlerror , 27 | where the second call follows the first immediately, the second call 28 | will always return a null pointer. 29 | .Sh SEE ALSO 30 | .Xr dlopen 3 31 | .Xr dlopen_preflight 3 32 | .Xr dlclose 3 33 | .Xr dlsym 3 34 | .Xr dyld 3 35 | -------------------------------------------------------------------------------- /doc/man/man3/dlopen_preflight.3: -------------------------------------------------------------------------------- 1 | .Dd April 17, 2006 2 | .Os 3 | .Dt DLOPEN_PREFLIGHT 3 4 | .Sh NAME 5 | .Nm dlopen_preflight 6 | .Nd preflight the load of a dynamic library or bundle 7 | .Sh SYNOPSIS 8 | .In dlfcn.h 9 | .Ft bool 10 | .Fn dlopen_preflight "const char* path" 11 | .Sh DESCRIPTION 12 | .Fn dlopen_preflight 13 | examines the mach-o file specified by 14 | .Fa path . 15 | It checks if the file and libraries it depends on are all compatible with the current process. 16 | That is, they contain the correct architecture and are not otherwise ABI incompatible. 17 | .Pp 18 | .Fn dlopen_preflight 19 | was first available in Mac OS X 10.5. 20 | .Sh SEARCHING 21 | .Fn dlopen_preflight 22 | uses the same steps as 23 | .Fn dlopen 24 | to find a compatible mach-o file. 25 | .Sh RETURN VALUES 26 | .Fn dlopen_preflight 27 | returns true on if the mach-o file is compatible. If the file is not compatible, it returns false 28 | and sets an error string that can be examined with 29 | .Fn dlerror . 30 | .Pp 31 | .Sh SEE ALSO 32 | .Xr dlopen 3 33 | .Xr dlerror 3 34 | -------------------------------------------------------------------------------- /doc/rst/index.rst: -------------------------------------------------------------------------------- 1 | DYLD Command Guide 2 | ------------------ 3 | 4 | The following documents are command descriptions for some of the DYLD tools. 5 | 6 | .. toctree:: 7 | :maxdepth: 1 8 | 9 | dyld_usage 10 | -------------------------------------------------------------------------------- /doc/tracing/dyld.codes: -------------------------------------------------------------------------------- 1 | 0x1f070000 dyld.static_intializer 2 | 0x1f070004 dyld.launch_executable 3 | 0x1f070008 dyld.map_file 4 | 0x1f07000c dyld.apply_fixups 5 | 0x1f070010 dyld.attach_codesignature 6 | 0x1f070014 dyld.build_closure 7 | 0x1f070018 dyld.add_image_callback 8 | 0x1f07001c dyld.remove_image_callback 9 | 0x1f070020 dyld.objc_image_init 10 | 0x1f070024 dyld.objc_images_map 11 | 0x1f070028 dyld.apply_interposing 12 | 0x1f07002c dyld.gdb_image_notifier 13 | 0x1f070030 dyld.remote_image_notifier 14 | 0x1f080000 dyld.dlopen 15 | 0x1f080004 dyld.dlopen_preflight 16 | 0x1f080008 dyld.dlclose 17 | 0x1f08000c dyld.dlsym 18 | 0x1f080010 dyld.dladdr 19 | 0x1f090000 dyld.DEBUG.vm_remap 20 | 0x1f090004 dyld.DEBUG.vm_dealloc 21 | 0x1f090008 dyld.DEBUG.map_loop 22 | 0x1f09000c dyld.DEBUG.marker 23 | -------------------------------------------------------------------------------- /dyld.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /dyld.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /dyld3/shared-cache/update_dyld_shared_cache_entitlements.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | com.apple.rootless.storage.dyld 6 | 7 | com.apple.private.storage.fusion.allow-pin-fastpromote 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /dyld_sim-entitlements.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | com.apple.private.dyld_sim 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/dyldAPIs.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/antons/dyld-shared-cache-big-sur/abdd035bdfda33998cc80cd06b625cd99563ca33/src/dyldAPIs.cpp -------------------------------------------------------------------------------- /src/libdyld_data_symbols.dirty: -------------------------------------------------------------------------------- 1 | __ZL12sGlobalMutex 2 | __ZZ26NSVersionOfLinkTimeLibraryE2mh 3 | __ZZ33_dyld_register_func_for_add_imageE1p 4 | __ZZ36_dyld_register_func_for_remove_imageE1p 5 | __ZZ21_dyld_get_image_slideE1p 6 | __ZZ6dlopenE1p 7 | __ZZ40dyld_register_image_state_change_handlerE1p 8 | __ZZ21_dyld_fast_stub_entryPvlE1p 9 | __ZZ34dyld_image_path_containing_addressE1p 10 | __ZZ20_NSGetExecutablePathE1p 11 | _myDyldSection 12 | _tlv_terminators_key 13 | -------------------------------------------------------------------------------- /src/libdyld_sim.exp: -------------------------------------------------------------------------------- 1 | _dyld_get_sdk_version 2 | _dyld_get_program_sdk_version 3 | _dyld_get_min_os_version 4 | _dyld_get_program_min_os_version 5 | 6 | -------------------------------------------------------------------------------- /testing/get_task_allow_entitlement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | get-task-allow 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /testing/nocr/execserver.defs: -------------------------------------------------------------------------------- 1 | #include 2 | -------------------------------------------------------------------------------- /testing/nocr/nocr.1: -------------------------------------------------------------------------------- 1 | .Dd Dec 15, 2015 2 | .Dt nocr 1 3 | .Os Darwin 4 | .Sh NAME 5 | .Nm nocr 6 | .Nd "runs a command with crash reporter disabled" 7 | .Sh SYNOPSIS 8 | .HP 5n 9 | \fBnocr\fR 10 | \fIcommand\fR 11 | .br 12 | .Sh DESCRIPTION 13 | \fBnocr\fR 14 | executes 15 | \fIcommand\fR 16 | in a way that blocks crash reporter should the command process crash. 17 | This is useful when running test suites 18 | .Pp 19 | .Sh "EXIT VALUE" 20 | Upon successful execution of a program, the exit status from 21 | \fInocr\fR 22 | will simply be the exit status of the program that was executed. 23 | .Pp 24 | If the program 25 | \fIcommand\fR 26 | crashed, the exit value will be 1 27 | -------------------------------------------------------------------------------- /testing/task_for_pid_entitlement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | com.apple.system-task-ports 6 | 7 | task_for_pid-allow 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /testing/test-cases/LC_DYLD_ENV-DYLD_LIBRARY_PATH.dtest/foo.c: -------------------------------------------------------------------------------- 1 | void foo() 2 | { 3 | } 4 | 5 | -------------------------------------------------------------------------------- /testing/test-cases/NSAddImage-basic.dtest/main.c: -------------------------------------------------------------------------------- 1 | // BUILD_ONLY: MacOSX 2 | 3 | // BUILD: $CC zzz.c -dynamiclib -o $BUILD_DIR/libzzz.dylib -install_name $RUN_DIR/libzzz.dylib 4 | // BUILD: $CC main.c -o $BUILD_DIR/NSAddImage-basic.exe -Wno-deprecated-declarations 5 | 6 | // RUN: ./NSAddImage-basic.exe $RUN_DIR/libzzz.dylib 7 | // RUN: ./NSAddImage-basic.exe libzzz.dylib 8 | 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | 15 | int main(int arg, const char* argv[]) 16 | { 17 | const char* path = argv[1]; 18 | printf("[BEGIN] NSAddImage-basic %s\n", path); 19 | 20 | const struct mach_header* mh = NSAddImage(path, NSADDIMAGE_OPTION_WITH_SEARCHING); 21 | if ( mh == NULL ) 22 | printf("[FAIL] NSAddImage-basic %s\n", path); 23 | else 24 | printf("[PASS] NSAddImage-basic %s\n", path); 25 | 26 | return 0; 27 | } 28 | 29 | -------------------------------------------------------------------------------- /testing/test-cases/NSAddImage-basic.dtest/zzz.c: -------------------------------------------------------------------------------- 1 | void zzz() {} 2 | -------------------------------------------------------------------------------- /testing/test-cases/NSAddImage-fail.dtest/main.c: -------------------------------------------------------------------------------- 1 | // BUILD_ONLY: MacOSX 2 | 3 | // BUILD: $CC main.c -o $BUILD_DIR/NSAddImage-fail.exe -Wno-deprecated-declarations 4 | 5 | // RUN: ./NSAddImage-fail.exe return 6 | // RUN: NOCR_TEST_NAME="NSAddImage-fail expected abort" $REQUIRE_CRASH ./NSAddImage-fail.exe abort 7 | 8 | 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | 16 | int main(int argc, const char* argv[]) 17 | { 18 | const char* arg = argv[1]; 19 | 20 | if ( strcmp(arg, "return") == 0 ) { 21 | printf("[BEGIN] NSAddImage-fail %s\n", arg); 22 | const struct mach_header* mh = NSAddImage("/xqz/42/libnotfound.xxx", NSADDIMAGE_OPTION_RETURN_ONLY_IF_LOADED); 23 | if ( mh == NULL ) 24 | printf("[PASS] NSAddImage-fail %s\n", arg); 25 | else 26 | printf("[FAIL] NSAddImage-fail %s\n", arg); 27 | } 28 | else { 29 | // run with nocr which print BEGIN/PASS/FAIL 30 | NSAddImage("/xqz/42/libnotfound.xxx", 0); 31 | } 32 | 33 | return 0; 34 | } 35 | 36 | -------------------------------------------------------------------------------- /testing/test-cases/NSAddImage-loaded.dtest/main.c: -------------------------------------------------------------------------------- 1 | // BUILD_ONLY: MacOSX 2 | 3 | // BUILD: $CC main.c -o $BUILD_DIR/NSAddImage-loaded.exe -Wno-deprecated-declarations 4 | 5 | // RUN: ./NSAddImage-loaded.exe return 6 | 7 | 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | 15 | int main(int argc, const char* argv[]) 16 | { 17 | printf("[BEGIN] NSAddImage-loaded\n"); 18 | 19 | // verify value is returned for image already loaded 20 | const struct mach_header* mh = NSAddImage("/usr/lib/libSystem.B.dylib", NSADDIMAGE_OPTION_RETURN_ONLY_IF_LOADED); 21 | if ( mh == NULL ) 22 | printf("[FAIL] NSAddImage-loaded\n"); 23 | 24 | // verify existing dylib is not loaded if it is not already loaded 25 | mh = NSAddImage("/usr/lib/libz.dylib", NSADDIMAGE_OPTION_RETURN_ONLY_IF_LOADED); 26 | if ( mh != NULL ) 27 | printf("[FAIL] NSAddImage-loaded\n"); 28 | 29 | printf("[PASS] NSAddImage-loaded\n"); 30 | 31 | return 0; 32 | } 33 | 34 | -------------------------------------------------------------------------------- /testing/test-cases/NSCreateObjectFileImageFromFile-basic.dtest/foo.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | void fooInBundle() 6 | { 7 | } 8 | -------------------------------------------------------------------------------- /testing/test-cases/NSCreateObjectFileImageFromFile-stress.dtest/foo.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | void fooInBundle() 6 | { 7 | } 8 | -------------------------------------------------------------------------------- /testing/test-cases/NSCreateObjectFileImageFromMemory-basic.dtest/foo.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | void fooInBundle() 6 | { 7 | } 8 | -------------------------------------------------------------------------------- /testing/test-cases/_dyld_for_each_objc_class-duplicates.dtest/linked1.m: -------------------------------------------------------------------------------- 1 | 2 | #import 3 | 4 | @interface NSString : NSObject 5 | @end 6 | 7 | @implementation NSString 8 | @end 9 | 10 | extern Class OBJC_CLASS_$_NSString; 11 | 12 | Class getLinked1NSString() { 13 | return (Class)&OBJC_CLASS_$_NSString; 14 | } 15 | -------------------------------------------------------------------------------- /testing/test-cases/_dyld_for_each_objc_class-duplicates.dtest/linked2.m: -------------------------------------------------------------------------------- 1 | 2 | #import 3 | 4 | @interface NSString : NSObject 5 | @end 6 | 7 | @implementation NSString 8 | @end 9 | 10 | extern Class OBJC_CLASS_$_NSString; 11 | 12 | Class getLinked2NSString() { 13 | return (Class)&OBJC_CLASS_$_NSString; 14 | } 15 | -------------------------------------------------------------------------------- /testing/test-cases/_dyld_for_each_objc_class-missing-weak-chained.dtest/lib1.m: -------------------------------------------------------------------------------- 1 | 2 | #import 3 | 4 | @interface DyldClass : NSObject 5 | @end 6 | 7 | @implementation DyldClass 8 | @end 9 | 10 | @interface DyldLinkedClass : NSObject 11 | @end 12 | 13 | @implementation DyldLinkedClass 14 | @end 15 | 16 | extern Class OBJC_CLASS_$_DyldClass; 17 | extern Class OBJC_CLASS_$_DyldLinkedClass; 18 | 19 | Class getLinked1DyldClass() { 20 | return (Class)&OBJC_CLASS_$_DyldClass; 21 | } 22 | 23 | Class getLinked1DyldLinkedClass() { 24 | return (Class)&OBJC_CLASS_$_DyldLinkedClass; 25 | } -------------------------------------------------------------------------------- /testing/test-cases/_dyld_for_each_objc_class-missing-weak-chained.dtest/lib2.m: -------------------------------------------------------------------------------- 1 | 2 | #import 3 | 4 | __attribute__((weak_import)) 5 | @interface MissingWeakSuperclass : NSObject 6 | @end 7 | 8 | // Note this class will be ignored at runtime as its superclass is weak 9 | @interface DyldClass : MissingWeakSuperclass 10 | @end 11 | 12 | @implementation DyldClass 13 | @end 14 | 15 | // Note that this class does not have a weak superclass, but we can't optimize anything in this 16 | // dylib as DyldClass does have a missing weak superclass. So we shouldn't find DyldLinkedClass in our 17 | // closure class map 18 | @interface DyldLinkedClass : NSObject 19 | @end 20 | 21 | @implementation DyldLinkedClass 22 | @end 23 | 24 | extern Class OBJC_CLASS_$_DyldLinkedClass; 25 | 26 | Class getLinked2DyldLinkedClass() { 27 | return (Class)&OBJC_CLASS_$_DyldLinkedClass; 28 | } -------------------------------------------------------------------------------- /testing/test-cases/_dyld_for_each_objc_class-missing-weak-chained.dtest/missing.m: -------------------------------------------------------------------------------- 1 | 2 | #import 3 | 4 | @interface MissingWeakSuperclass : NSObject 5 | @end 6 | 7 | @implementation MissingWeakSuperclass 8 | @end 9 | 10 | @interface DyldClass : MissingWeakSuperclass 11 | @end 12 | 13 | @implementation DyldClass 14 | @end 15 | 16 | id getMissingDyldClass() { 17 | return [DyldClass class]; 18 | } -------------------------------------------------------------------------------- /testing/test-cases/_dyld_for_each_objc_class-missing-weak.dtest/lib1.m: -------------------------------------------------------------------------------- 1 | 2 | #import 3 | 4 | @interface DyldClass : NSObject 5 | @end 6 | 7 | @implementation DyldClass 8 | @end 9 | 10 | @interface DyldLinkedClass : NSObject 11 | @end 12 | 13 | @implementation DyldLinkedClass 14 | @end 15 | 16 | extern Class OBJC_CLASS_$_DyldClass; 17 | extern Class OBJC_CLASS_$_DyldLinkedClass; 18 | 19 | Class getLinked1DyldClass() { 20 | return (Class)&OBJC_CLASS_$_DyldClass; 21 | } 22 | 23 | Class getLinked1DyldLinkedClass() { 24 | return (Class)&OBJC_CLASS_$_DyldLinkedClass; 25 | } -------------------------------------------------------------------------------- /testing/test-cases/_dyld_for_each_objc_class-missing-weak.dtest/lib2.m: -------------------------------------------------------------------------------- 1 | 2 | #import 3 | 4 | __attribute__((weak_import)) 5 | @interface MissingWeakSuperclass : NSObject 6 | @end 7 | 8 | // Note this class will be ignored at runtime as its superclass is weak 9 | @interface DyldClass : MissingWeakSuperclass 10 | @end 11 | 12 | @implementation DyldClass 13 | @end 14 | 15 | // Note that this class does not have a weak superclass, but we can't optimize anything in this 16 | // dylib as DyldClass does have a missing weak superclass. So we shouldn't find DyldLinkedClass in our 17 | // closure class map 18 | @interface DyldLinkedClass : NSObject 19 | @end 20 | 21 | @implementation DyldLinkedClass 22 | @end 23 | 24 | extern Class OBJC_CLASS_$_DyldLinkedClass; 25 | 26 | Class getLinked2DyldLinkedClass() { 27 | return (Class)&OBJC_CLASS_$_DyldLinkedClass; 28 | } -------------------------------------------------------------------------------- /testing/test-cases/_dyld_for_each_objc_class-missing-weak.dtest/missing.m: -------------------------------------------------------------------------------- 1 | 2 | #import 3 | 4 | @interface MissingWeakSuperclass : NSObject 5 | @end 6 | 7 | @implementation MissingWeakSuperclass 8 | @end 9 | 10 | @interface DyldClass : MissingWeakSuperclass 11 | @end 12 | 13 | @implementation DyldClass 14 | @end 15 | 16 | id getMissingDyldClass() { 17 | return [DyldClass class]; 18 | } -------------------------------------------------------------------------------- /testing/test-cases/_dyld_for_each_objc_class.dtest/linked1.m: -------------------------------------------------------------------------------- 1 | 2 | #import 3 | 4 | @interface DyldClass : NSObject 5 | @end 6 | 7 | @implementation DyldClass 8 | @end 9 | 10 | @interface DyldLinkedClass : NSObject 11 | @end 12 | 13 | @implementation DyldLinkedClass 14 | @end 15 | 16 | extern Class OBJC_CLASS_$_DyldClass; 17 | 18 | Class getLinked1DyldClass() { 19 | return (Class)&OBJC_CLASS_$_DyldClass; 20 | } -------------------------------------------------------------------------------- /testing/test-cases/_dyld_for_each_objc_class.dtest/linked2.m: -------------------------------------------------------------------------------- 1 | 2 | #import 3 | 4 | @interface DyldClass : NSObject 5 | @end 6 | 7 | @implementation DyldClass 8 | @end 9 | 10 | @interface DyldLinkedClass : NSObject 11 | @end 12 | 13 | @implementation DyldLinkedClass 14 | @end 15 | 16 | extern Class OBJC_CLASS_$_DyldClass; 17 | extern Class OBJC_CLASS_$_DyldLinkedClass; 18 | 19 | Class getLinked2DyldClass() { 20 | return (Class)&OBJC_CLASS_$_DyldClass; 21 | } 22 | 23 | Class getLinked2DyldLinkedClass() { 24 | return (Class)&OBJC_CLASS_$_DyldLinkedClass; 25 | } -------------------------------------------------------------------------------- /testing/test-cases/_dyld_for_each_objc_protocol.dtest/linked1.m: -------------------------------------------------------------------------------- 1 | 2 | #import 3 | 4 | @protocol DyldProtocol 5 | @end 6 | 7 | @protocol DyldLinkedProtocol 8 | @end 9 | 10 | Protocol* getLinked1DyldProtocol() { 11 | return @protocol(DyldProtocol); 12 | } 13 | 14 | Protocol* getLinked1DyldLinkedProtocol() { 15 | return @protocol(DyldLinkedProtocol); 16 | } 17 | -------------------------------------------------------------------------------- /testing/test-cases/_dyld_for_each_objc_protocol.dtest/linked2.m: -------------------------------------------------------------------------------- 1 | 2 | #import 3 | 4 | @protocol DyldProtocol 5 | @end 6 | 7 | @protocol DyldLinkedProtocol 8 | @end 9 | 10 | Protocol* getLinked2DyldProtocol() { 11 | return @protocol(DyldProtocol); 12 | } 13 | 14 | Protocol* getLinked2DyldLinkedProtocol() { 15 | return @protocol(DyldLinkedProtocol); 16 | } 17 | -------------------------------------------------------------------------------- /testing/test-cases/_dyld_images_for_addresses.dtest/foo.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include 4 | #include 5 | 6 | 7 | int foo1() 8 | { 9 | return 1; 10 | } 11 | 12 | int foo2() 13 | { 14 | return 2; 15 | } 16 | 17 | int foo3() 18 | { 19 | return 3; 20 | } 21 | 22 | 23 | -------------------------------------------------------------------------------- /testing/test-cases/_dyld_is_memory_immutable-lock.dtest/foo.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include 4 | 5 | void foo() 6 | { 7 | } 8 | 9 | -------------------------------------------------------------------------------- /testing/test-cases/_dyld_is_memory_immutable.dtest/bar.c: -------------------------------------------------------------------------------- 1 | const char* bar() 2 | { 3 | return "bar"; 4 | } 5 | -------------------------------------------------------------------------------- /testing/test-cases/_dyld_is_memory_immutable.dtest/foo.c: -------------------------------------------------------------------------------- 1 | const char* foo() 2 | { 3 | return "foo"; 4 | } 5 | -------------------------------------------------------------------------------- /testing/test-cases/_dyld_register_for_bulk_image_loads.dtest/bar.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | 6 | __attribute__((constructor)) 7 | void bar() { 8 | void* handle = dlopen(RUN_DIR "/libbaz.dylib", RTLD_FIRST); 9 | if ( handle == NULL ) { 10 | printf("[FAIL] dlopen(\"%s\") failed with: %s\n", RUN_DIR "/libbaz.dylib", dlerror()); 11 | exit(0); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /testing/test-cases/_dyld_register_for_bulk_image_loads.dtest/baz.c: -------------------------------------------------------------------------------- 1 | 2 | void baz() { } 3 | -------------------------------------------------------------------------------- /testing/test-cases/_dyld_register_for_bulk_image_loads.dtest/foo.c: -------------------------------------------------------------------------------- 1 | void foo() {} 2 | -------------------------------------------------------------------------------- /testing/test-cases/_dyld_register_for_bulk_image_loads.dtest/up.c: -------------------------------------------------------------------------------- 1 | 2 | void up() { } 3 | -------------------------------------------------------------------------------- /testing/test-cases/_dyld_register_for_image_loads.dtest/bar.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | 6 | __attribute__((constructor)) 7 | void bar() { 8 | void* handle = dlopen(RUN_DIR "/libbaz.dylib", RTLD_FIRST); 9 | if ( handle == NULL ) { 10 | printf("[FAIL] dlopen(\"%s\") failed with: %s\n", RUN_DIR "/libbaz.dylib", dlerror()); 11 | exit(0); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /testing/test-cases/_dyld_register_for_image_loads.dtest/baz.c: -------------------------------------------------------------------------------- 1 | 2 | void baz() { } 3 | -------------------------------------------------------------------------------- /testing/test-cases/_dyld_register_for_image_loads.dtest/foo.c: -------------------------------------------------------------------------------- 1 | void foo() {} 2 | -------------------------------------------------------------------------------- /testing/test-cases/_dyld_register_for_image_loads.dtest/up.c: -------------------------------------------------------------------------------- 1 | 2 | void up() { } 3 | -------------------------------------------------------------------------------- /testing/test-cases/_dyld_register_func_for_add_image.dtest/foo.c: -------------------------------------------------------------------------------- 1 | void foo() {} 2 | -------------------------------------------------------------------------------- /testing/test-cases/_dyld_shared_cache_is_locally_built.dtest/main.c: -------------------------------------------------------------------------------- 1 | 2 | // BUILD: $CC main.c -o $BUILD_DIR/_dyld_shared_cache_is_locally_built.exe 3 | 4 | // RUN: ./_dyld_shared_cache_is_locally_built.exe 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | 13 | int main() 14 | { 15 | printf("[BEGIN] _dyld_shared_cache_is_locally_built\n"); 16 | 17 | // We can't reliably test the result of this function, but it shouldn't crash 18 | _dyld_shared_cache_is_locally_built(); 19 | 20 | printf("[PASS] _dyld_shared_cache_is_locally_built\n"); 21 | 22 | return 0; 23 | } 24 | 25 | -------------------------------------------------------------------------------- /testing/test-cases/amfi-hardened-dlopen-leaf.dtest/my.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void foo() {} 4 | 5 | 6 | -------------------------------------------------------------------------------- /testing/test-cases/amfi-interpose.dtest/interposer.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | 6 | 7 | void* mymalloc(size_t size) 8 | { 9 | // bump ptr allocate twice the size and fills with '#' 10 | char* result = malloc(size*2); 11 | memset(result, '#', size*2); 12 | return result; 13 | } 14 | 15 | void myfree(void* p) 16 | { 17 | free(p); 18 | } 19 | 20 | DYLD_INTERPOSE(mymalloc, malloc) 21 | DYLD_INTERPOSE(myfree, free) 22 | -------------------------------------------------------------------------------- /testing/test-cases/chained-fixups-many-binds.dtest/main.c: -------------------------------------------------------------------------------- 1 | 2 | // BUILD: $CC foo.c -dynamiclib -o $BUILD_DIR/libFoo.dylib -install_name $RUN_DIR/libFoo.dylib 3 | // BUILD: $CC main.c -o $BUILD_DIR/chained-fixups-many-binds.exe $BUILD_DIR/libFoo.dylib -Wl,-fixup_chains 4 | 5 | // RUN: ./chained-fixups-many-binds.exe 6 | 7 | // Here's how to generate this monster 8 | // ( for i in `seq 1 65000`; do echo "void foo$i() { }"; done ) > foo.c 9 | // ( for i in `seq 1 65000`; do echo "extern void foo$i();"; done ) > foo.h 10 | // ( for i in `seq 1 65000`; do echo "__attribute__((used)) void* use$i = (void*)&foo$i;"; done ) > uses.h 11 | 12 | #include 13 | 14 | #include "foo.h" 15 | #include "uses.h" 16 | 17 | int main() { 18 | printf("[BEGIN] chained-fixups-many-binds\n"); 19 | printf("[PASS] chained-fixups-many-binds\n"); 20 | return 0; 21 | } -------------------------------------------------------------------------------- /testing/test-cases/cwd-relative-load.dtest/foo.c: -------------------------------------------------------------------------------- 1 | int foo = 42; 2 | -------------------------------------------------------------------------------- /testing/test-cases/cwd-relative-load.dtest/main.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | // BUILD: $CC foo.c -dynamiclib -o $BUILD_DIR/libfoo.dylib -install_name libfoo.dylib 4 | // BUILD: $CC main.c $BUILD_DIR/libfoo.dylib -o $BUILD_DIR/cwd-load.exe 5 | // BUILD: $DYLD_ENV_VARS_ENABLE $BUILD_DIR/cwd-load.exe 6 | 7 | // RUN: ./cwd-load.exe 8 | 9 | // libfoo.dylib is loaded from the current directory (not an absolute path) 10 | 11 | 12 | #include 13 | 14 | extern int foo; 15 | 16 | 17 | int main() 18 | { 19 | printf("[BEGIN] cwd-relative-load\n"); 20 | if ( foo == 42 ) 21 | printf("[PASS] cwd-relative-load\n"); 22 | else 23 | printf("[FAIL] cwd-relative-load, wrong value\n"); 24 | 25 | return 0; 26 | } 27 | 28 | 29 | -------------------------------------------------------------------------------- /testing/test-cases/dladdr-basic.dtest/main-no-syms.c: -------------------------------------------------------------------------------- 1 | 2 | // BUILD: $CC main-no-syms.c -o $BUILD_DIR/dladdr-stripped.exe 3 | // BUILD: strip $BUILD_DIR/dladdr-stripped.exe 4 | 5 | // RUN: ./dladdr-stripped.exe 6 | 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | 15 | 16 | /// 17 | /// verify dladdr() returns NULL for a symbol name in a fully stripped 18 | /// main executable (and not _mh_execute_header+nnn). 19 | /// 20 | 21 | int main() 22 | { 23 | printf("[BEGIN] dladdr-stripped\n"); 24 | 25 | Dl_info info; 26 | if ( dladdr(&main, &info) == 0 ) { 27 | printf("[FAIL] dladdr(&main, xx) failed\n"); 28 | return 0; 29 | } 30 | 31 | if ( info.dli_sname != NULL ){ 32 | printf("[FAIL] dladdr() returned: \"%s\" instead of NULL\n", info.dli_sname); 33 | return 0; 34 | } 35 | 36 | printf("[PASS] dladdr-stripped\n"); 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /testing/test-cases/dlclose-static-terminator.dtest/foo.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | typedef void (*NotifyProc)(void); 5 | 6 | NotifyProc gNotifer = NULL; 7 | 8 | 9 | static __attribute__((destructor)) 10 | void myTerm() 11 | { 12 | if ( gNotifer ) 13 | gNotifer(); 14 | } 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /testing/test-cases/dlopen-DYLD_LIBRARY_PATH.dtest/bar.c: -------------------------------------------------------------------------------- 1 | int bar() 2 | { 3 | return VALUE; 4 | } 5 | 6 | -------------------------------------------------------------------------------- /testing/test-cases/dlopen-DYLD_LIBRARY_PATH.dtest/foo.c: -------------------------------------------------------------------------------- 1 | extern int bar(); 2 | 3 | int foo() 4 | { 5 | return bar() + VALUE; 6 | } 7 | 8 | -------------------------------------------------------------------------------- /testing/test-cases/dlopen-RTLD_LOCAL-coalesce.dtest/foo1.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | int __attribute__((weak)) coalA = 1; 4 | int __attribute__((weak)) coalB = 1; 5 | 6 | int foo1_coalA() 7 | { 8 | return coalA; 9 | } 10 | 11 | int foo1_coalB() 12 | { 13 | return coalB; 14 | } 15 | 16 | -------------------------------------------------------------------------------- /testing/test-cases/dlopen-RTLD_LOCAL-coalesce.dtest/foo2.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | int __attribute__((weak)) coalA = 2; 4 | int __attribute__((weak)) coalB = 2; 5 | int __attribute__((weak)) coalC = 2; 6 | 7 | int foo2_coalA() 8 | { 9 | return coalA; 10 | } 11 | 12 | int foo2_coalB() 13 | { 14 | return coalB; 15 | } 16 | 17 | int foo2_coalC() 18 | { 19 | return coalC; 20 | } 21 | -------------------------------------------------------------------------------- /testing/test-cases/dlopen-RTLD_LOCAL-coalesce.dtest/foo3.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | int __attribute__((weak)) coalA = 3; 4 | int __attribute__((weak)) coalB = 3; 5 | int __attribute__((weak)) coalC = 3; 6 | 7 | int foo3_coalA() 8 | { 9 | return coalA; 10 | } 11 | 12 | int foo3_coalB() 13 | { 14 | return coalB; 15 | } 16 | 17 | int foo3_coalC() 18 | { 19 | return coalC; 20 | } 21 | -------------------------------------------------------------------------------- /testing/test-cases/dlopen-RTLD_LOCAL-hides.dtest/bar.c: -------------------------------------------------------------------------------- 1 | int bar() 2 | { 3 | return 11; 4 | } 5 | 6 | -------------------------------------------------------------------------------- /testing/test-cases/dlopen-RTLD_LOCAL-hides.dtest/foo.c: -------------------------------------------------------------------------------- 1 | int foo() 2 | { 3 | return 10; 4 | } 5 | 6 | -------------------------------------------------------------------------------- /testing/test-cases/dlopen-RTLD_NODELETE.dtest/bar.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | int bar = 11; 4 | 5 | -------------------------------------------------------------------------------- /testing/test-cases/dlopen-RTLD_NODELETE.dtest/foo.c: -------------------------------------------------------------------------------- 1 | 2 | int foo = 10; 3 | 4 | -------------------------------------------------------------------------------- /testing/test-cases/dlopen-RTLD_NOLOAD.dtest/foo.c: -------------------------------------------------------------------------------- 1 | int foo() 2 | { 3 | return 10; 4 | } 5 | 6 | -------------------------------------------------------------------------------- /testing/test-cases/dlopen-RTLD_NOLOAD.dtest/init-a.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include 4 | 5 | extern bool inInitB; 6 | extern bool doneInitB; 7 | 8 | bool initsInWrongOrder = false; 9 | bool doneInitA = false; 10 | 11 | __attribute__((constructor)) 12 | void initA() 13 | { 14 | if ( inInitB ) 15 | initsInWrongOrder = true; 16 | doneInitA = true; 17 | } 18 | 19 | bool allInitsDone() 20 | { 21 | return doneInitA && doneInitB; 22 | } 23 | -------------------------------------------------------------------------------- /testing/test-cases/dlopen-RTLD_NOLOAD.dtest/init-b.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | bool doneInitB = false; 8 | bool inInitB = false; 9 | 10 | 11 | __attribute__((constructor)) 12 | void initB() 13 | { 14 | inInitB = true; 15 | 16 | // "upward" link to libInitA.dylib 17 | void* handle = dlopen(RUN_DIR "/libInitA.dylib", RTLD_NOLOAD); 18 | if ( handle == NULL ) { 19 | printf("[FAIL] dlopen-RTLD_NOLOAD-in-initializer: dlopen(libInitA.dylib, RTLD_NOLOAD) failed but it should have worked: %s\n", dlerror()); 20 | return; 21 | } 22 | inInitB = false; 23 | 24 | doneInitB = true; 25 | } 26 | -------------------------------------------------------------------------------- /testing/test-cases/dlopen-RTLD_NOW.dtest/bar.c: -------------------------------------------------------------------------------- 1 | 2 | #ifdef HAS_SYMBOL 3 | void bar() { } 4 | #endif 5 | 6 | 7 | -------------------------------------------------------------------------------- /testing/test-cases/dlopen-RTLD_NOW.dtest/foo.c: -------------------------------------------------------------------------------- 1 | 2 | extern void bar(); 3 | 4 | void foo() 5 | { 6 | bar(); 7 | } 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /testing/test-cases/dlopen-atpath-restricted.dtest/bar.c: -------------------------------------------------------------------------------- 1 | void bar() {} 2 | -------------------------------------------------------------------------------- /testing/test-cases/dlopen-atpath-restricted.dtest/foo.c: -------------------------------------------------------------------------------- 1 | int foo() 2 | { 3 | return 10; 4 | } 5 | 6 | -------------------------------------------------------------------------------- /testing/test-cases/dlopen-bad-file.dtest/bad.txt: -------------------------------------------------------------------------------- 1 | bad file 2 | -------------------------------------------------------------------------------- /testing/test-cases/dlopen-basic.dtest/foo.c: -------------------------------------------------------------------------------- 1 | int foo() 2 | { 3 | return 10; 4 | } 5 | 6 | -------------------------------------------------------------------------------- /testing/test-cases/dlopen-empty-data.dtest/foo.c: -------------------------------------------------------------------------------- 1 | 2 | int dummy; 3 | 4 | int foo() 5 | { 6 | return 10; 7 | } 8 | 9 | -------------------------------------------------------------------------------- /testing/test-cases/dlopen-empty-data.dtest/main.c: -------------------------------------------------------------------------------- 1 | 2 | // BUILD: $CC foo.c -dynamiclib -install_name $RUN_DIR/libfoo-static.dylib -o $BUILD_DIR/libfoo-static.dylib 3 | // BUILD: $CC foo.c -dynamiclib -install_name $RUN_DIR/libfoo-dynamic.dylib -o $BUILD_DIR/libfoo-dynamic.dylib 4 | // BUILD: $CC main.c $BUILD_DIR/libfoo-static.dylib -o $BUILD_DIR/dlopen-empty-data.exe -DRUN_DIR="$RUN_DIR" 5 | 6 | 7 | // RUN: ./dlopen-empty-data.exe 8 | 9 | #include 10 | #include 11 | 12 | // libfoo-static.dylib and libfoo-dynamic.dylib each have an empty (no disk size) DATA segment 13 | 14 | int main() 15 | { 16 | printf("[BEGIN] dlopen-empty-data\n"); 17 | 18 | void* handle = dlopen(RUN_DIR "/libfoo-dynamic.dylib", RTLD_LAZY); 19 | if ( handle == NULL ) { 20 | printf("[FAIL] dlopen-empty-data: libfoo-dynamic.dylib could not be loaded: %s\n", dlerror()); 21 | return 0; 22 | } 23 | 24 | printf("[PASS] dlopen-empty-data\n"); 25 | return 0; 26 | } 27 | 28 | -------------------------------------------------------------------------------- /testing/test-cases/dlopen-fail-cleanly.dtest/a.c: -------------------------------------------------------------------------------- 1 | int a() 2 | { 3 | return 10; 4 | } 5 | 6 | -------------------------------------------------------------------------------- /testing/test-cases/dlopen-fail-cleanly.dtest/b.m: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | extern void c_extra(); 4 | 5 | // The existence of this class should prevent libb.dylib from being unloaded 6 | 7 | @interface TestClass : NSObject 8 | -(void) foo; 9 | @end 10 | 11 | @implementation TestClass 12 | -(void) foo { c_extra(); } 13 | @end 14 | 15 | -------------------------------------------------------------------------------- /testing/test-cases/dlopen-fail-cleanly.dtest/c.c: -------------------------------------------------------------------------------- 1 | int c() 2 | { 3 | return 10; 4 | } 5 | 6 | #ifdef EXTRA_SYMBOL 7 | 8 | void c_extra() 9 | { 10 | } 11 | 12 | #endif 13 | 14 | -------------------------------------------------------------------------------- /testing/test-cases/dlopen-flat.dtest/bar.c: -------------------------------------------------------------------------------- 1 | 2 | extern int foo(); 3 | 4 | extern int gInitialisersCalled; 5 | 6 | __attribute__((constructor)) 7 | static void onLoad() { 8 | ++gInitialisersCalled; 9 | } 10 | 11 | typedef int(*retTy)(); 12 | 13 | retTy bar() { 14 | return &foo; 15 | } -------------------------------------------------------------------------------- /testing/test-cases/dlopen-flat.dtest/foo.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | extern int gInitialisersCalled; 4 | 5 | __attribute__((constructor)) 6 | static void onLoad() { 7 | ++gInitialisersCalled; 8 | } 9 | 10 | 11 | int foo() { 12 | return 0; 13 | } -------------------------------------------------------------------------------- /testing/test-cases/dlopen-framework-fallback.dtest/main.c: -------------------------------------------------------------------------------- 1 | 2 | // BUILD: $CC main.c -o $BUILD_DIR/dlopen-framework-fallback.exe 3 | 4 | // RUN: ./dlopen-framework-fallback.exe 5 | 6 | #include 7 | #include 8 | 9 | 10 | 11 | int main() 12 | { 13 | printf("[BEGIN] dlopen-framework-fallback\n"); 14 | 15 | // Verify dyld will fallback and look for framework in /System/Library/Frameworks/ 16 | void* handle = dlopen("/System/Library/BadPath/CoreFoundation.framework/CoreFoundation", RTLD_LAZY); 17 | if ( handle == NULL ) { 18 | printf("dlerror(): %s\n", dlerror()); 19 | printf("[FAIL] dlopen-framework-fallback\n"); 20 | return 0; 21 | } 22 | 23 | // validate handle works to find symbols 24 | void* sym = dlsym(handle, "CFRetain"); 25 | if ( sym == NULL ) { 26 | printf("dlerror(): %s\n", dlerror()); 27 | printf("[FAIL] dlopen-framework-fallback\n"); 28 | return 0; 29 | } 30 | 31 | printf("[PASS] dlopen-framework-fallback\n"); 32 | 33 | return 0; 34 | } 35 | 36 | -------------------------------------------------------------------------------- /testing/test-cases/dlopen-haswell.dtest/a.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | bool isHaswell() 4 | { 5 | #if __x86_64h__ 6 | return true; 7 | #else 8 | return false; 9 | #endif 10 | } 11 | -------------------------------------------------------------------------------- /testing/test-cases/dlopen-in-init.dtest/foo.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | 15 | static void* work1(void* arg) 16 | { 17 | void* h = dlopen("System/Library/Frameworks/Foundation.framework/Foundation", 0); 18 | 19 | return NULL; 20 | } 21 | 22 | 23 | __attribute__((constructor)) 24 | void myinit() 25 | { 26 | pthread_t workerThread; 27 | 28 | if ( pthread_create(&workerThread, NULL, work1, NULL) != 0 ) { 29 | printf("[FAIL] dlopen-in-init, pthread_create\n"); 30 | return; 31 | } 32 | 33 | void* dummy; 34 | pthread_join(workerThread, &dummy); 35 | } 36 | 37 | -------------------------------------------------------------------------------- /testing/test-cases/dlopen-in-init.dtest/main.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | // BUILD: $CC foo.c -dynamiclib -o $BUILD_DIR/libfoo.dylib -install_name $RUN_DIR/libfoo.dylib 4 | // BUILD: $CC main.c -o $BUILD_DIR/dlopen-in-init.exe $BUILD_DIR/libfoo.dylib 5 | 6 | // RUN: ./dlopen-in-init.exe 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | 13 | __attribute__((constructor)) 14 | void myinit() 15 | { 16 | 17 | } 18 | 19 | 20 | int main() 21 | { 22 | printf("[BEGIN] dlopen-in-init\n"); 23 | 24 | // The test is for libdyld.dylib to not crash when libfoo.dylib dlopen() stuff in its initializer 25 | 26 | printf("[PASS] dlopen-in-init\n"); 27 | return 0; 28 | } 29 | 30 | -------------------------------------------------------------------------------- /testing/test-cases/dlopen-in-init2.dtest/bar.c: -------------------------------------------------------------------------------- 1 | 2 | static int inited = 0; 3 | 4 | __attribute__((constructor)) 5 | static void myinit() 6 | { 7 | inited = 1; 8 | } 9 | 10 | int barIsInited() { 11 | return inited; 12 | } 13 | 14 | int bar() { 15 | return inited ? 0 : 1; 16 | } -------------------------------------------------------------------------------- /testing/test-cases/dlopen-in-init2.dtest/baz.c: -------------------------------------------------------------------------------- 1 | 2 | static int inited = 0; 3 | 4 | __attribute__((constructor)) 5 | static void myinit() 6 | { 7 | inited = 1; 8 | } 9 | 10 | int bazInited() { 11 | return inited; 12 | } -------------------------------------------------------------------------------- /testing/test-cases/dlopen-in-init3.dtest/baz.c: -------------------------------------------------------------------------------- 1 | 2 | static int inited = 0; 3 | 4 | __attribute__((constructor)) 5 | static void myinit() 6 | { 7 | inited = 1; 8 | } 9 | 10 | int bazIsInited() { 11 | return inited; 12 | } -------------------------------------------------------------------------------- /testing/test-cases/dlopen-in-init3.dtest/foo.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | extern int bar(); 5 | extern int bazIsInited(); 6 | 7 | int foo() { 8 | if ( bar() != 0 ) { 9 | return 1; 10 | } 11 | if ( bazIsInited() == 0 ) { 12 | printf("[FAIL] dlopen-in-init3, didn't init baz\n"); 13 | return 1; 14 | } 15 | return 0; 16 | } -------------------------------------------------------------------------------- /testing/test-cases/dlopen-indirect-groupNum.dtest/bar.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | void barInDylib() 6 | { 7 | } 8 | -------------------------------------------------------------------------------- /testing/test-cases/dlopen-indirect-groupNum.dtest/baz.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | extern void barInDylib(); 6 | 7 | void bazInDylib() 8 | { 9 | return barInDylib(); 10 | } 11 | -------------------------------------------------------------------------------- /testing/test-cases/dlopen-indirect-groupNum.dtest/foo.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | void fooInBundle() 6 | { 7 | } 8 | -------------------------------------------------------------------------------- /testing/test-cases/dlopen-intertwined.dtest/A.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | extern void setState(const char* from); 5 | 6 | 7 | void a(const char* from) { 8 | char buffer[100]; 9 | sprintf(buffer, "a() from %s", from); 10 | setState(buffer); 11 | } 12 | -------------------------------------------------------------------------------- /testing/test-cases/dlopen-intertwined.dtest/B.c: -------------------------------------------------------------------------------- 1 | extern void c(const char*); 2 | 3 | void b() { } 4 | 5 | void __attribute__((constructor)) 6 | initB() 7 | { 8 | c("initB"); 9 | } 10 | 11 | 12 | -------------------------------------------------------------------------------- /testing/test-cases/dlopen-intertwined.dtest/C.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | extern void setState(const char* from); 5 | 6 | void c(const char* from) { 7 | char buffer[100]; 8 | sprintf(buffer, "c() from %s", from); 9 | setState(buffer); 10 | } 11 | 12 | void __attribute__((constructor)) 13 | initC() 14 | { 15 | setState("initC"); 16 | } 17 | -------------------------------------------------------------------------------- /testing/test-cases/dlopen-intertwined.dtest/D.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | extern void setState(const char* from); 5 | extern void c(const char* from); 6 | 7 | void d(const char* from) { 8 | char buffer[100]; 9 | sprintf(buffer, "d() from %s", from); 10 | setState(buffer); 11 | } 12 | 13 | void __attribute__((constructor)) 14 | initD() 15 | { 16 | c("initD"); 17 | } 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /testing/test-cases/dlopen-intertwined.dtest/E.c: -------------------------------------------------------------------------------- 1 | extern void a(const char*); 2 | 3 | void e() { } 4 | 5 | 6 | void __attribute__((constructor)) 7 | initE() 8 | { 9 | a("initE"); 10 | } 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /testing/test-cases/dlopen-intertwined.dtest/F.c: -------------------------------------------------------------------------------- 1 | extern void d(const char*); 2 | 3 | void f() { } 4 | 5 | void __attribute__((constructor)) 6 | initF() 7 | { 8 | d("initF"); 9 | } 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /testing/test-cases/dlopen-intertwined.dtest/base.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | static const char* expectedStrings[] = { 6 | "a() from main", 7 | "initC", 8 | "c() from initB", 9 | "c() from initD", 10 | "a() from initE", 11 | "d() from initF", 12 | "DONE" 13 | }; 14 | 15 | static const char** curState = expectedStrings; 16 | 17 | void setState(const char* from) 18 | { 19 | printf("%s\n", from); 20 | if ( strcmp(*curState, from) != 0 ) { 21 | printf("[FAIL] dlopen-intertwined: expected %s\n", *curState); 22 | exit(0); 23 | } 24 | ++curState; 25 | } 26 | 27 | -------------------------------------------------------------------------------- /testing/test-cases/dlopen-long-error-message.dtest/main.c: -------------------------------------------------------------------------------- 1 | 2 | // BUILD: $CC main.c -o $BUILD_DIR/dlopen-long-error-message.exe 3 | 4 | // RUN: ./dlopen-long-error-message.exe 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | 12 | 13 | int main() 14 | { 15 | printf("[BEGIN] dlopen-long-error-message\n"); 16 | 17 | for (int i=0; i < 10; ++i) { 18 | void* handle = dlopen("/bogus/path/bogus/path/bogus/path/bogus/path/bogus/path/bogus/path/bogus/path/bogus/path/bogus/path/bogus/path/bogus/path/bogus/path/bogus/path/bogus/path/bogus/path/bogus/path/bogus/path/bogus/path/bogus/path/bogus/path/bogus/path/bogus/path/bogus/path/bogus/path/bogus/path/libbogus.dylib", RTLD_FIRST); 19 | if ( handle != NULL ) { 20 | printf("[FAIL] dlopen-long-error-message should have failed on non-existent file\n"); 21 | return 0; 22 | } 23 | free(strdup("hello there")); 24 | } 25 | 26 | printf("[PASS] dlopen-long-error-message\n"); 27 | 28 | return 0; 29 | } 30 | 31 | -------------------------------------------------------------------------------- /testing/test-cases/dlopen-prebuilt-dlopen-closure.dtest/main.c: -------------------------------------------------------------------------------- 1 | 2 | // BUILD: $CC main.c -o $BUILD_DIR/dlopen-prebuilt-dlopen-closure.exe 3 | 4 | // RUN: ./dlopen-prebuilt-dlopen-closure.exe 5 | 6 | // /usr/lib/libobjc-trampolines.dylib is not in the shared cache, but gets a prebuilt 7 | // closure. On embedded platforms, this is validated using the cd-hash of the file vs 8 | // what is in the pre-built closure. 9 | 10 | #include 11 | #include 12 | 13 | int main() 14 | { 15 | printf("[BEGIN] dlopen-prebuilt-dlopen-closure\n"); 16 | 17 | void* handle = dlopen("/usr/lib/libobjc-trampolines.dylib", RTLD_LAZY); 18 | if ( handle == NULL ) { 19 | printf("dlerror(): %s\n", dlerror()); 20 | printf("[FAIL] dlopen-prebuilt-dlopen-closure\n"); 21 | return 0; 22 | } 23 | 24 | printf("[PASS] dlopen-prebuilt-dlopen-closure\n"); 25 | 26 | return 0; 27 | } 28 | 29 | -------------------------------------------------------------------------------- /testing/test-cases/dlopen-race.dtest/foo.c: -------------------------------------------------------------------------------- 1 | int foo() 2 | { 3 | return 10; 4 | } 5 | 6 | -------------------------------------------------------------------------------- /testing/test-cases/dlopen-race.dtest/main.c: -------------------------------------------------------------------------------- 1 | 2 | // BUILD: $CC foo.c -dynamiclib -install_name $RUN_DIR/libfoo.dylib -o $BUILD_DIR/libfoo.dylib 3 | // BUILD: $CC main.c -o $BUILD_DIR/dlopen-race.exe -DRUN_DIR="$RUN_DIR" 4 | 5 | // RUN: ./dlopen-race.exe 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | 13 | 14 | int main() 15 | { 16 | printf("[BEGIN] dlopen-read\n"); 17 | 18 | __block bool allGood = true; 19 | dispatch_apply(6, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(size_t index) { 20 | for (int i=0; i < 500; ++i) { 21 | void* handle = dlopen(RUN_DIR "/libfoo.dylib", RTLD_LAZY); 22 | if ( handle == NULL ) { 23 | printf("[FAIL] dlopen-read: %s\n", dlerror()); 24 | exit(0); 25 | } 26 | dlclose(handle); 27 | } 28 | }); 29 | 30 | printf("[PASS] dlopen-read\n"); 31 | return 0; 32 | } 33 | 34 | -------------------------------------------------------------------------------- /testing/test-cases/dlopen-recurse.dtest/bar.c: -------------------------------------------------------------------------------- 1 | int bar() 2 | { 3 | return 0; 4 | } 5 | 6 | -------------------------------------------------------------------------------- /testing/test-cases/dlopen-recurse.dtest/foo.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | void myinit() __attribute__((constructor)); 5 | 6 | void myinit() 7 | { 8 | // call dlopen() in initializer 9 | void* handle = dlopen(RUN_DIR "/libbar.dylib", RTLD_LAZY); 10 | } 11 | 12 | int foo() 13 | { 14 | return 0; 15 | } 16 | 17 | -------------------------------------------------------------------------------- /testing/test-cases/dlopen-recurse.dtest/main.c: -------------------------------------------------------------------------------- 1 | 2 | // BUILD: $CC bar.c -dynamiclib -install_name $RUN_DIR/libbar.dylib -o $BUILD_DIR/libbar.dylib 3 | // BUILD: $CC foo.c -dynamiclib -install_name $RUN_DIR/libfoo.dylib -o $BUILD_DIR/libfoo.dylib -DRUN_DIR="$RUN_DIR" 4 | // BUILD: $CC main.c -o $BUILD_DIR/dlopen-recurse.exe -DRUN_DIR="$RUN_DIR" 5 | 6 | // RUN: ./dlopen-recurse.exe 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | 14 | 15 | int main() 16 | { 17 | printf("[BEGIN] dlopen-recurse\n"); 18 | 19 | // libfoo's initializer calls dlopen(). If that hangs, we have a locking bug 20 | void* handle = dlopen(RUN_DIR "/libfoo.dylib", RTLD_LAZY); 21 | dlclose(handle); 22 | 23 | printf("[PASS] dlopen-recurse\n"); 24 | return 0; 25 | } 26 | 27 | -------------------------------------------------------------------------------- /testing/test-cases/dlopen-rpath-from-dylib.dtest/bar.c: -------------------------------------------------------------------------------- 1 | int bar() 2 | { 3 | return 0; 4 | } 5 | 6 | -------------------------------------------------------------------------------- /testing/test-cases/dlopen-rpath-from-dylib.dtest/main.c: -------------------------------------------------------------------------------- 1 | 2 | // BUILD: mkdir -p $BUILD_DIR/dir 3 | // BUILD: $CC bar.c -dynamiclib -install_name @rpath/libbar.dylib -o $BUILD_DIR/dir/libbar.dylib 4 | // BUILD: $CC test.c -dynamiclib -install_name $RUN_DIR/libtest.dylib -o $BUILD_DIR/libtest.dylib -rpath @loader_path/dir 5 | // BUILD: $CC main.c -o $BUILD_DIR/dlopen-rpath-from-dylib.exe $BUILD_DIR/libtest.dylib 6 | 7 | // RUN: ./dlopen-rpath-from-dylib.exe 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | 14 | /// test that a call to dlopen() from a dylib uses the LC_RPATH from that dylib 15 | 16 | extern bool test_dlopen(); 17 | 18 | int main() 19 | { 20 | printf("[BEGIN] dlopen-rpath-from-dylib\n"); 21 | 22 | if ( test_dlopen() ) 23 | printf("[PASS] dlopen-rpath-from-dylib\n"); 24 | else 25 | printf("[FAIL] dlopen-rpath-from-dylib\n"); 26 | 27 | return 0; 28 | } 29 | 30 | -------------------------------------------------------------------------------- /testing/test-cases/dlopen-rpath-from-dylib.dtest/test.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | 6 | bool test_dlopen() 7 | { 8 | void* handle = dlopen("@rpath/libbar.dylib", RTLD_LAZY); 9 | if ( handle == NULL ) { 10 | printf("[FAIL] dlopen-rpath-from-dylib: dlopen(@rpath/libbar.dylib) failed: %s\n", dlerror()); 11 | return false; 12 | } 13 | 14 | dlclose(handle); 15 | 16 | return true; 17 | } 18 | 19 | 20 | -------------------------------------------------------------------------------- /testing/test-cases/dlopen-rpath-implicit.dtest/foo.c: -------------------------------------------------------------------------------- 1 | int foo() 2 | { 3 | return 10; 4 | } 5 | 6 | -------------------------------------------------------------------------------- /testing/test-cases/dlopen-rpath-implicit.dtest/main.c: -------------------------------------------------------------------------------- 1 | 2 | // BUILD: mkdir -p $BUILD_DIR/dir1 3 | // BUILD: $CC foo.c -dynamiclib -install_name @rpath/libimplicitrpath.dylib -o $BUILD_DIR/dir1/libimplicitrpath.dylib 4 | // BUILD: $CC main.c -o $BUILD_DIR/dlopen-rpath-implicit.exe -rpath @loader_path/dir1 5 | 6 | // RUN: ./dlopen-rpath-implicit.exe 7 | 8 | #include 9 | #include 10 | 11 | 12 | /// test that a leaf name passed to dlopen() searches the rpath 13 | 14 | int main() 15 | { 16 | printf("[BEGIN] dlopen-rpath-implicit\n"); 17 | 18 | void* handle = dlopen("libimplicitrpath.dylib", RTLD_LAZY); 19 | if ( handle == NULL ) { 20 | printf("[FAIL] dlopen-rpath-implicit: dlopen(libimplicitrpath.dylib) failed: %s\n", dlerror()); 21 | return 0; 22 | } 23 | 24 | dlclose(handle); 25 | 26 | printf("[PASS] dlopen-rpath-implicit\n"); 27 | 28 | return 0; 29 | } 30 | 31 | -------------------------------------------------------------------------------- /testing/test-cases/dlopen-rpath-prev-override.dtest/bad.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | __attribute__((constructor)) 6 | void init() 7 | { 8 | printf("[FAIL] dlopen-rpath-prev-override\n"); 9 | exit(0); 10 | } 11 | -------------------------------------------------------------------------------- /testing/test-cases/dlopen-rpath-prev-override.dtest/dyn.c: -------------------------------------------------------------------------------- 1 | int sub2() 2 | { 3 | return 2; 4 | } 5 | 6 | -------------------------------------------------------------------------------- /testing/test-cases/dlopen-rpath-prev-override.dtest/foo.c: -------------------------------------------------------------------------------- 1 | int foo() 2 | { 3 | return 10; 4 | } 5 | 6 | -------------------------------------------------------------------------------- /testing/test-cases/dlopen-rpath-prev-override.dtest/good.c: -------------------------------------------------------------------------------- 1 | int sub1() 2 | { 3 | return 1; 4 | } 5 | 6 | -------------------------------------------------------------------------------- /testing/test-cases/dlopen-rpath-prev.dtest/foo.c: -------------------------------------------------------------------------------- 1 | int foo() 2 | { 3 | return 10; 4 | } 5 | 6 | -------------------------------------------------------------------------------- /testing/test-cases/dlopen-rpath-prev.dtest/sub1.c: -------------------------------------------------------------------------------- 1 | int sub1() 2 | { 3 | return 1; 4 | } 5 | 6 | -------------------------------------------------------------------------------- /testing/test-cases/dlopen-rpath-prev.dtest/sub2.c: -------------------------------------------------------------------------------- 1 | int sub2() 2 | { 3 | return 2; 4 | } 5 | 6 | -------------------------------------------------------------------------------- /testing/test-cases/dlopen-signing.dtest/dylib.c: -------------------------------------------------------------------------------- 1 | int foo() { 2 | return 10; 3 | } 4 | -------------------------------------------------------------------------------- /testing/test-cases/dlopen-symlink.dtest/foo.c: -------------------------------------------------------------------------------- 1 | void foo() {} 2 | -------------------------------------------------------------------------------- /testing/test-cases/dlsym-RTLD_DEFAULT.dtest/foo.c: -------------------------------------------------------------------------------- 1 | 2 | void foo() { } 3 | 4 | #if DYN 5 | void foo2() {} 6 | #endif 7 | -------------------------------------------------------------------------------- /testing/test-cases/dlsym-RTLD_MAIN_ONLY.dtest/foo.c: -------------------------------------------------------------------------------- 1 | 2 | void foo() { } 3 | 4 | #if DYN 5 | void foo2() {} 6 | #endif 7 | -------------------------------------------------------------------------------- /testing/test-cases/dlsym-RTLD_NEXT.dtest/foo.c: -------------------------------------------------------------------------------- 1 | 2 | void foo() { } 3 | 4 | #if DYN 5 | void foo2() {} 6 | #endif 7 | -------------------------------------------------------------------------------- /testing/test-cases/dlsym-RTLD_SELF.dtest/foo.c: -------------------------------------------------------------------------------- 1 | 2 | void foo() { } 3 | 4 | #if DYN 5 | void foo2() {} 6 | #endif 7 | -------------------------------------------------------------------------------- /testing/test-cases/dlsym-handle.dtest/bar.c: -------------------------------------------------------------------------------- 1 | 2 | void bar() { } 3 | -------------------------------------------------------------------------------- /testing/test-cases/dlsym-handle.dtest/base.c: -------------------------------------------------------------------------------- 1 | 2 | void base() { } 3 | 4 | -------------------------------------------------------------------------------- /testing/test-cases/dlsym-handle.dtest/foo.c: -------------------------------------------------------------------------------- 1 | 2 | void foo() { } 3 | -------------------------------------------------------------------------------- /testing/test-cases/dlsym-in-interposed-malloc.dtest/main.c: -------------------------------------------------------------------------------- 1 | // BUILD: $CC main.c -o $BUILD_DIR/dlsym-in-interposed-malloc.exe 2 | // BUILD: $DYLD_ENV_VARS_ENABLE $BUILD_DIR/dlsym-in-interposed-malloc.exe 3 | // BUILD: $CC interposer.c -dynamiclib -o $BUILD_DIR/libmyalloc.dylib -install_name libmyalloc.dylib 4 | 5 | // RUN: DYLD_INSERT_LIBRARIES=libmyalloc.dylib ./dlsym-in-interposed-malloc.exe 6 | 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | int main() 13 | { 14 | printf("[BEGIN] dlsym-in-interposed-malloc\n"); 15 | 16 | // malloc should have been called when dyld3's libdyld was initialized, but 17 | // call it one more time anyway just to make sure its working 18 | (void)malloc(1); 19 | 20 | 21 | //printf("%p %p %p %p\n", p1, p2, p3, p4); 22 | printf("[PASS] dlsym-in-interposed-malloc\n"); 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /testing/test-cases/dlsym-re-export.dtest/foo.c: -------------------------------------------------------------------------------- 1 | int foo() 2 | { 3 | return 10; 4 | } 5 | 6 | -------------------------------------------------------------------------------- /testing/test-cases/dlsym-re-export.dtest/sub1.c: -------------------------------------------------------------------------------- 1 | int sub1() 2 | { 3 | return 1; 4 | } 5 | 6 | -------------------------------------------------------------------------------- /testing/test-cases/dlsym-re-export.dtest/sub2.c: -------------------------------------------------------------------------------- 1 | int sub2() 2 | { 3 | return 2; 4 | } 5 | 6 | -------------------------------------------------------------------------------- /testing/test-cases/dtrace.dtest/main.c: -------------------------------------------------------------------------------- 1 | // BUILD_ONLY: MacOSX 2 | 3 | // if we ever re-enable this on iOS we will need to add // BOOT_ARGS: dtrace_dof_mode=1 4 | 5 | // BUILD: /usr/sbin/dtrace -h -s main.d -o $TEMP_DIR/probes.h 6 | // BUILD: $CC main.c -I$TEMP_DIR -o $BUILD_DIR/dtrace.exe 7 | // BUILD: $DYLD_ENV_VARS_ENABLE $BUILD_DIR/dtrace.exe 8 | 9 | // RUN: $SUDO dtrace -l -n 'dyld_testing*:dtrace.exe:main:callback' -c ./dtrace.exe 10 | 11 | 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | #include "probes.h" 19 | 20 | int main() 21 | { 22 | printf("[BEGIN] dtrace\n"); 23 | 24 | DYLD_TESTING_CALLBACK(); 25 | 26 | if (!DYLD_TESTING_CALLBACK_ENABLED()) 27 | printf("[FAIL] dtrace: DYLD_TESTING_CALLBACK_ENABLED() returned false\n"); 28 | else 29 | printf("[PASS] dtrace\n"); 30 | 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /testing/test-cases/dtrace.dtest/main.d: -------------------------------------------------------------------------------- 1 | provider dyld_testing { 2 | probe callback(); 3 | }; 4 | -------------------------------------------------------------------------------- /testing/test-cases/dyld-insert-library-double.dtest/bar.c: -------------------------------------------------------------------------------- 1 | 2 | void foo() { } 3 | -------------------------------------------------------------------------------- /testing/test-cases/dyld-insert-library-double.dtest/foo.c: -------------------------------------------------------------------------------- 1 | 2 | void foo() { } 3 | -------------------------------------------------------------------------------- /testing/test-cases/dyld-insert-library-rpath.dtest/bar.c: -------------------------------------------------------------------------------- 1 | 2 | void foo() { } 3 | -------------------------------------------------------------------------------- /testing/test-cases/dyld-insert-library-rpath.dtest/baz.c: -------------------------------------------------------------------------------- 1 | 2 | void foo() { } 3 | -------------------------------------------------------------------------------- /testing/test-cases/dyld-insert-library-rpath.dtest/foo.c: -------------------------------------------------------------------------------- 1 | 2 | void foo() { } 3 | -------------------------------------------------------------------------------- /testing/test-cases/dyld_abort_payload.dtest/defSymbol.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | #if HAS_SYMBOL 4 | int slipperySymbol = 5; 5 | #endif 6 | -------------------------------------------------------------------------------- /testing/test-cases/dyld_abort_payload.dtest/emptyMain.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(int argc, const char* argv[]) 4 | { 5 | return 1; 6 | } 7 | 8 | -------------------------------------------------------------------------------- /testing/test-cases/dyld_abort_payload.dtest/foo.c: -------------------------------------------------------------------------------- 1 | 2 | void foo() 3 | { 4 | } 5 | 6 | -------------------------------------------------------------------------------- /testing/test-cases/dyld_abort_payload.dtest/useSymbol.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | extern int slipperySymbol; 4 | 5 | int main() 6 | { 7 | return slipperySymbol; 8 | } 9 | -------------------------------------------------------------------------------- /testing/test-cases/dyld_fork-locks.dest/main.c: -------------------------------------------------------------------------------- 1 | 2 | // BUILD: $CC main.c -o $BUILD_DIR/dyld_fork_test.exe 3 | 4 | // RUN: ./dyld_fork_test.exe 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | bool isParent = true; 11 | 12 | static void notifyBeforeFork(const struct mach_header* mh, intptr_t vmaddr_slide) 13 | { 14 | static bool sRanNotifier = false; 15 | if (sRanNotifier) 16 | return; 17 | sRanNotifier = true; 18 | 19 | // fork and exec child 20 | pid_t sChildPid = fork(); 21 | if ( sChildPid < 0 ) { 22 | printf("[FAIL] dyld_fork_test didn't fork\n"); 23 | return; 24 | } 25 | if ( sChildPid == 0 ) { 26 | // child side 27 | isParent = false; 28 | } 29 | } 30 | 31 | int main(int argc, const char* argv[]) 32 | { 33 | printf("[BEGIN] dyld_fork_test\n"); 34 | 35 | _dyld_register_func_for_add_image(¬ifyBeforeFork); 36 | 37 | if (isParent) { 38 | printf("[PASS] dyld_fork_test\n"); 39 | } 40 | 41 | return 0; 42 | } -------------------------------------------------------------------------------- /testing/test-cases/dyld_get_sdk_version.dtest/bad.txt: -------------------------------------------------------------------------------- 1 | bad file 2 | -------------------------------------------------------------------------------- /testing/test-cases/dyld_has_inserted_or_interposing_libraries.dtest/foo.c: -------------------------------------------------------------------------------- 1 | 2 | void foo() { } 3 | -------------------------------------------------------------------------------- /testing/test-cases/dyld_has_inserted_or_interposing_libraries.dtest/interposer.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | extern void foo(); 5 | 6 | void my_foo() { } 7 | 8 | DYLD_INTERPOSE(my_foo, foo); 9 | -------------------------------------------------------------------------------- /testing/test-cases/dyld_image_path_containing_address.dtest/main.c: -------------------------------------------------------------------------------- 1 | 2 | // BUILD: $CC main.c -o $BUILD_DIR/dyld_image_path_containing_address-test.exe 3 | 4 | // RUN: ./dyld_image_path_containing_address-test.exe 5 | 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | 14 | int main() 15 | { 16 | printf("[BEGIN] dyld_image_path_containing_address-test\n"); 17 | 18 | int count = _dyld_image_count(); 19 | for (int i=0; i < count; ++i) { 20 | const struct mach_header* mh = _dyld_get_image_header(i); 21 | const char* name1 = _dyld_get_image_name(i); 22 | const char* name2 = dyld_image_path_containing_address(mh); 23 | if ( strcmp(name1, name2) != 0 ) { 24 | printf("[FAIL] dyld_image_path_containing_address-test: %s != %s\n", name1, name2); 25 | return 0; 26 | } 27 | } 28 | 29 | printf("[PASS] dyld_image_path_containing_address-test\n"); 30 | return 0; 31 | } 32 | 33 | -------------------------------------------------------------------------------- /testing/test-cases/dyld_need_closure.dtest/foo.c: -------------------------------------------------------------------------------- 1 | int main() 2 | { 3 | return 0; 4 | } 5 | -------------------------------------------------------------------------------- /testing/test-cases/dyld_need_closure.dtest/main.c: -------------------------------------------------------------------------------- 1 | 2 | // BUILD: $CC main.c -o $BUILD_DIR/foo.exe 3 | // BUILD: $CC main.c -o $BUILD_DIR/dyld_need_closure.exe 4 | 5 | // RUN: ./dyld_need_closure.exe 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | 12 | int main() 13 | { 14 | printf("[BEGIN] dyld_need_closure\n"); 15 | 16 | // We only support trying to save to containerised paths, so anything not 17 | // of that form should fail 18 | if ( !dyld_need_closure("./foo.exe", "/tmp/Containers/Data/") ) { 19 | printf("[FAIL] dyld_closure: Should have needed a closure for containerised path\n"); 20 | return 0; 21 | } 22 | 23 | if ( dyld_need_closure("./foo.exe", "/tmp/Containers/Data2/") ) { 24 | printf("[FAIL] dyld_closure: Should have rejected a closure for non-containerised path\n"); 25 | return 0; 26 | } 27 | 28 | printf("[PASS] dyld_need_closure\n"); 29 | 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /testing/test-cases/dyld_process_info.dtest/File: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/antons/dyld-shared-cache-big-sur/abdd035bdfda33998cc80cd06b625cd99563ca33/testing/test-cases/dyld_process_info.dtest/File -------------------------------------------------------------------------------- /testing/test-cases/dyld_process_info.dtest/linksWithCF.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | 6 | __attribute__((section("__DATA,__allow_alt_plat"))) uint64_t dummy; 7 | 8 | int main() 9 | { 10 | (void)kill(getpid(), SIGSTOP); 11 | return 0; 12 | } 13 | 14 | -------------------------------------------------------------------------------- /testing/test-cases/dyld_process_info_notify.dtest/foo.c: -------------------------------------------------------------------------------- 1 | 2 | void foo() { 3 | } 4 | 5 | -------------------------------------------------------------------------------- /testing/test-cases/dyld_process_info_notify.dtest/target.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | 10 | 11 | int main(int argc, const char* argv[]) 12 | { 13 | if ( (argc > 1) && (strcmp(argv[1], "suspend-in-main") == 0) ) 14 | (void)kill(getpid(), SIGSTOP); 15 | 16 | for (int i=0; i < 3; ++i) { 17 | void* h = dlopen("./libfoo.dylib", 0); 18 | dlclose(h); 19 | } 20 | 21 | return 0; 22 | } 23 | 24 | -------------------------------------------------------------------------------- /testing/test-cases/dyld_process_info_unload.dtest/foo.c: -------------------------------------------------------------------------------- 1 | void foo() {} 2 | -------------------------------------------------------------------------------- /testing/test-cases/dyld_process_info_unload.dtest/target.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | 9 | 10 | int main(int argc, const char* argv[]) 11 | { 12 | //fprintf(stderr, "target starting\n"); 13 | usleep(1000); 14 | // load and unload in a loop 15 | for (int i=1; i < 10000; ++i) { 16 | void* h = dlopen("./libfoo.dylib", 0); 17 | usleep(100000/(i*100)); 18 | dlclose(h); 19 | } 20 | //fprintf(stderr, "target done\n"); 21 | 22 | return 0; 23 | } 24 | 25 | -------------------------------------------------------------------------------- /testing/test-cases/dyld_shared_cache_some_image_overridden.dtest/myzlib.c: -------------------------------------------------------------------------------- 1 | const char* zlibVersion() 2 | { 3 | return "my"; 4 | } 5 | -------------------------------------------------------------------------------- /testing/test-cases/dyld_shared_cache_some_image_overridden.dtest/reexported-myzlib.c: -------------------------------------------------------------------------------- 1 | const char* zlibVersion() 2 | { 3 | return "my"; 4 | } 5 | -------------------------------------------------------------------------------- /testing/test-cases/dyld_shared_cache_some_image_overridden.dtest/reexporter.c: -------------------------------------------------------------------------------- 1 | 2 | int foo() { 3 | return 0; 4 | } 5 | -------------------------------------------------------------------------------- /testing/test-cases/dylib-re-export-old-format.dtest/bar.c: -------------------------------------------------------------------------------- 1 | 2 | int bar() { 3 | return 42; 4 | } 5 | 6 | -------------------------------------------------------------------------------- /testing/test-cases/dylib-re-export-old-format.dtest/foo.c: -------------------------------------------------------------------------------- 1 | 2 | int foo = 1; 3 | 4 | -------------------------------------------------------------------------------- /testing/test-cases/dylib-re-export-old-format.dtest/main.c: -------------------------------------------------------------------------------- 1 | // BUILD_ONLY: MacOSX 2 | // BUILD_MIN_OS: 10.5 3 | // BUILD: $CC bar.c -dynamiclib -install_name $RUN_DIR/libbar.dylib -o $BUILD_DIR/libbar.dylib -nostdlib -ldylib1.o 4 | // BUILD: $CC foo.c -dynamiclib $BUILD_DIR/libbar.dylib -sub_library libbar -install_name $RUN_DIR/libfoo.dylib -o $BUILD_DIR/libfoo.dylib -nostdlib -ldylib1.o 5 | // BUILD: $CC main.c -o $BUILD_DIR/dylib-re-export.exe $BUILD_DIR/libfoo.dylib -L$BUILD_DIR -nostdlib -lSystem -lcrt1.10.5.o 6 | 7 | // RUN: ./dylib-re-export.exe 8 | 9 | 10 | #include 11 | 12 | extern int bar(); 13 | 14 | 15 | int main() 16 | { 17 | printf("[BEGIN] dylib-re-export-old-format\n"); 18 | if ( bar() == 42 ) 19 | printf("[PASS] dylib-re-export-old-format\n"); 20 | else 21 | printf("[FAIL] dylib-re-export-old-format, wrong value\n"); 22 | 23 | return 0; 24 | } 25 | 26 | 27 | -------------------------------------------------------------------------------- /testing/test-cases/dylib-re-export.dtest/bar.c: -------------------------------------------------------------------------------- 1 | 2 | int bar() { 3 | return 42; 4 | } 5 | 6 | -------------------------------------------------------------------------------- /testing/test-cases/dylib-re-export.dtest/foo.c: -------------------------------------------------------------------------------- 1 | 2 | int foo = 1; 3 | 4 | -------------------------------------------------------------------------------- /testing/test-cases/dylib-re-export.dtest/main.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | // BUILD: $CC bar.c -dynamiclib -o $BUILD_DIR/libbar.dylib -install_name $RUN_DIR/libbar.dylib 4 | // BUILD: $CC foo.c -dynamiclib $BUILD_DIR/libbar.dylib -sub_library libbar -install_name $RUN_DIR/libfoo.dylib -o $BUILD_DIR/libfoo.dylib 5 | // BUILD: $CC main.c -o $BUILD_DIR/dylib-re-export.exe $BUILD_DIR/libfoo.dylib -L$BUILD_DIR 6 | 7 | // RUN: ./dylib-re-export.exe 8 | 9 | 10 | #include 11 | 12 | extern int bar(); 13 | 14 | 15 | int main() 16 | { 17 | printf("[BEGIN] dylib-re-export\n"); 18 | if ( bar() == 42 ) 19 | printf("[PASS] dylib-re-export\n"); 20 | else 21 | printf("[FAIL] dylib-re-export, wrong value\n"); 22 | 23 | return 0; 24 | } 25 | 26 | 27 | -------------------------------------------------------------------------------- /testing/test-cases/dylib-static-link.dtest/foo.c: -------------------------------------------------------------------------------- 1 | 2 | int foo = 42; 3 | 4 | -------------------------------------------------------------------------------- /testing/test-cases/dylib-static-link.dtest/missing.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | printf("[BEGIN] dylib-static-link missing\n"); 7 | printf("[FAIL] dylib-static-link missing, program should not have launched\n"); 8 | 9 | return 0; 10 | } 11 | 12 | 13 | -------------------------------------------------------------------------------- /testing/test-cases/dylib-static-link.dtest/present.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | // BUILD: $CC foo.c -dynamiclib -o $BUILD_DIR/libfoo.dylib -install_name $RUN_DIR/libfoo.dylib 4 | // BUILD: $CC present.c $BUILD_DIR/libfoo.dylib -o $BUILD_DIR/dylib-static-present.exe 5 | // BUILD: $CC foo.c -dynamiclib -o $TEMP_DIR/libfoo2.dylib -install_name $RUN_DIR/libfoomissing.dylib 6 | // BUILD: $CC missing.c $TEMP_DIR/libfoo2.dylib -o $BUILD_DIR/dylib-static-missing.exe 7 | 8 | // RUN: ./dylib-static-present.exe 9 | // RUN: NOCR_TEST_NAME="dylib-static-link missing" $REQUIRE_CRASH ./dylib-static-missing.exe 10 | 11 | 12 | #include 13 | 14 | extern int foo; 15 | 16 | 17 | int main() 18 | { 19 | printf("[BEGIN] dylib-static-link present\n"); 20 | if ( foo == 42 ) 21 | printf("[PASS] dylib-static-link present\n"); 22 | else 23 | printf("[FAIL] dylib-static-link present, wrong value\n"); 24 | 25 | return 0; 26 | } 27 | 28 | 29 | -------------------------------------------------------------------------------- /testing/test-cases/dylib-static-weak-link.dtest/foo.c: -------------------------------------------------------------------------------- 1 | 2 | int foo = 42; 3 | 4 | -------------------------------------------------------------------------------- /testing/test-cases/dylib-static-weak-link.dtest/missing.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | extern int foo __attribute__((weak_import)); 5 | 6 | 7 | int main() 8 | { 9 | printf("[BEGIN] dylib-static-weak-link missing\n"); 10 | // dylib won't be found at runtime, so &foo should be NULL 11 | if ( &foo == NULL ) 12 | printf("[PASS] dylib-static-weak-link missing\n"); 13 | else 14 | printf("[FAIL] dylib-static-weak-link missing, &foo != NULL\n"); 15 | 16 | return 0; 17 | } 18 | 19 | 20 | -------------------------------------------------------------------------------- /testing/test-cases/env-DYLD_FALLBACK_FRAMEWORK_PATH.dtest/foo.c: -------------------------------------------------------------------------------- 1 | int foo() 2 | { 3 | return VALUE; 4 | } 5 | 6 | -------------------------------------------------------------------------------- /testing/test-cases/env-DYLD_FALLBACK_FRAMEWORK_PATH.dtest/main.c: -------------------------------------------------------------------------------- 1 | 2 | // BUILD: mkdir -p $TEMP_DIR/Foo.framework $BUILD_DIR/FallbackFrameworks/Foo.framework 3 | // BUILD: $CC foo.c -dynamiclib -o $TEMP_DIR/Foo.framework/Foo -install_name $RUN_DIR/Foo.framework/Foo -DVALUE=1 4 | // BUILD: $CC foo.c -dynamiclib -o $BUILD_DIR/FallbackFrameworks/Foo.framework/Foo -install_name $RUN_DIR/Foo.framework/Foo -DVALUE=42 5 | // BUILD: $CC main.c -o $BUILD_DIR/env-DYLD_FALLBACK_FRAMEWORK_PATH.exe $TEMP_DIR/Foo.framework/Foo 6 | // BUILD: $DYLD_ENV_VARS_ENABLE $BUILD_DIR/env-DYLD_FALLBACK_FRAMEWORK_PATH.exe 7 | 8 | // RUN: DYLD_FALLBACK_FRAMEWORK_PATH=$RUN_DIR/FallbackFrameworks/ ./env-DYLD_FALLBACK_FRAMEWORK_PATH.exe 9 | 10 | #include 11 | #include 12 | 13 | extern int foo(); 14 | 15 | int main() 16 | { 17 | printf("[BEGIN] env-DYLD_FALLBACK_FRAMEWORK_PATH\n"); 18 | 19 | if ( foo() == 42 ) 20 | printf("[PASS] env-DYLD_FALLBACK_FRAMEWORK_PATH\n"); 21 | else 22 | printf("[FAIL] env-DYLD_FALLBACK_FRAMEWORK_PATH\n"); 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /testing/test-cases/env-DYLD_FALLBACK_LIBRARY_PATH.dtest/foo.c: -------------------------------------------------------------------------------- 1 | int foo() 2 | { 3 | return VALUE; 4 | } 5 | 6 | -------------------------------------------------------------------------------- /testing/test-cases/env-DYLD_FALLBACK_LIBRARY_PATH.dtest/main.c: -------------------------------------------------------------------------------- 1 | 2 | // BUILD: mkdir -p $BUILD_DIR/fallback 3 | // BUILD: $CC foo.c -dynamiclib -o $TEMP_DIR/libfoo.dylib -install_name $RUN_DIR/libfoo.dylib -DVALUE=1 4 | // BUILD: $CC foo.c -dynamiclib -o $BUILD_DIR/fallback/libfoo.dylib -install_name $RUN_DIR/libfoo.dylib -DVALUE=42 5 | // BUILD: $CC main.c -o $BUILD_DIR/env-DYLD_FALLBACK_LIBRARY_PATH.exe $TEMP_DIR/libfoo.dylib 6 | // BUILD: $DYLD_ENV_VARS_ENABLE $BUILD_DIR/env-DYLD_FALLBACK_LIBRARY_PATH.exe 7 | 8 | // RUN: DYLD_FALLBACK_LIBRARY_PATH=$RUN_DIR/fallback/ ./env-DYLD_FALLBACK_LIBRARY_PATH.exe 9 | 10 | #include 11 | 12 | extern int foo(); 13 | 14 | int main() 15 | { 16 | printf("[BEGIN] env-DYLD_FALLBACK_LIBRARY_PATH\n"); 17 | 18 | if ( foo() == 42 ) 19 | printf("[PASS] env-DYLD_FALLBACK_LIBRARY_PATH\n"); 20 | else 21 | printf("[FAIL] env-DYLD_FALLBACK_LIBRARY_PATH\n"); 22 | 23 | return 0; 24 | } 25 | 26 | -------------------------------------------------------------------------------- /testing/test-cases/env-DYLD_FRAMEWORK_PATH.dtest/foo.c: -------------------------------------------------------------------------------- 1 | int foo() 2 | { 3 | return VALUE; 4 | } 5 | 6 | -------------------------------------------------------------------------------- /testing/test-cases/env-DYLD_IMAGE_SUFFIX.dtest/bar.c: -------------------------------------------------------------------------------- 1 | int bar() 2 | { 3 | return VALUE; 4 | } 5 | 6 | -------------------------------------------------------------------------------- /testing/test-cases/env-DYLD_IMAGE_SUFFIX.dtest/foo.c: -------------------------------------------------------------------------------- 1 | int foo() 2 | { 3 | return VALUE; 4 | } 5 | 6 | -------------------------------------------------------------------------------- /testing/test-cases/env-DYLD_LIBRARY_PATH-cache.dtest/myzlib.c: -------------------------------------------------------------------------------- 1 | const char* zlibVersion() 2 | { 3 | return "my"; 4 | } 5 | -------------------------------------------------------------------------------- /testing/test-cases/env-DYLD_LIBRARY_PATH-cache.dtest/reexported-myzlib.c: -------------------------------------------------------------------------------- 1 | const char* zlibVersion() 2 | { 3 | return "my"; 4 | } 5 | -------------------------------------------------------------------------------- /testing/test-cases/env-DYLD_LIBRARY_PATH-cache.dtest/reexporter.c: -------------------------------------------------------------------------------- 1 | 2 | int foo() { 3 | return 0; 4 | } 5 | -------------------------------------------------------------------------------- /testing/test-cases/env-DYLD_LIBRARY_PATH.dtest/foo.c: -------------------------------------------------------------------------------- 1 | int foo() 2 | { 3 | return VALUE; 4 | } 5 | 6 | -------------------------------------------------------------------------------- /testing/test-cases/env-DYLD_LIBRARY_PATH.dtest/main.c: -------------------------------------------------------------------------------- 1 | 2 | // BUILD: mkdir -p $BUILD_DIR/door1 $BUILD_DIR/door2 3 | // BUILD: $CC foo.c -dynamiclib -o $BUILD_DIR/door1/libfoo.dylib -install_name $RUN_DIR/door1/libfoo.dylib -DVALUE=1 4 | // BUILD: $CC foo.c -dynamiclib -o $BUILD_DIR/door2/libfoo.dylib -install_name $RUN_DIR/door2/libfoo.dylib -DVALUE=42 5 | // BUILD: $CC main.c -o $BUILD_DIR/env-DYLD_LIBRARY_PATH.exe $BUILD_DIR/door1/libfoo.dylib 6 | // BUILD: $DYLD_ENV_VARS_ENABLE $BUILD_DIR/env-DYLD_LIBRARY_PATH.exe 7 | 8 | // RUN: ./env-DYLD_LIBRARY_PATH.exe 9 | // RUN: DYLD_LIBRARY_PATH=$RUN_DIR/door2/ ./env-DYLD_LIBRARY_PATH.exe 10 | 11 | #include 12 | #include 13 | 14 | extern int foo(); 15 | 16 | int main() 17 | { 18 | int expected = (getenv("DYLD_LIBRARY_PATH") != NULL) ? 42 : 1; 19 | 20 | printf("[BEGIN] env-DYLD_LIBRARY_PATH, expect %d\n", expected); 21 | 22 | if ( foo() == expected ) 23 | printf("[PASS] env-DYLD_LIBRARY_PATH\n"); 24 | else 25 | printf("[FAIL] env-DYLD_LIBRARY_PATH\n"); 26 | 27 | return 0; 28 | } 29 | 30 | -------------------------------------------------------------------------------- /testing/test-cases/env-DYLD_VERSIONED_FRAMEWORK_PATH.dtest/foo.c: -------------------------------------------------------------------------------- 1 | 2 | int foo() 3 | { 4 | return RESULT; 5 | } 6 | -------------------------------------------------------------------------------- /testing/test-cases/env-DYLD_VERSIONED_LIBRARY_PATH.dtest/foo.c: -------------------------------------------------------------------------------- 1 | 2 | int foo() 3 | { 4 | return RESULT; 5 | } 6 | -------------------------------------------------------------------------------- /testing/test-cases/flat-namespace-absolute-symbol.dtest/foo.s: -------------------------------------------------------------------------------- 1 | 2 | .global _myAbs1 3 | _myAbs1 = 0 4 | 5 | -------------------------------------------------------------------------------- /testing/test-cases/flat-namespace-absolute-symbol.dtest/main.c: -------------------------------------------------------------------------------- 1 | // BUILD_ONLY: MacOSX 2 | 3 | // BUILD: $CC foo.s -dynamiclib -o $BUILD_DIR/libfoo.dylib -install_name $RUN_DIR/libfoo.dylib 4 | // BUILD: $CC main.c $BUILD_DIR/libfoo.dylib -o $BUILD_DIR/flat-namespace.exe -flat_namespace 5 | 6 | // RUN: ./flat-namespace.exe 7 | 8 | 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | extern int myAbs1; 15 | int* ptr = &myAbs1; 16 | 17 | int main() 18 | { 19 | printf("[BEGIN] flat-namespace-absolute-symbol\n"); 20 | 21 | if ( ptr != 0 ) { 22 | printf("[FAIL] absolute symbol not bound to zero with flat lookup\n"); 23 | return 0; 24 | } 25 | 26 | printf("[PASS] flat-namespace-absolute-symbol\n"); 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /testing/test-cases/flat-namespace.dtest/foo.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | char buffer[100000]; 6 | char* p = buffer; 7 | 8 | void* malloc(size_t size) 9 | { 10 | // bump ptr allocate and fill second half with '#' 11 | char* result = p; 12 | p += size; 13 | memset(result, '#', size); 14 | p = (char*)(((long)p + 15) & (-16)); // 16-byte align next malloc 15 | return result; 16 | } 17 | 18 | void free(void* p) 19 | { 20 | } 21 | 22 | -------------------------------------------------------------------------------- /testing/test-cases/flat-namespace.dtest/main.c: -------------------------------------------------------------------------------- 1 | // BUILD_ONLY: MacOSX 2 | 3 | // BUILD: $CC foo.c -dynamiclib -o $BUILD_DIR/libfoo.dylib -install_name $RUN_DIR/libfoo.dylib 4 | // BUILD: $CC main.c $BUILD_DIR/libfoo.dylib -o $BUILD_DIR/flat-namespace.exe -flat_namespace 5 | 6 | // RUN: ./flat-namespace.exe 7 | 8 | 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | int main() 15 | { 16 | printf("[BEGIN] flat-namespace\n"); 17 | 18 | // check that the malloc in libfoo.dylib was used by looking at the content the allocated buffer 19 | // strncmp is tricky for flat namespace because it is re-exporte and renamed 20 | char* p1 = malloc(10); 21 | if ( strncmp(p1, "##########", 10) != 0 ) { 22 | printf("[FAIL] malloc() from main executable not interposed\n"); 23 | return 0; 24 | } 25 | 26 | printf("[PASS] flat-namespace\n"); 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /testing/test-cases/image_infos-uuids.dtest/foo.c: -------------------------------------------------------------------------------- 1 | int foo() 2 | { 3 | return 10; 4 | } 5 | 6 | -------------------------------------------------------------------------------- /testing/test-cases/init-term-segments.dtest/foo.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | bool ranInit = false; 15 | bool* gRanTerm = NULL; 16 | 17 | #define SUPPORT_CUSTOM_SEGMENTS !(__arm64e__ || (__arm64__ && __ARM64_ARCH_8_32__)) 18 | 19 | #if SUPPORT_CUSTOM_SEGMENTS 20 | __attribute__((section(("__SOMETEXT,__text")))) 21 | #endif 22 | __attribute__((constructor)) 23 | void myinit() 24 | { 25 | ranInit = true; 26 | } 27 | 28 | bool foo(bool* ptr) { 29 | if (!ranInit) 30 | return false; 31 | gRanTerm = ptr; 32 | return true; 33 | } 34 | 35 | #if SUPPORT_CUSTOM_SEGMENTS 36 | __attribute__((section(("__MORETEXT,__text")))) 37 | #endif 38 | __attribute__((destructor)) 39 | void myterm() 40 | { 41 | if ( gRanTerm != NULL ) 42 | *gRanTerm = true; 43 | } -------------------------------------------------------------------------------- /testing/test-cases/interpose-malloc.dtest/foo.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | void* myalloc1(size_t sz) 5 | { 6 | return malloc(sz); 7 | } 8 | 9 | void* (*pMalloc)(size_t) = &malloc; 10 | 11 | void* myalloc2(size_t sz) 12 | { 13 | return (*pMalloc)(sz); 14 | } 15 | 16 | -------------------------------------------------------------------------------- /testing/test-cases/interpose-malloc.dtest/interposer.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | 6 | 7 | void* mymalloc(size_t size) 8 | { 9 | // bump ptr allocate twice the size and fills with '#' 10 | char* result = malloc(size*2); 11 | memset(result, '#', size*2); 12 | return result; 13 | } 14 | 15 | void myfree(void* p) 16 | { 17 | free(p); 18 | } 19 | 20 | DYLD_INTERPOSE(mymalloc, malloc) 21 | DYLD_INTERPOSE(myfree, free) 22 | -------------------------------------------------------------------------------- /testing/test-cases/interpose-resolver.dtest/foo.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | static int foo_ten() 5 | { 6 | return 10; 7 | } 8 | 9 | 10 | // This foo is a "resolver" function that return the actual address of "foo" 11 | void* foo() 12 | { 13 | __asm__(".symbol_resolver _foo"); // magic until we have compiler support 14 | return &foo_ten; 15 | } 16 | 17 | 18 | -------------------------------------------------------------------------------- /testing/test-cases/interpose-resolver.dtest/interposer.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | extern int foo(); 6 | 7 | int myfoo() 8 | { 9 | return 11; 10 | } 11 | 12 | 13 | DYLD_INTERPOSE(myfoo, foo) 14 | -------------------------------------------------------------------------------- /testing/test-cases/interpose-then-dlopen.dtest/bar.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | extern int interposableFoo(); 5 | 6 | int (*pFoo)() = &interposableFoo; 7 | 8 | int callFoo() 9 | { 10 | return (*pFoo)(); 11 | } 12 | 13 | extern int interposableBar(); 14 | 15 | int (*pBar)() = &interposableBar; 16 | 17 | int callBar() 18 | { 19 | return (*pBar)(); 20 | } 21 | 22 | -------------------------------------------------------------------------------- /testing/test-cases/interpose-then-dlopen.dtest/foo.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | extern int interposableFoo(); 6 | int (*pFoo)() = &interposableFoo; 7 | 8 | int callFoo() 9 | { 10 | return (*pFoo)(); 11 | } 12 | 13 | extern int interposableBar(); 14 | 15 | int myBar() { 16 | return 2; 17 | } 18 | 19 | int (*pBar)() = &myBar; 20 | 21 | int callBar() 22 | { 23 | return (*pBar)(); 24 | } 25 | 26 | DYLD_INTERPOSE(myBar, interposableBar) 27 | -------------------------------------------------------------------------------- /testing/test-cases/interpose-then-dlopen.dtest/fooimpl.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | int interposableFoo() { 4 | return 100; 5 | } 6 | 7 | 8 | int interposableBar() { 9 | return 100; 10 | } 11 | -------------------------------------------------------------------------------- /testing/test-cases/interpose-then-dlopen.dtest/interposable.txt: -------------------------------------------------------------------------------- 1 | _interposableFoo 2 | _interposableBar 3 | -------------------------------------------------------------------------------- /testing/test-cases/interpose-then-dlopen.dtest/interposer.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | 6 | 7 | int myFoo() { 8 | return 4; 9 | } 10 | 11 | int interposableFoo(); 12 | 13 | DYLD_INTERPOSE(myFoo, interposableFoo) 14 | -------------------------------------------------------------------------------- /testing/test-cases/interpose-weak.dtest/foo.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | int foo1() { return 1; } 5 | 6 | int foo2() { return 2; } 7 | 8 | #ifndef NO_FOO34 9 | int foo3() { return 3; } 10 | int foo4() { return 4; } 11 | #endif 12 | 13 | -------------------------------------------------------------------------------- /testing/test-cases/interpose-weak.dtest/interposer.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | extern int foo2(); 5 | extern int foo4() __attribute__((weak_import)); 6 | 7 | 8 | 9 | int myfoo2() { return 12; } 10 | int myfoo4() { return 14; } 11 | 12 | 13 | 14 | DYLD_INTERPOSE(myfoo2, foo2) 15 | DYLD_INTERPOSE(myfoo4, foo4) 16 | -------------------------------------------------------------------------------- /testing/test-cases/launch-image-cache.dtest/foo1.c: -------------------------------------------------------------------------------- 1 | int foo1() { return 1; }; 2 | -------------------------------------------------------------------------------- /testing/test-cases/launch-image-cache.dtest/foo10.c: -------------------------------------------------------------------------------- 1 | int foo10() { return 10; }; 2 | -------------------------------------------------------------------------------- /testing/test-cases/launch-image-cache.dtest/foo11.c: -------------------------------------------------------------------------------- 1 | int foo11() { return 11; }; 2 | -------------------------------------------------------------------------------- /testing/test-cases/launch-image-cache.dtest/foo12.c: -------------------------------------------------------------------------------- 1 | int foo12() { return 12; }; 2 | -------------------------------------------------------------------------------- /testing/test-cases/launch-image-cache.dtest/foo13.c: -------------------------------------------------------------------------------- 1 | int foo13() { return 13; }; 2 | -------------------------------------------------------------------------------- /testing/test-cases/launch-image-cache.dtest/foo14.c: -------------------------------------------------------------------------------- 1 | int foo14() { return 14; }; 2 | -------------------------------------------------------------------------------- /testing/test-cases/launch-image-cache.dtest/foo15.c: -------------------------------------------------------------------------------- 1 | int foo15() { return 15; }; 2 | -------------------------------------------------------------------------------- /testing/test-cases/launch-image-cache.dtest/foo16.c: -------------------------------------------------------------------------------- 1 | int foo16() { return 16; }; 2 | -------------------------------------------------------------------------------- /testing/test-cases/launch-image-cache.dtest/foo17.c: -------------------------------------------------------------------------------- 1 | int foo17() { return 17; }; 2 | -------------------------------------------------------------------------------- /testing/test-cases/launch-image-cache.dtest/foo18.c: -------------------------------------------------------------------------------- 1 | int foo18() { return 18; }; 2 | -------------------------------------------------------------------------------- /testing/test-cases/launch-image-cache.dtest/foo19.c: -------------------------------------------------------------------------------- 1 | int foo19() { return 19; }; 2 | -------------------------------------------------------------------------------- /testing/test-cases/launch-image-cache.dtest/foo2.c: -------------------------------------------------------------------------------- 1 | int foo2() { return 2; }; 2 | -------------------------------------------------------------------------------- /testing/test-cases/launch-image-cache.dtest/foo20.c: -------------------------------------------------------------------------------- 1 | int foo20() { return 20; }; 2 | -------------------------------------------------------------------------------- /testing/test-cases/launch-image-cache.dtest/foo21.c: -------------------------------------------------------------------------------- 1 | int foo21() { return 21; }; 2 | -------------------------------------------------------------------------------- /testing/test-cases/launch-image-cache.dtest/foo22.c: -------------------------------------------------------------------------------- 1 | int foo22() { return 22; }; 2 | -------------------------------------------------------------------------------- /testing/test-cases/launch-image-cache.dtest/foo23.c: -------------------------------------------------------------------------------- 1 | int foo23() { return 23; }; 2 | -------------------------------------------------------------------------------- /testing/test-cases/launch-image-cache.dtest/foo24.c: -------------------------------------------------------------------------------- 1 | int foo24() { return 24; }; 2 | -------------------------------------------------------------------------------- /testing/test-cases/launch-image-cache.dtest/foo25.c: -------------------------------------------------------------------------------- 1 | int foo25() { return 25; }; 2 | -------------------------------------------------------------------------------- /testing/test-cases/launch-image-cache.dtest/foo26.c: -------------------------------------------------------------------------------- 1 | int foo26() { return 26; }; 2 | -------------------------------------------------------------------------------- /testing/test-cases/launch-image-cache.dtest/foo27.c: -------------------------------------------------------------------------------- 1 | int foo27() { return 27; }; 2 | -------------------------------------------------------------------------------- /testing/test-cases/launch-image-cache.dtest/foo28.c: -------------------------------------------------------------------------------- 1 | int foo28() { return 28; }; 2 | -------------------------------------------------------------------------------- /testing/test-cases/launch-image-cache.dtest/foo29.c: -------------------------------------------------------------------------------- 1 | int foo29() { return 29; }; 2 | -------------------------------------------------------------------------------- /testing/test-cases/launch-image-cache.dtest/foo3.c: -------------------------------------------------------------------------------- 1 | int foo3() { return 3; }; 2 | -------------------------------------------------------------------------------- /testing/test-cases/launch-image-cache.dtest/foo30.c: -------------------------------------------------------------------------------- 1 | int foo30() { return 30; }; 2 | -------------------------------------------------------------------------------- /testing/test-cases/launch-image-cache.dtest/foo31.c: -------------------------------------------------------------------------------- 1 | int foo31() { return 31; }; 2 | -------------------------------------------------------------------------------- /testing/test-cases/launch-image-cache.dtest/foo32.c: -------------------------------------------------------------------------------- 1 | int foo32() { return 32; }; 2 | -------------------------------------------------------------------------------- /testing/test-cases/launch-image-cache.dtest/foo4.c: -------------------------------------------------------------------------------- 1 | int foo4() { return 4; }; 2 | -------------------------------------------------------------------------------- /testing/test-cases/launch-image-cache.dtest/foo5.c: -------------------------------------------------------------------------------- 1 | int foo5() { return 5; }; 2 | -------------------------------------------------------------------------------- /testing/test-cases/launch-image-cache.dtest/foo6.c: -------------------------------------------------------------------------------- 1 | int foo6() { return 6; }; 2 | -------------------------------------------------------------------------------- /testing/test-cases/launch-image-cache.dtest/foo7.c: -------------------------------------------------------------------------------- 1 | int foo7() { return 7; }; 2 | -------------------------------------------------------------------------------- /testing/test-cases/launch-image-cache.dtest/foo8.c: -------------------------------------------------------------------------------- 1 | int foo8() { return 8; }; 2 | -------------------------------------------------------------------------------- /testing/test-cases/launch-image-cache.dtest/foo9.c: -------------------------------------------------------------------------------- 1 | int foo9() { return 9; }; 2 | -------------------------------------------------------------------------------- /testing/test-cases/lazy-symbol-missing.dtest/foo.c: -------------------------------------------------------------------------------- 1 | 2 | void bar() 3 | { 4 | } 5 | 6 | #if HAS_SYMBOL 7 | int slipperySymbol() 8 | { 9 | return 10; 10 | } 11 | #endif 12 | 13 | 14 | -------------------------------------------------------------------------------- /testing/test-cases/lazy-symbol-missing.dtest/main-call.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include 4 | 5 | 6 | extern int slipperySymbol(); 7 | 8 | 9 | int main(int argc, const char* argv[]) 10 | { 11 | slipperySymbol(); 12 | return 0; 13 | } 14 | 15 | -------------------------------------------------------------------------------- /testing/test-cases/missing-weak-def.dtest/bar-empty.c: -------------------------------------------------------------------------------- 1 | 2 | int not_bar() { 3 | return 0; 4 | } -------------------------------------------------------------------------------- /testing/test-cases/missing-weak-def.dtest/bar.c: -------------------------------------------------------------------------------- 1 | 2 | int bar() { 3 | return 0; 4 | } -------------------------------------------------------------------------------- /testing/test-cases/missing-weak-def.dtest/main.c: -------------------------------------------------------------------------------- 1 | 2 | // BUILD: $CC bar.c -dynamiclib -install_name $RUN_DIR/libbar.dylib -o $TEMP_DIR/libbar.dylib 3 | // BUILD: $CC bar-empty.c -dynamiclib -install_name $BUILD_DIR/libbar.dylib -o $BUILD_DIR/libbar.dylib 4 | // BUILD: $CC main.c $TEMP_DIR/libbar.dylib -o $BUILD_DIR/missing-weak-def.exe 5 | 6 | // RUN: ./missing-weak-def.exe 7 | 8 | // bar is a weak_import weak bind and the libbar we have at runtime is missing that symbol 9 | 10 | 11 | #include 12 | #include 13 | 14 | __attribute__((weak)) 15 | __attribute__((weak_import)) 16 | int bar(); 17 | 18 | int main() 19 | { 20 | printf("[BEGIN] missing-weak-def\n"); 21 | 22 | if (&bar) { 23 | printf("[FAIL] missing-weak-def\n"); 24 | return 0; 25 | } 26 | 27 | printf("[PASS] missing-weak-def\n"); 28 | return 0; 29 | } 30 | 31 | -------------------------------------------------------------------------------- /testing/test-cases/no-shared-cache.dtest/main.c: -------------------------------------------------------------------------------- 1 | // BUILD_ONLY: MacOSX 2 | 3 | // BUILD: $CC main.c -framework AppKit -o $BUILD_DIR/no_shared_cache.exe 4 | 5 | // RUN: DYLD_SHARED_REGION=avoid ./no_shared_cache.exe 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | 14 | // This program links with AppKit which in dyld3 mode stress tests building closures when there is no dyld shared cache 15 | 16 | int main() 17 | { 18 | printf("[BEGIN] no-shared-cache\n"); 19 | 20 | size_t cacheLen; 21 | const void* cacheStart = _dyld_get_shared_cache_range(&cacheLen); 22 | 23 | if ( cacheStart != NULL ) { 24 | printf("[FAIL] no-shared-cache: _dyld_get_shared_cache_range() returned %p even though we are not using a dyld cache\n", cacheStart); 25 | return 0; 26 | } 27 | 28 | printf("[PASS] no-shared-cache\n"); 29 | return 0; 30 | } 31 | 32 | -------------------------------------------------------------------------------- /testing/test-cases/restrict-search.dtest/foo.c: -------------------------------------------------------------------------------- 1 | int foo() 2 | { 3 | return 10; 4 | } 5 | 6 | -------------------------------------------------------------------------------- /testing/test-cases/rpath-absolute.dtest/foo.c: -------------------------------------------------------------------------------- 1 | int foo = 42; 2 | -------------------------------------------------------------------------------- /testing/test-cases/rpath-absolute.dtest/main.c: -------------------------------------------------------------------------------- 1 | 2 | // BOOT_ARGS: dyld_flags=2 3 | 4 | // BUILD: $CC foo.c -dynamiclib -o $BUILD_DIR/librpathabs.dylib -install_name @rpath/librpathabs.dylib 5 | // BUILD: $CC foo.c -dynamiclib $BUILD_DIR/librpathabs.dylib -o $BUILD_DIR/libfoo.dylib -install_name $RUN_DIR/libfoo.dylib -rpath $RUN_DIR 6 | // BUILD: $CC main.c $BUILD_DIR/libfoo.dylib -o $BUILD_DIR/rpath-absolute.exe 7 | 8 | // RUN: DYLD_AMFI_FAKE=0 ./rpath-absolute.exe 9 | 10 | // main prog links with libfoo.dylib which uses an absolute LC_RPRATH and @rpath to find librpathabs.dylib 11 | // must be able to run with full restrictions 12 | 13 | #include 14 | 15 | extern int foo; 16 | 17 | 18 | int main() 19 | { 20 | printf("[BEGIN] rpath-absolute.exe\n"); 21 | printf("[PASS] rpath-absolute.exe\n"); 22 | return 0; 23 | } 24 | 25 | 26 | -------------------------------------------------------------------------------- /testing/test-cases/rpath-weak-missing.dtest/foo.c: -------------------------------------------------------------------------------- 1 | int foo = 42; 2 | -------------------------------------------------------------------------------- /testing/test-cases/rpath-weak-missing.dtest/main.c: -------------------------------------------------------------------------------- 1 | 2 | // BOOT_ARGS: dyld_flags=2 3 | 4 | // BUILD: $CC foo.c -dynamiclib -o $TEMP_DIR/libmissing.dylib -install_name @rpath/libmissing.dylib 5 | // BUILD: $CC foo.c -dynamiclib -Wl,-weak_library,$TEMP_DIR/libmissing.dylib -o $BUILD_DIR/libfoo.dylib -install_name $RUN_DIR/libfoo.dylib -rpath $RUN_DIR 6 | // BUILD: $CC main.c -o $BUILD_DIR/rpath-weak-missing.exe -DRUN_DIR="$RUN_DIR" 7 | 8 | // RUN: ./rpath-weak-missing.exe 9 | // RUN: DYLD_AMFI_FAKE=0 ./rpath-weak-missing.exe 10 | 11 | // main prog dlopen()s libfoo.dylib which weak links to @rpath/libmissing.dylib 12 | 13 | #include 14 | #include 15 | 16 | 17 | int main() 18 | { 19 | printf("[BEGIN] rpath-weak-missing\n"); 20 | 21 | void* handle = dlopen(RUN_DIR "/libfoo.dylib", RTLD_LAZY); 22 | if ( handle == NULL ) { 23 | printf("[FAIL] rpath-weak-missing dlopen(\"%s/libfoo.dylib\") - %s\n", RUN_DIR, dlerror()); 24 | return 0; 25 | } 26 | 27 | printf("[PASS] rpath-weak-missing\n"); 28 | return 0; 29 | } 30 | 31 | 32 | -------------------------------------------------------------------------------- /testing/test-cases/shared_cache_optimized.dtest/main.c: -------------------------------------------------------------------------------- 1 | 2 | // BUILD: $CC main.c -o $BUILD_DIR/shared_cache_optimized.exe 3 | 4 | // RUN: ./shared_cache_optimized.exe 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | 13 | int main() 14 | { 15 | printf("[BEGIN] shared_cache_optimized\n"); 16 | 17 | // tests run on internal installs which use un-optimzed dyld cache 18 | if ( _dyld_shared_cache_optimized() ) 19 | printf("[FAIL] shared_cache_optimized unexpectedly returned true\n"); 20 | else 21 | printf("[PASS] shared_cache_optimized\n"); 22 | 23 | return 0; 24 | } 25 | 26 | -------------------------------------------------------------------------------- /testing/test-cases/static-terminators.dtest/base.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | static bool mainCalled = false; 6 | static bool libCalled = false; 7 | static bool libCalledBeforeMain = false; 8 | 9 | void mainTerminated() 10 | { 11 | mainCalled = true; 12 | } 13 | 14 | void libDynamicTerminated() 15 | { 16 | libCalled = true; 17 | if ( !mainCalled ) 18 | libCalledBeforeMain = true; 19 | } 20 | 21 | 22 | static __attribute__((destructor)) 23 | void myTerm() 24 | { 25 | if ( !mainCalled ) 26 | printf("[FAIL] static-terminators, main's terminator not called\n"); 27 | else if ( !libCalled ) 28 | printf("[FAIL] static-terminators, libDynamic's terminator not called\n"); 29 | else if ( !libCalledBeforeMain ) 30 | printf("[FAIL] static-terminators, libDynamic's terminator called out of order\n"); 31 | else 32 | printf("[PASS] static-terminators\n"); 33 | } 34 | 35 | -------------------------------------------------------------------------------- /testing/test-cases/static-terminators.dtest/foo.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | extern void libDynamicTerminated(); 6 | 7 | 8 | static __attribute__((destructor)) 9 | void myTerm() 10 | { 11 | //fprintf(stderr, "foo static terminator\n"); 12 | libDynamicTerminated(); 13 | } 14 | 15 | -------------------------------------------------------------------------------- /testing/test-cases/symbol-resolver-basic.dtest/foo.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | static int foo_ten() 5 | { 6 | return 10; 7 | } 8 | 9 | static int foo_zero() 10 | { 11 | return 0; 12 | } 13 | 14 | 15 | // This foo is a "resolver" function that return the actual address of "foo" 16 | void* foo() 17 | { 18 | __asm__(".symbol_resolver _foo"); // magic until we have compiler support 19 | #if TEN 20 | return &foo_ten; 21 | #else 22 | return &foo_zero; 23 | #endif 24 | } 25 | 26 | 27 | -------------------------------------------------------------------------------- /testing/test-cases/symbol-resolver-basic.dtest/foo2.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | extern int foo(); 5 | 6 | // test that calls to resolver based function in same dylib work 7 | int fooPlusOne() 8 | { 9 | return foo() + 1; 10 | } 11 | 12 | -------------------------------------------------------------------------------- /testing/test-cases/thread-local-cleanup.dtest/foo.c: -------------------------------------------------------------------------------- 1 | 2 | __thread int a; 3 | __thread int b = 5; 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /testing/test-cases/thread-local-cleanup.dtest/main.c: -------------------------------------------------------------------------------- 1 | 2 | // BUILD: $CC foo.c -dynamiclib -install_name $RUN_DIR/libtlv.dylib -o $BUILD_DIR/libtlv.dylib 3 | // BUILD: $CC main.c -DRUN_DIR="$RUN_DIR" -o $BUILD_DIR/thread-local-cleanup.exe 4 | 5 | // RUN: ./thread-local-cleanup.exe 6 | 7 | #include 8 | #include 9 | 10 | 11 | 12 | 13 | 14 | int main() 15 | { 16 | printf("[BEGIN] thread-local-cleanup\n"); 17 | 18 | for (int i=0; i < 1000; ++i) { 19 | void* handle = dlopen(RUN_DIR "/libtlv.dylib", RTLD_FIRST); 20 | if ( handle == NULL ) { 21 | printf("[FAIL] thread-local-cleanup: iteration %d %s\n", i, dlerror()); 22 | return 0; 23 | } 24 | 25 | int result = dlclose(handle); 26 | if ( result != 0 ) { 27 | printf("[FAIL] thread-local-cleanup: iteration %d %s\n", i, dlerror()); 28 | return 0; 29 | } 30 | } 31 | 32 | printf("[PASS] thread-local-cleanup\n"); 33 | 34 | return 0; 35 | } 36 | 37 | -------------------------------------------------------------------------------- /testing/test-cases/thread-local-destructors.dtest/foo.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | __thread int a; 5 | __thread int b = 5; 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /testing/test-cases/thread-local-variables.dtest/foo.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | __thread int a; 5 | __thread int b = 5; 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /testing/test-cases/unix-conformance.dtest/main.c: -------------------------------------------------------------------------------- 1 | 2 | // This tests that our header such as dlfcn.h pass unix conformance. 3 | 4 | // BUILD_ONLY: MacOSX 5 | 6 | // BUILD: $CC main.c -o $BUILD_DIR/unix-conformance.exe -D_XOPEN_SOURCE=600 7 | // BUILD: $CC main.c -o $TEMP_DIR/scratch.exe -D_XOPEN_SOURCE=600 -D_POSIX_C_SOURCE=200112 8 | 9 | // RUN: ./unix-conformance.exe 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | int main() 17 | { 18 | printf("[BEGIN] unix-conformance.dtest\n"); 19 | 20 | printf("[PASS] unix-conformance.dtest\n"); 21 | return 0; 22 | } 23 | 24 | -------------------------------------------------------------------------------- /testing/test-cases/weak-coalesce-inserted-dylibs.dtest/bar.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | void* operator new(size_t size) 5 | { 6 | return malloc(size); 7 | } 8 | 9 | void operator delete(void* ptr) 10 | { 11 | free(ptr); 12 | } 13 | 14 | -------------------------------------------------------------------------------- /testing/test-cases/weak-coalesce-inserted-dylibs.dtest/foo.cpp: -------------------------------------------------------------------------------- 1 | 2 | void foo() { 3 | int* v = new int(1); 4 | delete v; 5 | } 6 | -------------------------------------------------------------------------------- /testing/test-cases/weak-coalesce-unload.dtest/foo1.c: -------------------------------------------------------------------------------- 1 | 2 | __attribute__((weak)) 3 | int foo = 1; 4 | 5 | void* fooPtr() { 6 | return &foo; 7 | } -------------------------------------------------------------------------------- /testing/test-cases/weak-coalesce-unload.dtest/foo2.c: -------------------------------------------------------------------------------- 1 | 2 | __attribute__((weak)) 3 | int foo() { 4 | return 2; 5 | } 6 | 7 | void* fooPtr() { 8 | return &foo; 9 | } 10 | 11 | 12 | -------------------------------------------------------------------------------- /testing/test-cases/weak-coalesce-unload.dtest/foo3.c: -------------------------------------------------------------------------------- 1 | 2 | __attribute__((weak)) 3 | int foo() { 4 | return 3; 5 | } 6 | 7 | void* fooPtr() { 8 | return &foo; 9 | } 10 | 11 | 12 | -------------------------------------------------------------------------------- /testing/test-cases/weak-coalesce.dtest/base.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | extern void baseCheck(); 4 | 5 | extern int coal1; 6 | extern int coal2; 7 | 8 | extern void baseVerifyCoal1(const char* where, int* addr); 9 | extern void baseVerifyCoal2(const char* where, int* addr); 10 | -------------------------------------------------------------------------------- /testing/test-cases/weak-coalesce.dtest/foo2.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "base.h" 4 | 5 | int coal1 = 2; // note: this is not weak and therefore should win 6 | int __attribute__((weak)) coal2 = 2; 7 | 8 | static __attribute__((constructor)) 9 | void myinit() 10 | { 11 | //fprintf(stderr, "myinit() in foo1.c\n"); 12 | baseVerifyCoal1("in foo2", &coal1); 13 | baseVerifyCoal2("in foo2", &coal2); 14 | } 15 | -------------------------------------------------------------------------------- /testing/test-cases/weak-coalesce.dtest/foo3.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "base.h" 4 | 5 | int __attribute__((weak)) coal1 = 3; 6 | int __attribute__((weak)) coal2 = 2; 7 | 8 | static __attribute__((constructor)) 9 | void myinit() 10 | { 11 | //fprintf(stderr, "myinit() in foo1.c\n"); 12 | baseVerifyCoal1("in foo3", &coal1); 13 | baseVerifyCoal2("in foo3", &coal2); 14 | } 15 | 16 | -------------------------------------------------------------------------------- /testing/test-cases/weak-coalesce.dtest/main.c: -------------------------------------------------------------------------------- 1 | 2 | // BUILD: $CC base.c -dynamiclib -install_name $RUN_DIR/libbase.dylib -o $BUILD_DIR/libbase.dylib 3 | // BUILD: $CC foo3.c -dynamiclib -install_name $RUN_DIR/libfoo3.dylib -o $BUILD_DIR/libfoo3.dylib $BUILD_DIR/libbase.dylib 4 | // BUILD: $CC foo2.c -dynamiclib -install_name $RUN_DIR/libfoo2.dylib -o $BUILD_DIR/libfoo2.dylib $BUILD_DIR/libfoo3.dylib $BUILD_DIR/libbase.dylib 5 | // BUILD: $CC foo1.c -dynamiclib -install_name $RUN_DIR/libfoo1.dylib -o $BUILD_DIR/libfoo1.dylib $BUILD_DIR/libfoo2.dylib $BUILD_DIR/libbase.dylib 6 | // BUILD: $CC main.c $BUILD_DIR/libfoo1.dylib $BUILD_DIR/libbase.dylib -o $BUILD_DIR/weak-coalesce.exe 7 | 8 | // RUN: ./weak-coalesce.exe 9 | 10 | 11 | #include 12 | #include 13 | 14 | #include "base.h" 15 | 16 | int main() 17 | { 18 | printf("[BEGIN] weak-coalesce\n"); 19 | 20 | baseVerifyCoal1("in main", &coal1); 21 | baseVerifyCoal2("in main", &coal2); 22 | 23 | baseCheck(); 24 | return 0; 25 | } 26 | 27 | -------------------------------------------------------------------------------- /testing/test-cases/weak-dylib-re-export.dtest/bar.c: -------------------------------------------------------------------------------- 1 | 2 | int bar() { 3 | return 42; 4 | } 5 | 6 | -------------------------------------------------------------------------------- /testing/test-cases/weak-dylib-re-export.dtest/foo.c: -------------------------------------------------------------------------------- 1 | 2 | int foo = 1; 3 | 4 | -------------------------------------------------------------------------------- /testing/test-cases/weak-dylib-re-export.dtest/main.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | // BUILD: $CC bar.c -dynamiclib -o $TEMP_DIR/libbar.dylib -install_name $RUN_DIR/libbar.dylib 4 | // BUILD: $CC foo.c -dynamiclib -L$TEMP_DIR -weak-lbar -Wl,-reexported_symbols_list,symbols.txt -install_name $RUN_DIR/libfoo.dylib -o $BUILD_DIR/libfoo.dylib 5 | // BUILD: $CC main.c -o $BUILD_DIR/dylib-re-export.exe $BUILD_DIR/libfoo.dylib -L$BUILD_DIR 6 | 7 | // RUN: ./dylib-re-export.exe 8 | 9 | 10 | #include 11 | 12 | __attribute__((weak_import)) 13 | extern int bar(); 14 | 15 | int main() 16 | { 17 | printf("[BEGIN] dylib-re-export\n"); 18 | if ( &bar == 0 ) 19 | printf("[PASS] dylib-re-export\n"); 20 | else 21 | printf("[FAIL] dylib-re-export, wrong value\n"); 22 | 23 | return 0; 24 | } 25 | 26 | 27 | -------------------------------------------------------------------------------- /testing/test-cases/weak-dylib-re-export.dtest/symbols.txt: -------------------------------------------------------------------------------- 1 | _bar 2 | -------------------------------------------------------------------------------- /unit-tests/bin/exit-non-zero-pass.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl -w 2 | 3 | use strict; 4 | 5 | sub PASS 6 | { 7 | my ($format, $args) = @_; 8 | if(!defined $args) 9 | { $args = []; } 10 | printf("PASS \"$format\"\n", @$args); 11 | } 12 | 13 | sub FAIL 14 | { 15 | my ($format, $args) = @_; 16 | if(!defined $args) 17 | { $args = []; } 18 | printf("FAIL \"$format\"\n", @$args); 19 | } 20 | 21 | my $pass_string = shift @ARGV; 22 | my $fail_string = shift @ARGV; 23 | 24 | 25 | # redirect stderr to stdout 26 | open(STDERR, ">/tmp/exit-non-zero.tmp") || die("$!"); 27 | if(0 != system(@ARGV)) 28 | { 29 | PASS($pass_string); 30 | } 31 | else 32 | { 33 | FAIL($fail_string); 34 | } 35 | close(STDERR) || die("$!"); 36 | open(OUT, ") 38 | { 39 | print $_; 40 | } 41 | close(OUT) || die("$!"); 42 | unlink "/tmp/exit-non-zero.tmp"; 43 | exit 0; 44 | 45 | -------------------------------------------------------------------------------- /unit-tests/bin/exit-zero-pass.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl -w 2 | 3 | use strict; 4 | 5 | sub PASS 6 | { 7 | my ($format, $args) = @_; 8 | if(!defined $args) 9 | { $args = []; } 10 | printf("PASS \"$format\"\n", @$args); 11 | } 12 | 13 | sub FAIL 14 | { 15 | my ($format, $args) = @_; 16 | if(!defined $args) 17 | { $args = []; } 18 | printf("FAIL \"$format\"\n", @$args); 19 | } 20 | 21 | my $pass_string = shift @ARGV; 22 | my $fail_string = shift @ARGV; 23 | 24 | # redirect stderr to stdout 25 | open(STDERR, ">/tmp/exit-zero-pass.tmp") || die("$!"); 26 | if(0 == system(@ARGV)) 27 | { 28 | PASS($pass_string); 29 | } 30 | else 31 | { 32 | FAIL($fail_string); 33 | } 34 | close(STDERR) || die("$!"); 35 | open(OUT, ") 37 | { 38 | print $_; 39 | } 40 | close(OUT) || die("$!"); 41 | unlink "/tmp/exit-zero-pass.tmp"; 42 | exit 0; 43 | 44 | -------------------------------------------------------------------------------- /unit-tests/bin/fail-if-non-zero.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl -w 2 | 3 | use strict; 4 | 5 | # first arg is fail string, rest of args are command line to invoke 6 | my $fail_string = shift @ARGV; 7 | 8 | if(system(@ARGV) != 0) 9 | { 10 | printf("FAIL \"$fail_string\"\n"); 11 | } 12 | 13 | exit 0; 14 | 15 | -------------------------------------------------------------------------------- /unit-tests/bin/pass-iff-exit-zero.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl -w 2 | 3 | # 4 | # Usage: 5 | # 6 | # ${PASS_IFF} command 7 | # 8 | 9 | use strict; 10 | 11 | my $test_name = ""; 12 | if ( exists $ENV{UNIT_TEST_NAME} ) { 13 | $test_name = $ENV{UNIT_TEST_NAME}; 14 | } 15 | 16 | if(0 != system(@ARGV)) 17 | { 18 | printf("FAIL $test_name\n"); 19 | exit 1; 20 | } 21 | 22 | printf("PASS $test_name\n"); 23 | exit 0; 24 | -------------------------------------------------------------------------------- /unit-tests/build-and-run-iPhoneOS-unit-tests: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # need to be root to build test suite 4 | sudo ./build-iPhoneOS-unit-tests 5 | 6 | # transfer to device 7 | echo " * * * Transfering to device * * *" 8 | rsync -a /tmp/unpack-and-run-all-tests /tmp/dyld-testing.cpgz rsync://root@localhost:10873/root/tmp 9 | 10 | 11 | # running on device 12 | echo " * * * Running on device * * *" 13 | /Developer/Platforms/iPhoneOS.platform/usr/local/bin/PurpleExec /tmp/unpack-and-run-all-tests 14 | 15 | -------------------------------------------------------------------------------- /unit-tests/include/test.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define DEFINE_TEST_FUNC(name) \ 5 | static \ 6 | inline \ 7 | void \ 8 | name(const char *format, ...) \ 9 | { \ 10 | va_list args; \ 11 | va_start(args, format); \ 12 | common(stdout, #name, format, args); \ 13 | va_end(args); \ 14 | return; \ 15 | } 16 | 17 | static 18 | inline 19 | void 20 | common(FILE *file, const char *prefix, const char *format, va_list args) 21 | { 22 | fprintf(file, "%s \"", prefix); 23 | vfprintf(file, format, args); 24 | fprintf(file, "\"\n"); // should check for trailing newline 25 | return; 26 | } 27 | 28 | DEFINE_TEST_FUNC(PASS); 29 | DEFINE_TEST_FUNC(XPASS); 30 | DEFINE_TEST_FUNC(FAIL); 31 | DEFINE_TEST_FUNC(XFAIL); 32 | 33 | DEFINE_TEST_FUNC(UNTESTED); 34 | DEFINE_TEST_FUNC(UNSUPPORTED); 35 | DEFINE_TEST_FUNC(UNRESOLVED); 36 | -------------------------------------------------------------------------------- /unit-tests/test-cases/DYLD_LIBRARY_PATH-dyld_env/foo.c: -------------------------------------------------------------------------------- 1 | 2 | int foo() 3 | { 4 | return RESULT; 5 | } 6 | -------------------------------------------------------------------------------- /unit-tests/test-cases/NSAddImage-MATCH_BY_INSTALLNAME/bar.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005 Apple Computer, Inc. All rights reserved. 3 | * 4 | * @APPLE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. Please obtain a copy of the License at 10 | * http://www.opensource.apple.com/apsl/ and read it before using this 11 | * file. 12 | * 13 | * The Original Code and all software distributed under the License are 14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 | * Please see the License for the specific language governing rights and 19 | * limitations under the License. 20 | * 21 | * @APPLE_LICENSE_HEADER_END@ 22 | */ 23 | 24 | -------------------------------------------------------------------------------- /unit-tests/test-cases/NSAddressOfSymbol-NULL/Makefile: -------------------------------------------------------------------------------- 1 | 2 | TESTROOT = ../.. 3 | include ${TESTROOT}/include/common.makefile 4 | 5 | all-check: all check 6 | 7 | check: 8 | ./main 9 | 10 | all: main 11 | 12 | main : main.c 13 | ${CC} ${CCFLAGS} -I${TESTROOT}/include -o main main.c -Wno-deprecated-declarations 14 | 15 | 16 | 17 | clean: 18 | ${RM} ${RMFLAGS} *~ main 19 | 20 | -------------------------------------------------------------------------------- /unit-tests/test-cases/absolute-symbol/Makefile: -------------------------------------------------------------------------------- 1 | TESTROOT = ../.. 2 | include ${TESTROOT}/include/common.makefile 3 | 4 | # 5 | # verify addends work 6 | # 7 | 8 | all-check: all check 9 | 10 | check: 11 | ./main 12 | 13 | all: 14 | 15 | ${CC} ${CCFLAGS} foo.c abs.s -dynamiclib -o libfoo.dylib 16 | ${CC} ${CCFLAGS} -I${TESTROOT}/include libfoo.dylib -o main main.c 17 | 18 | 19 | clean: 20 | ${RM} ${RMFLAGS} *~ main libfoo.dylib 21 | 22 | -------------------------------------------------------------------------------- /unit-tests/test-cases/absolute-symbol/abs.s: -------------------------------------------------------------------------------- 1 | 2 | .global _myAbs1 3 | _myAbs1 = 0 4 | 5 | 6 | 7 | .global _myAbs2 8 | _myAbs2 = 1 9 | 10 | 11 | 12 | _myLocalAbs = 3 13 | -------------------------------------------------------------------------------- /unit-tests/test-cases/absolute-symbol/foo.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | int var = 5; 4 | void func() { } 5 | 6 | -------------------------------------------------------------------------------- /unit-tests/test-cases/absolute-symbol/main.c: -------------------------------------------------------------------------------- 1 | #include // fprintf(), NULL 2 | #include // exit(), EXIT_SUCCESS 3 | #include 4 | 5 | #include "test.h" // PASS(), FAIL(), XPASS(), XFAIL() 6 | 7 | 8 | extern int var; 9 | extern void func(); 10 | extern int myAbs1 __attribute__((weak_import)); 11 | extern int myAbs2; 12 | 13 | 14 | int main() 15 | { 16 | 17 | if (&myAbs1 != 0 ) { 18 | FAIL("absolute-symbol: &myAbs1 != 0"); 19 | return 0; 20 | } 21 | 22 | 23 | if ((uintptr_t)&myAbs2 != 1 ) { 24 | FAIL("absolute-symbol: &myAbs2 != 1"); 25 | return 0; 26 | } 27 | 28 | 29 | PASS("absolute-symbol"); 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /unit-tests/test-cases/addend/Makefile: -------------------------------------------------------------------------------- 1 | TESTROOT = ../.. 2 | include ${TESTROOT}/include/common.makefile 3 | 4 | # 5 | # verify addends work 6 | # 7 | 8 | all-check: all check 9 | 10 | check: 11 | ./main 12 | 13 | all: main 14 | 15 | main : main.c libfoo.dylib 16 | ${CC} ${CCFLAGS} -I${TESTROOT}/include libfoo.dylib -o main main.c 17 | 18 | libfoo.dylib : foo.c 19 | ${CC} ${CCFLAGS} foo.c -dynamiclib -o libfoo.dylib 20 | 21 | clean: 22 | ${RM} ${RMFLAGS} *~ main libfoo.dylib 23 | 24 | -------------------------------------------------------------------------------- /unit-tests/test-cases/addend/foo.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | const char a = 10; 4 | const char b = 11; 5 | const char c = 12; 6 | const char d = 13; 7 | const char e = 14; 8 | -------------------------------------------------------------------------------- /unit-tests/test-cases/all_image_infos/foo.c: -------------------------------------------------------------------------------- 1 | void foo() {} 2 | 3 | -------------------------------------------------------------------------------- /unit-tests/test-cases/big-jump-table/pointers.c: -------------------------------------------------------------------------------- 1 | 2 | #include "foo.h" 3 | 4 | long useNonLazy() 5 | { 6 | long result = 0; 7 | result += (long)&foo001; 8 | result += (long)&foo002; 9 | result += (long)&foo003; 10 | #if CASE > 0 11 | result += (long)&foo818; 12 | #endif 13 | #if CASE > 1 14 | result += (long)&foo817; 15 | #endif 16 | #if CASE > 2 17 | result += (long)&foo816; 18 | #endif 19 | #if CASE > 3 20 | result += (long)&foo815; 21 | #endif 22 | return result; 23 | } 24 | -------------------------------------------------------------------------------- /unit-tests/test-cases/branch-islands/extra.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | bool test1() 5 | { 6 | return false; 7 | } 8 | 9 | -------------------------------------------------------------------------------- /unit-tests/test-cases/branch-islands/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include // exit(), EXIT_SUCCESS 3 | #include 4 | #include 5 | 6 | #include "test.h" // PASS(), FAIL(), XPASS(), XFAIL() 7 | 8 | // returns false on success 9 | extern bool test1(); 10 | 11 | const char* str = "hello"; 12 | 13 | 14 | int main() 15 | { 16 | if ( test1() ) 17 | FAIL("branch-islands: test1"); 18 | 19 | if ( strncmp(str, "he", 2) != 0 ) 20 | FAIL("branch-islands: strncmp stub"); 21 | 22 | 23 | PASS("branch-islands"); 24 | return EXIT_SUCCESS; 25 | } 26 | 27 | -------------------------------------------------------------------------------- /unit-tests/test-cases/bundle-dont-gc/bar.c: -------------------------------------------------------------------------------- 1 | 2 | void bar() {} 3 | 4 | -------------------------------------------------------------------------------- /unit-tests/test-cases/bundle-dont-gc/foo.c: -------------------------------------------------------------------------------- 1 | 2 | void foo() {} 3 | 4 | -------------------------------------------------------------------------------- /unit-tests/test-cases/concurrent-dlopen-initializers/foo.c: -------------------------------------------------------------------------------- 1 | 2 | void foo() {} 3 | void bar() {} 4 | void baz() {} 5 | -------------------------------------------------------------------------------- /unit-tests/test-cases/coreSymbolication-notify/bar.c: -------------------------------------------------------------------------------- 1 | 2 | int bar = 10; 3 | -------------------------------------------------------------------------------- /unit-tests/test-cases/coreSymbolication-notify/foo.c: -------------------------------------------------------------------------------- 1 | 2 | void foo() {} 3 | 4 | -------------------------------------------------------------------------------- /unit-tests/test-cases/crt-argv-NULL/main.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | 5 | int main(int argc, const char* argv[]) 6 | { 7 | if ( argv[0] != NULL ) { 8 | // re-exec with empty argv[] array 9 | char* const emptyArgv[] = { NULL }; 10 | execv(argv[0], emptyArgv); 11 | } 12 | 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /unit-tests/test-cases/crt-custom/mystart.s: -------------------------------------------------------------------------------- 1 | # Built output for (null) 2 | # Generated at (null) 3 | # Using (null) configuration, (null) architecture for (null) target of (null) project 4 | 5 | 6 | 7 | 8 | .text 9 | .align 2 10 | .globl _mystart 11 | _mystart: 12 | #if __i386__ 13 | call L1 14 | L1: popl %eax 15 | movl L_flag$non_lazy_ptr-L1(%eax), %eax 16 | movl $2, (%eax) 17 | jmp start 18 | #elif __x86_64__ 19 | movl $2, _flag(%rip) 20 | jmp start 21 | #elif __ppc__ || __ppc64__ 22 | li r0,2 23 | lis r2,ha16(_flag) 24 | stw r0,lo16(_flag)(r2) 25 | b start 26 | #elif __arm__ 27 | ldr r3, L4 28 | mov r2, #2 29 | add r3, pc 30 | ldr r3, [r3] 31 | str r2, [r3, #0] 32 | b start 33 | L4: .long L_flag$non_lazy_ptr-(L4-8) 34 | #endif 35 | 36 | #if __i386__ || __arm__ 37 | .section __DATA,__nl_symbol_ptr,non_lazy_symbol_pointers 38 | .align 2 39 | L_flag$non_lazy_ptr: 40 | .indirect_symbol _flag 41 | .long 0 42 | #endif 43 | 44 | 45 | -------------------------------------------------------------------------------- /unit-tests/test-cases/crt-result/bad.c: -------------------------------------------------------------------------------- 1 | int main() { return 1; } 2 | -------------------------------------------------------------------------------- /unit-tests/test-cases/crt-result/good.c: -------------------------------------------------------------------------------- 1 | int main() { return 0; } 2 | -------------------------------------------------------------------------------- /unit-tests/test-cases/dlclose-dylib-dynamic-ref/bar.c: -------------------------------------------------------------------------------- 1 | __attribute__((weak)) 2 | int mydata; 3 | 4 | 5 | int bar() 6 | { 7 | return mydata; 8 | } 9 | -------------------------------------------------------------------------------- /unit-tests/test-cases/dlclose-dylib-dynamic-ref/baz.c: -------------------------------------------------------------------------------- 1 | __attribute__((weak)) 2 | int mydata; 3 | 4 | 5 | int baz() 6 | { 7 | return mydata; 8 | } 9 | -------------------------------------------------------------------------------- /unit-tests/test-cases/dlclose-dylib-dynamic-ref/foo.c: -------------------------------------------------------------------------------- 1 | __attribute__((weak)) 2 | int mydata; 3 | 4 | 5 | int foo() 6 | { 7 | return mydata; 8 | } 9 | -------------------------------------------------------------------------------- /unit-tests/test-cases/dlclose-dylib-ref-count/bar.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | int bar() 4 | { 5 | return 10; 6 | } 7 | -------------------------------------------------------------------------------- /unit-tests/test-cases/dlclose-dylib-ref-count/base.c: -------------------------------------------------------------------------------- 1 | void base() { } 2 | -------------------------------------------------------------------------------- /unit-tests/test-cases/dlclose-dylib-ref-count/foo.c: -------------------------------------------------------------------------------- 1 | 2 | int foo() 3 | { 4 | return 10; 5 | } 6 | -------------------------------------------------------------------------------- /unit-tests/test-cases/dlclose-dylib-terminators/bar.cpp: -------------------------------------------------------------------------------- 1 | extern "C" int bazData; 2 | 3 | class BazUser { 4 | public: 5 | BazUser() { } 6 | ~BazUser() { bazData = 0; } 7 | }; 8 | 9 | 10 | BazUser b; 11 | 12 | 13 | int bar() 14 | { 15 | return bazData; 16 | } 17 | 18 | -------------------------------------------------------------------------------- /unit-tests/test-cases/dlclose-dylib-terminators/baz.c: -------------------------------------------------------------------------------- 1 | int bazData = 5; 2 | 3 | 4 | int baz() 5 | { 6 | return bazData; 7 | } 8 | -------------------------------------------------------------------------------- /unit-tests/test-cases/dlclose-dylib-terminators/foo.cpp: -------------------------------------------------------------------------------- 1 | 2 | extern void bar(); 3 | 4 | 5 | 6 | class A { 7 | public: 8 | A() { bar(); } 9 | ~A() { bar(); } 10 | }; 11 | 12 | 13 | // Create global object which will have its destructor run when 14 | // this dylib is unloaded. The destructor will call into libbar, 15 | // so libbar.dylib can't be unloaded before this dylib. 16 | A a; 17 | 18 | 19 | 20 | 21 | void foo() 22 | { 23 | } 24 | -------------------------------------------------------------------------------- /unit-tests/test-cases/dlclose-order/bar.cxx: -------------------------------------------------------------------------------- 1 | #include "base.h" 2 | 3 | 4 | class Bar { 5 | public: 6 | Bar() { if ( bazInitied) barInitied = true; } 7 | ~Bar() { if ( barInitied && !bazTeminated ) barTeminated = true; } 8 | }; 9 | 10 | 11 | Bar bar; 12 | 13 | -------------------------------------------------------------------------------- /unit-tests/test-cases/dlclose-order/base.c: -------------------------------------------------------------------------------- 1 | #include "base.h" 2 | 3 | bool barInitied = false; 4 | bool barTeminated = false; 5 | 6 | bool bazInitied = false; 7 | bool bazTeminated = false; 8 | 9 | -------------------------------------------------------------------------------- /unit-tests/test-cases/dlclose-order/base.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | extern bool barInitied; 4 | extern bool barTeminated; 5 | 6 | extern bool bazInitied; 7 | extern bool bazTeminated; 8 | 9 | 10 | -------------------------------------------------------------------------------- /unit-tests/test-cases/dlclose-order/baz.cxx: -------------------------------------------------------------------------------- 1 | #include "base.h" 2 | 3 | class Baz { 4 | public: 5 | Baz() { bazInitied = true; } 6 | ~Baz() { bazTeminated = true; } 7 | 8 | }; 9 | 10 | 11 | Baz baz; 12 | 13 | -------------------------------------------------------------------------------- /unit-tests/test-cases/dlclose-unmap/foo.c: -------------------------------------------------------------------------------- 1 | 2 | void foo() {} -------------------------------------------------------------------------------- /unit-tests/test-cases/dlopen-DYLD_FALLBACK_LIBRARY_PATH/Makefile: -------------------------------------------------------------------------------- 1 | TESTROOT = ../.. 2 | include ${TESTROOT}/include/common.makefile 3 | 4 | PWD = $(shell pwd) 5 | 6 | # 7 | # Test that DYLD_FALLBACK_LIBRARY_PATH does not apply to dlopen() of a full path 8 | # DYLD_FALLBACK_LIBRARY_PATH man page misleading 9 | # 10 | 11 | 12 | all-check: all check 13 | 14 | check: 15 | export DYLD_FALLBACK_LIBRARY_PATH="${PWD}/hide" && ./main 16 | 17 | all: main hide/libfoo.dylib 18 | 19 | main : main.c hide/libfoo.dylib 20 | ${CC} ${CCFLAGS} -I${TESTROOT}/include -o main main.c 21 | 22 | 23 | hide/libfoo.dylib : foo.c 24 | mkdir -p hide 25 | ${CC} ${CCFLAGS} -dynamiclib foo.c -o "${PWD}/hide/libfoo.dylib" 26 | 27 | 28 | 29 | clean: 30 | ${RM} -rf *~ main hide 31 | 32 | -------------------------------------------------------------------------------- /unit-tests/test-cases/dlopen-DYLD_FALLBACK_LIBRARY_PATH/foo.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | int foo() 4 | { 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /unit-tests/test-cases/dlopen-RTLD_LOCAL-weak/Makefile: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | TESTROOT = ../.. 5 | include ${TESTROOT}/include/common.makefile 6 | 7 | # 8 | # verifes that RTLD_LOCAL suppresses weak symbol coalescing 9 | # 10 | 11 | 12 | 13 | all-check: all check 14 | 15 | check: 16 | ./main 17 | 18 | all: main libfoo.dylib libbar.dylib 19 | 20 | main : main.c 21 | ${CC} ${CCFLAGS} -I${TESTROOT}/include -o main main.c 22 | 23 | libfoo.dylib : foo.c 24 | ${CC} ${CCFLAGS} -dynamiclib foo.c -o libfoo.dylib 25 | 26 | libbar.dylib : bar.c 27 | ${CC} ${CCFLAGS} -dynamiclib bar.c -o libbar.dylib 28 | 29 | clean: 30 | ${RM} ${RMFLAGS} *~ main libfoo.dylib libbar.dylib 31 | 32 | -------------------------------------------------------------------------------- /unit-tests/test-cases/dlopen-RTLD_LOCAL-weak/bar.c: -------------------------------------------------------------------------------- 1 | int __attribute__((weak)) A[] = { 1, 2, 3, 4 }; 2 | 3 | 4 | int* getA() { return A; } 5 | 6 | -------------------------------------------------------------------------------- /unit-tests/test-cases/dlopen-RTLD_LOCAL-weak/foo.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | int __attribute__((weak)) A[] = { 5, 6, 7, 8 }; 4 | 5 | int* getA() { return A; } 6 | -------------------------------------------------------------------------------- /unit-tests/test-cases/dlopen-RTLD_NOLOAD-symlink/bar.c: -------------------------------------------------------------------------------- 1 | int bar() { return 0; } 2 | -------------------------------------------------------------------------------- /unit-tests/test-cases/dlopen-RTLD_NOLOAD-symlink/foo.c: -------------------------------------------------------------------------------- 1 | int foo() { return 0; } 2 | 3 | -------------------------------------------------------------------------------- /unit-tests/test-cases/dlopen-codesign-dynamic/foo.c: -------------------------------------------------------------------------------- 1 | void foo() 2 | { 3 | } 4 | -------------------------------------------------------------------------------- /unit-tests/test-cases/dlopen-codesign/foo.c: -------------------------------------------------------------------------------- 1 | void foo() 2 | { 3 | } 4 | -------------------------------------------------------------------------------- /unit-tests/test-cases/dlopen-codesign/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | 9 | #include "test.h" 10 | 11 | 12 | int main() 13 | { 14 | void* handle = dlopen("libfoo.dylib", RTLD_LAZY); 15 | if ( handle != NULL ) { 16 | FAIL("dlopen-codesign: load of libfoo.dylib should have failed"); 17 | return EXIT_SUCCESS; 18 | } 19 | const char* msg = dlerror(); 20 | if ( strstr(msg, "signature") == NULL ) { 21 | FAIL("dlopen-codesign: load of libfoo.dylib failed, but message was wrong: %s", msg); 22 | return EXIT_SUCCESS; 23 | } 24 | 25 | PASS("dlopen-codesign"); 26 | return EXIT_SUCCESS; 27 | } 28 | -------------------------------------------------------------------------------- /unit-tests/test-cases/dlopen-dyld-locking/base.h: -------------------------------------------------------------------------------- 1 | 2 | extern void waitForState(int); 3 | extern void setState(int); 4 | -------------------------------------------------------------------------------- /unit-tests/test-cases/dlopen-error/foo.c: -------------------------------------------------------------------------------- 1 | 2 | void foo() {} 3 | -------------------------------------------------------------------------------- /unit-tests/test-cases/dlopen-executable/foo.c: -------------------------------------------------------------------------------- 1 | int foo() 2 | { 3 | return 10; 4 | } 5 | 6 | int main() 7 | { 8 | return 0; 9 | } 10 | 11 | -------------------------------------------------------------------------------- /unit-tests/test-cases/dlopen-init-dlopen-notify/bar.c: -------------------------------------------------------------------------------- 1 | void bar() {} 2 | -------------------------------------------------------------------------------- /unit-tests/test-cases/dlopen-init-dlopen-up/bar.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | extern int foo(); 4 | 5 | int bar() { return foo(); } 6 | -------------------------------------------------------------------------------- /unit-tests/test-cases/dlopen-init-dlopen/bar.c: -------------------------------------------------------------------------------- 1 | void bar() {} 2 | -------------------------------------------------------------------------------- /unit-tests/test-cases/dlopen-init-up/bar.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | extern int foo(); 4 | 5 | int bar() { return foo(); } 6 | -------------------------------------------------------------------------------- /unit-tests/test-cases/dlopen-leak/bar.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void bar() 4 | { 5 | strcpy(NULL, NULL); 6 | } 7 | -------------------------------------------------------------------------------- /unit-tests/test-cases/dlopen-leak/foo.c: -------------------------------------------------------------------------------- 1 | void foo() 2 | { 3 | } 4 | -------------------------------------------------------------------------------- /unit-tests/test-cases/dlopen-sandbox/base.sb: -------------------------------------------------------------------------------- 1 | 2 | (version 1) 3 | (allow default) 4 | (debug deny) 5 | 6 | (deny FILTER 7 | (literal "DIR/libfoo.dylib")) 8 | 9 | 10 | -------------------------------------------------------------------------------- /unit-tests/test-cases/dlopen-sandbox/foo.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | int foo() 4 | { 5 | return 42; 6 | } 7 | 8 | -------------------------------------------------------------------------------- /unit-tests/test-cases/dlopen-search-leak/foo.c: -------------------------------------------------------------------------------- 1 | void foo() 2 | { 3 | } 4 | -------------------------------------------------------------------------------- /unit-tests/test-cases/dlopen_preflight-basic/bar.c: -------------------------------------------------------------------------------- 1 | 2 | int bar = 10; 3 | -------------------------------------------------------------------------------- /unit-tests/test-cases/dlopen_preflight-basic/foo.c: -------------------------------------------------------------------------------- 1 | 2 | void foo() {} 3 | 4 | -------------------------------------------------------------------------------- /unit-tests/test-cases/dlopen_preflight-cycle/bar.c: -------------------------------------------------------------------------------- 1 | 2 | int bar = 10; 3 | -------------------------------------------------------------------------------- /unit-tests/test-cases/dlopen_preflight-cycle/baz.c: -------------------------------------------------------------------------------- 1 | void baz() {} 2 | -------------------------------------------------------------------------------- /unit-tests/test-cases/dlopen_preflight-cycle/foo.c: -------------------------------------------------------------------------------- 1 | 2 | void foo() {} 3 | 4 | -------------------------------------------------------------------------------- /unit-tests/test-cases/dlopen_preflight-leak-image-deny-single/foo.c: -------------------------------------------------------------------------------- 1 | void foo() 2 | { 3 | } 4 | -------------------------------------------------------------------------------- /unit-tests/test-cases/dlopen_preflight-leak/bar.c: -------------------------------------------------------------------------------- 1 | void bar() 2 | { 3 | } 4 | -------------------------------------------------------------------------------- /unit-tests/test-cases/dlopen_preflight-leak/foo.c: -------------------------------------------------------------------------------- 1 | void foo() 2 | { 3 | } 4 | -------------------------------------------------------------------------------- /unit-tests/test-cases/dlsym-RTLD_MAIN_ONLY/Makefile: -------------------------------------------------------------------------------- 1 | 2 | 3 | TESTROOT = ../.. 4 | include ${TESTROOT}/include/common.makefile 5 | 6 | all-check: all check 7 | 8 | check: 9 | ./main 10 | 11 | all: main 12 | 13 | main : main.c libfoo.dylib 14 | ${CC} ${CCFLAGS} -I${TESTROOT}/include libfoo.dylib -o main main.c 15 | 16 | libfoo.dylib : foo.c 17 | ${CC} ${CCFLAGS} -dynamiclib foo.c -o libfoo.dylib 18 | 19 | 20 | clean: 21 | ${RM} ${RMFLAGS} *~ main libfoo.dylib 22 | 23 | -------------------------------------------------------------------------------- /unit-tests/test-cases/dtrace-static-probes/foo.d: -------------------------------------------------------------------------------- 1 | 2 | provider Foo { 3 | probe count(int); 4 | }; 5 | 6 | 7 | #pragma D attributes Evolving/Evolving/Common provider Foo args 8 | -------------------------------------------------------------------------------- /unit-tests/test-cases/dtrace-static-probes/main.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | #include "foo.h" 5 | 6 | 7 | int main() { 8 | for (int i=0; i < 5; ++i) { 9 | FOO_COUNT(i); 10 | } 11 | 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /unit-tests/test-cases/dyld_is_memory_immutable/Makefile: -------------------------------------------------------------------------------- 1 | TESTROOT = ../.. 2 | include ${TESTROOT}/include/common.makefile 3 | 4 | # 5 | # verify addends work 6 | # 7 | 8 | all-check: all check 9 | 10 | check: 11 | ./main 12 | 13 | all: 14 | ${CC} ${CCFLAGS} bar.c -dynamiclib -o libbar.dylib 15 | ${CC} ${CCFLAGS} foo.c -dynamiclib -o libfoo.dylib 16 | ${CC} ${CCFLAGS} -I${TESTROOT}/include libfoo.dylib -o main main.c 17 | 18 | 19 | clean: 20 | ${RM} ${RMFLAGS} *~ main libfoo.dylib libbar.dylib 21 | 22 | -------------------------------------------------------------------------------- /unit-tests/test-cases/dyld_is_memory_immutable/bar.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | const char* bar() 5 | { 6 | return "bar"; 7 | } 8 | -------------------------------------------------------------------------------- /unit-tests/test-cases/dyld_is_memory_immutable/foo.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | const char* foo() 4 | { 5 | return "foo"; 6 | } -------------------------------------------------------------------------------- /unit-tests/test-cases/dynamic_cast-basic/Makefile: -------------------------------------------------------------------------------- 1 | 2 | 3 | TESTROOT = ../.. 4 | include ${TESTROOT}/include/common.makefile 5 | 6 | all-check: all check 7 | 8 | check: 9 | ./main 10 | 11 | all: main 12 | 13 | main: main.cxx librealmain.dylib 14 | ${CXX} ${CXXFLAGS} -I${TESTROOT}/include -o main main.cxx librealmain.dylib 15 | 16 | librealmain.dylib: realmain.cxx libfoo.dylib 17 | ${CXX} ${CXXFLAGS} -I${TESTROOT}/include -dynamiclib -o librealmain.dylib realmain.cxx libfoo.dylib 18 | 19 | libfoo.dylib: foo.cxx 20 | ${CXX} ${CXXFLAGS} -I${TESTROOT}/include -dynamiclib -o libfoo.dylib foo.cxx 21 | 22 | clean: 23 | ${RM} ${RMFLAGS} *~ main libfoo.dylib librealmain.dylib 24 | 25 | -------------------------------------------------------------------------------- /unit-tests/test-cases/dynamic_cast-basic/foo.cxx: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | #include "foo.h" 5 | 6 | test* maketestsub() 7 | { 8 | return new testsub(); 9 | } 10 | 11 | bool istestsub(test* t) 12 | { 13 | return (dynamic_cast(t) != NULL); 14 | } 15 | 16 | -------------------------------------------------------------------------------- /unit-tests/test-cases/dynamic_cast-basic/foo.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | class test 4 | { 5 | public: 6 | virtual void aa() {} 7 | 8 | int f; 9 | }; 10 | 11 | class testsub : public test 12 | { 13 | public: 14 | testsub() : g(0) {} 15 | virtual void aa() {} 16 | 17 | int g; 18 | }; 19 | 20 | 21 | class testsubother : public test 22 | { 23 | public: 24 | testsubother() : h(0) {} 25 | virtual void aa() {} 26 | 27 | int h; 28 | }; 29 | 30 | extern test* maketestsub(); 31 | 32 | extern bool istestsub(test* t); -------------------------------------------------------------------------------- /unit-tests/test-cases/dynamic_cast-basic/main.cxx: -------------------------------------------------------------------------------- 1 | 2 | extern void realmain(); 3 | 4 | int main() 5 | { 6 | realmain(); 7 | return 0; 8 | } 9 | 10 | 11 | -------------------------------------------------------------------------------- /unit-tests/test-cases/dynamic_cast-basic/realmain.cxx: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include // fprintf(), NULL 4 | #include // exit(), EXIT_SUCCESS 5 | 6 | #include "test.h" // PASS(), FAIL(), XPASS(), XFAIL() 7 | 8 | #include "foo.h" 9 | 10 | 11 | void realmain() 12 | { 13 | test* t1 = maketestsub(); 14 | test* t2 = new testsub(); 15 | test* t3 = new testsubother(); 16 | testsub* t1a = dynamic_cast(t1); 17 | testsubother* t3a = dynamic_cast(t3); 18 | if ( (t1a == NULL) || (t3a == NULL) || !istestsub(t2) ) 19 | FAIL("dynamic_cast-basic"); 20 | else 21 | PASS("dynamic_cast-basic"); 22 | } 23 | 24 | 25 | -------------------------------------------------------------------------------- /unit-tests/test-cases/env-DYLD_FALLBACK_LIBRARY_PATH/compress.c: -------------------------------------------------------------------------------- 1 | int compress() 2 | { 3 | return 0; 4 | } 5 | -------------------------------------------------------------------------------- /unit-tests/test-cases/env-DYLD_FALLBACK_LIBRARY_PATH/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include "test.h" 7 | 8 | extern void compress(); 9 | 10 | int main(int argc, const char* argv[]) 11 | { 12 | #if !SHOULD_FAIL 13 | Dl_info info; 14 | if ( dladdr(&compress, &info) ) { 15 | //fprintf(stderr, "_compress found in %s\n", info.dli_fname); 16 | if ( strstr(info.dli_fname, argv[1]) != 0 ) { 17 | PASS("env-DYLD_FALLBACK_LIBRARY_PATH"); 18 | exit(0); 19 | } 20 | } 21 | FAIL("env-DYLD_FALLBACK_LIBRARY_PATH"); 22 | #endif 23 | return EXIT_SUCCESS; 24 | } 25 | -------------------------------------------------------------------------------- /unit-tests/test-cases/executable-image-index/foo.c: -------------------------------------------------------------------------------- 1 | void foo() { } 2 | 3 | -------------------------------------------------------------------------------- /unit-tests/test-cases/flat-data/bar.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005 Apple Computer, Inc. All rights reserved. 3 | * 4 | * @APPLE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. Please obtain a copy of the License at 10 | * http://www.opensource.apple.com/apsl/ and read it before using this 11 | * file. 12 | * 13 | * The Original Code and all software distributed under the License are 14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 | * Please see the License for the specific language governing rights and 19 | * limitations under the License. 20 | * 21 | * @APPLE_LICENSE_HEADER_END@ 22 | */ 23 | 24 | int bar = 2; 25 | -------------------------------------------------------------------------------- /unit-tests/test-cases/framework-DYLD_LIBRARY_PATH/foo.c: -------------------------------------------------------------------------------- 1 | 2 | int foo() 3 | { 4 | return RESULT; 5 | } 6 | -------------------------------------------------------------------------------- /unit-tests/test-cases/ignore-bad-files/foo.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005 Apple Computer, Inc. All rights reserved. 3 | * 4 | * @APPLE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. Please obtain a copy of the License at 10 | * http://www.opensource.apple.com/apsl/ and read it before using this 11 | * file. 12 | * 13 | * The Original Code and all software distributed under the License are 14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 | * Please see the License for the specific language governing rights and 19 | * limitations under the License. 20 | * 21 | * @APPLE_LICENSE_HEADER_END@ 22 | */ 23 | void foo() {} 24 | -------------------------------------------------------------------------------- /unit-tests/test-cases/image-count/Makefile: -------------------------------------------------------------------------------- 1 | 2 | TESTROOT = ../.. 3 | include ${TESTROOT}/include/common.makefile 4 | 5 | 6 | 7 | all-check: all check 8 | 9 | check: 10 | ./main 11 | 12 | all: 13 | ${CC} ${CCFLAGS} foo.c -dynamiclib -o libfoo.dylib 14 | ${CC} ${CCFLAGS} -I${TESTROOT}/include -o main main.c -I../../../include 15 | 16 | clean: 17 | ${RM} ${RMFLAGS} main libfoo.dylib 18 | -------------------------------------------------------------------------------- /unit-tests/test-cases/image-count/foo.c: -------------------------------------------------------------------------------- 1 | void foo() {} 2 | 3 | -------------------------------------------------------------------------------- /unit-tests/test-cases/image-remove-crash/Makefile: -------------------------------------------------------------------------------- 1 | TESTROOT = ../.. 2 | include ${TESTROOT}/include/common.makefile 3 | 4 | all-check: all check 5 | 6 | check: 7 | ./main 8 | 9 | all: 10 | ${CC} ${CCFLAGS} -I${TESTROOT}/include -o main main.c 11 | ${CC} ${CCFLAGS} -I${TESTROOT}/include -o foo.bundle foo.c -bundle 12 | 13 | 14 | 15 | clean: 16 | ${RM} ${RMFLAGS} *~ main foo.bundle 17 | 18 | -------------------------------------------------------------------------------- /unit-tests/test-cases/image-remove-crash/foo.c: -------------------------------------------------------------------------------- 1 | 2 | void foo() {} 3 | 4 | -------------------------------------------------------------------------------- /unit-tests/test-cases/image-remove-notification/foo.c: -------------------------------------------------------------------------------- 1 | 2 | void foo() {} 3 | 4 | -------------------------------------------------------------------------------- /unit-tests/test-cases/image-slide/foo.c: -------------------------------------------------------------------------------- 1 | void foo() {} 2 | 3 | -------------------------------------------------------------------------------- /unit-tests/test-cases/image-state-change/bar.c: -------------------------------------------------------------------------------- 1 | 2 | int bar = 10; 3 | -------------------------------------------------------------------------------- /unit-tests/test-cases/image-state-change/foo.c: -------------------------------------------------------------------------------- 1 | 2 | void foo() {} 3 | 4 | -------------------------------------------------------------------------------- /unit-tests/test-cases/image-state-deny-OFI/bar.c: -------------------------------------------------------------------------------- 1 | 2 | int bar = 10; 3 | -------------------------------------------------------------------------------- /unit-tests/test-cases/image-state-deny-OFI/foo.c: -------------------------------------------------------------------------------- 1 | 2 | void foo() {} 3 | 4 | -------------------------------------------------------------------------------- /unit-tests/test-cases/image-state-deny-all_image_infos/bar.c: -------------------------------------------------------------------------------- 1 | void bar() {} 2 | -------------------------------------------------------------------------------- /unit-tests/test-cases/image-state-deny-cache-leak/bar.c: -------------------------------------------------------------------------------- 1 | 2 | void bar() { } 3 | -------------------------------------------------------------------------------- /unit-tests/test-cases/image-state-deny-cache-leak/foo.c: -------------------------------------------------------------------------------- 1 | 2 | void foo() {} 3 | 4 | -------------------------------------------------------------------------------- /unit-tests/test-cases/image-state-deny-dlclose/foo.c: -------------------------------------------------------------------------------- 1 | 2 | void foo() {} 3 | 4 | -------------------------------------------------------------------------------- /unit-tests/test-cases/image-state-deny-leak/bar.c: -------------------------------------------------------------------------------- 1 | 2 | void bar() { } 3 | -------------------------------------------------------------------------------- /unit-tests/test-cases/image-state-deny-leak/foo.c: -------------------------------------------------------------------------------- 1 | 2 | void foo() {} 3 | 4 | -------------------------------------------------------------------------------- /unit-tests/test-cases/image-state-deny/bar.c: -------------------------------------------------------------------------------- 1 | 2 | int bar = 10; 3 | -------------------------------------------------------------------------------- /unit-tests/test-cases/image-state-deny/foo.c: -------------------------------------------------------------------------------- 1 | 2 | void foo() {} 3 | 4 | -------------------------------------------------------------------------------- /unit-tests/test-cases/image-state-dependents-initialized/foo.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | int foo_value = 1; 4 | 5 | void __attribute__((constructor)) setup_foo() 6 | { 7 | foo_value = 2; 8 | } 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /unit-tests/test-cases/image_header_containing_address/foo.c: -------------------------------------------------------------------------------- 1 | void foo() {} 2 | -------------------------------------------------------------------------------- /unit-tests/test-cases/image_path_containing_address/foo.c: -------------------------------------------------------------------------------- 1 | void foo() {} 2 | -------------------------------------------------------------------------------- /unit-tests/test-cases/initializer-bounds-check/bar.c: -------------------------------------------------------------------------------- 1 | 2 | int bar = 0; 3 | 4 | void altSecondInit() 5 | { 6 | bar = 1; 7 | } 8 | -------------------------------------------------------------------------------- /unit-tests/test-cases/initializer-bounds-check/foo1.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | extern void* initializers[] __asm__("section$start$__DATA$__mod_init_func"); 4 | 5 | extern void altSecondInit(); 6 | 7 | 8 | __attribute__((constructor)) 9 | void firstInit() 10 | { 11 | // slam second initializer to be pointer into another dylib 12 | initializers[1] = &altSecondInit; 13 | } 14 | 15 | -------------------------------------------------------------------------------- /unit-tests/test-cases/initializer-bounds-check/foo2.c: -------------------------------------------------------------------------------- 1 | #include // fprintf(), NULL 2 | #include // exit(), EXIT_SUCCESS 3 | 4 | #include "test.h" // PASS(), FAIL(), XPASS(), XFAIL() 5 | 6 | __attribute__((constructor)) 7 | void secondInit() 8 | { 9 | FAIL("initializer-bounds-check, second init called"); 10 | exit(0); 11 | } 12 | 13 | -------------------------------------------------------------------------------- /unit-tests/test-cases/interpose-basic-prebound/foo.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | bool check_dylib_interposing() 6 | { 7 | const char* x = strdup("123"); 8 | const char* y = strdup("456"); 9 | 10 | return ( (strcmp(x, "hello") == 0) && (strcmp(y, "hello") == 0) ); 11 | } 12 | 13 | -------------------------------------------------------------------------------- /unit-tests/test-cases/interpose-dynamic-dlsym/foo.c: -------------------------------------------------------------------------------- 1 | #include // fprintf(), NULL 2 | #include // exit(), EXIT_SUCCESS 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | 9 | int foo() { return 0; } 10 | 11 | int alt_foo() { return 10; } 12 | 13 | 14 | 15 | 16 | static const struct dyld_interpose_tuple sTable[] = { {&alt_foo, &foo} }; 17 | 18 | 19 | __attribute__((constructor)) 20 | void init() 21 | { 22 | // switch main executable to use alt_foo() when it calls foo() 23 | dyld_dynamic_interpose((const struct mach_header*)_NSGetMachExecuteHeader(), sTable, 1); 24 | 25 | } 26 | 27 | -------------------------------------------------------------------------------- /unit-tests/test-cases/interpose-dynamic-lazy/foo.c: -------------------------------------------------------------------------------- 1 | #include // fprintf(), NULL 2 | #include // exit(), EXIT_SUCCESS 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | 9 | 10 | int foo() { return 0; } 11 | 12 | int alt_foo() { return 10; } 13 | 14 | 15 | 16 | 17 | static const struct dyld_interpose_tuple sTable[] = { {&alt_foo, &foo} }; 18 | 19 | 20 | __attribute__((constructor)) 21 | void init() 22 | { 23 | 24 | dyld_dynamic_interpose((const struct mach_header*)_NSGetMachExecuteHeader(), sTable, 1); 25 | 26 | } 27 | 28 | -------------------------------------------------------------------------------- /unit-tests/test-cases/interpose-multiple/base.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "base.h" 3 | 4 | int base1() { return 1; } 5 | int base2() { return 2; } 6 | 7 | -------------------------------------------------------------------------------- /unit-tests/test-cases/interpose-multiple/base.h: -------------------------------------------------------------------------------- 1 | 2 | extern int base1(); 3 | extern int base2(); 4 | -------------------------------------------------------------------------------- /unit-tests/test-cases/interpose-multiple/foo1.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "base.h" 5 | #include "test.h" // PASS(), FAIL(), XPASS(), XFAIL() 6 | 7 | 8 | int (*p2)() = &base2; 9 | 10 | __attribute__((constructor)) 11 | void myinit() 12 | { 13 | if ( (*p2)() == 20 ) 14 | PASS("interpose-multiple"); 15 | else 16 | FAIL("interpose-multiple"); 17 | } 18 | 19 | 20 | int mybase1() 21 | { 22 | return 10; 23 | } 24 | 25 | 26 | DYLD_INTERPOSE(mybase1, base1) 27 | -------------------------------------------------------------------------------- /unit-tests/test-cases/interpose-multiple/foo2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "base.h" 5 | #include "test.h" // PASS(), FAIL(), XPASS(), XFAIL() 6 | 7 | int (*p1)() = &base1; 8 | 9 | __attribute__((constructor)) 10 | void myinit() 11 | { 12 | if ( (*p1)() == 10 ) 13 | PASS("interpose-multiple"); 14 | else 15 | FAIL("interpose-multiple"); 16 | } 17 | 18 | 19 | int mybase2() 20 | { 21 | return 20; 22 | } 23 | 24 | 25 | DYLD_INTERPOSE(mybase2, base2) 26 | -------------------------------------------------------------------------------- /unit-tests/test-cases/lazy-binding-reg-params/foo.h: -------------------------------------------------------------------------------- 1 | #include // fprintf(), NULL 2 | 3 | 4 | extern 5 | #if __i386__ 6 | __attribute__((regparm(3))) 7 | #endif 8 | bool dointtest(int p1, int p2, int p3, int p4, int p5); 9 | 10 | #if __ppc__ || __ppc64__ 11 | extern bool dofloattest(double,double,double,double,double,double,double,double,double,double,double,double,double); 12 | #endif 13 | 14 | 15 | #if __i386__ || __x86_64__ || __ppc__ || __ppc64__ 16 | 17 | #if __i386__ || __x86_64__ 18 | typedef float vFloat __attribute__ ((__vector_size__ (16))); 19 | #elif __ppc__ || __ppc64__ 20 | typedef __vector float vFloat; 21 | #endif 22 | 23 | extern bool dovectortest(vFloat, vFloat, vFloat, vFloat, vFloat); 24 | 25 | #endif -------------------------------------------------------------------------------- /unit-tests/test-cases/lazy-dylib-init-order/expected.out: -------------------------------------------------------------------------------- 1 | main_init 2 | main 3 | foo_init 4 | foo 5 | foo_term 6 | main_term 7 | -------------------------------------------------------------------------------- /unit-tests/test-cases/lazy-dylib-init-order/foo.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | int foo() 5 | { 6 | printf("foo\n"); 7 | return 1; 8 | } 9 | int bar() { return 1; } 10 | 11 | 12 | static __attribute__((constructor)) void foo_init() 13 | { 14 | printf("foo_init\n"); 15 | } 16 | 17 | static __attribute__((destructor)) void foo_term() 18 | { 19 | printf("foo_term\n"); 20 | } 21 | 22 | -------------------------------------------------------------------------------- /unit-tests/test-cases/lazy-dylib-init-order/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | extern int foo(); 6 | extern int bar(); 7 | 8 | static __attribute__((constructor)) void main_init() 9 | { 10 | printf("main_init\n"); 11 | } 12 | 13 | static __attribute__((destructor)) void main_term() 14 | { 15 | printf("main_term\n"); 16 | } 17 | 18 | 19 | int main() 20 | { 21 | printf("main\n"); 22 | foo(); 23 | return 0; 24 | } 25 | 26 | -------------------------------------------------------------------------------- /unit-tests/test-cases/lazy-dylib-missing-dylib/foo.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | int foo() 4 | { 5 | return 1; 6 | } 7 | -------------------------------------------------------------------------------- /unit-tests/test-cases/lazy-dylib-missing-symbol/foo.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | int foo() 4 | { 5 | return 1; 6 | } 7 | 8 | #if BAR 9 | int bar() 10 | { 11 | return 1; 12 | } 13 | #endif 14 | 15 | 16 | -------------------------------------------------------------------------------- /unit-tests/test-cases/loader_path-symlink/bar.c: -------------------------------------------------------------------------------- 1 | void bar() 2 | { 3 | } 4 | -------------------------------------------------------------------------------- /unit-tests/test-cases/loader_path-symlink/foo.c: -------------------------------------------------------------------------------- 1 | void foo() 2 | { 3 | } 4 | -------------------------------------------------------------------------------- /unit-tests/test-cases/loader_path-symlink/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "test.h" 6 | 7 | extern void foo(); 8 | 9 | int main() 10 | { 11 | foo(); 12 | PASS("loader_path-symlink"); 13 | return EXIT_SUCCESS; 14 | } 15 | -------------------------------------------------------------------------------- /unit-tests/test-cases/loader_path/bar.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005 Apple Computer, Inc. All rights reserved. 3 | * 4 | * @APPLE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. Please obtain a copy of the License at 10 | * http://www.opensource.apple.com/apsl/ and read it before using this 11 | * file. 12 | * 13 | * The Original Code and all software distributed under the License are 14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 | * Please see the License for the specific language governing rights and 19 | * limitations under the License. 20 | * 21 | * @APPLE_LICENSE_HEADER_END@ 22 | */ 23 | void bar() {} 24 | -------------------------------------------------------------------------------- /unit-tests/test-cases/non-lazy-slide/bar.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | int bar = 10; 4 | -------------------------------------------------------------------------------- /unit-tests/test-cases/non-lazy-slide/foo.c: -------------------------------------------------------------------------------- 1 | 2 | extern int bar; 3 | 4 | int foo() 5 | { 6 | return bar; 7 | } 8 | -------------------------------------------------------------------------------- /unit-tests/test-cases/non-lazy-slide/main.c: -------------------------------------------------------------------------------- 1 | #include // fprintf(), NULL 2 | #include // exit(), EXIT_SUCCESS 3 | #include 4 | 5 | #include "test.h" // PASS(), FAIL(), XPASS(), XFAIL() 6 | 7 | // libfoo.dylib is built from multiple source files 8 | // It internally uses non-lazy pointer to compute 9 | // the result for foo() 10 | 11 | 12 | extern int foo(); 13 | 14 | int main() 15 | { 16 | if ( foo() == 10 ) 17 | PASS("non-lazy-slide"); 18 | else 19 | FAIL("non-lazy-slide"); 20 | return EXIT_SUCCESS; 21 | } 22 | 23 | 24 | -------------------------------------------------------------------------------- /unit-tests/test-cases/non-lazy-weak/bar.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | __attribute__((weak)) int bar = 10; 4 | -------------------------------------------------------------------------------- /unit-tests/test-cases/non-lazy-weak/foo.c: -------------------------------------------------------------------------------- 1 | 2 | extern int bar; 3 | 4 | int foo() 5 | { 6 | return bar; 7 | } 8 | -------------------------------------------------------------------------------- /unit-tests/test-cases/non-lazy-weak/main.c: -------------------------------------------------------------------------------- 1 | #include // fprintf(), NULL 2 | #include // exit(), EXIT_SUCCESS 3 | #include 4 | 5 | #include "test.h" // PASS(), FAIL(), XPASS(), XFAIL() 6 | 7 | // libfoo.dylib has a weak global variable that foo() returns 8 | 9 | extern int foo(); 10 | 11 | int main() 12 | { 13 | if ( foo() == 10 ) 14 | PASS("non-lazy-weak"); 15 | else 16 | FAIL("non-lazy-weak"); 17 | return EXIT_SUCCESS; 18 | } 19 | 20 | 21 | -------------------------------------------------------------------------------- /unit-tests/test-cases/operator-new-dylib/Makefile: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | # 6 | # test that if the main executable overrides operator new 7 | # that a dylib using operator new is redirected to it. 8 | # 9 | # 10 | 11 | TESTROOT = ../.. 12 | include ${TESTROOT}/include/common.makefile 13 | 14 | 15 | all-check: all check 16 | 17 | check: 18 | ./main 19 | 20 | all: main 21 | 22 | 23 | main: main.cxx libfoo.dylib 24 | ${CXX} ${CXXFLAGS} -I${TESTROOT}/include -o main main.cxx libfoo.dylib 25 | 26 | libfoo.dylib: foo.cxx 27 | ${CXX} ${CXXFLAGS} -dynamiclib foo.cxx -o libfoo.dylib 28 | 29 | 30 | 31 | clean: 32 | ${RM} ${RMFLAGS} *~ main libfoo.dylib 33 | 34 | -------------------------------------------------------------------------------- /unit-tests/test-cases/operator-new-dylib/foo.cxx: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | 6 | 7 | 8 | 9 | char* foo() 10 | { 11 | return new char[24]; 12 | } 13 | 14 | -------------------------------------------------------------------------------- /unit-tests/test-cases/operator-new-dylib/main.cxx: -------------------------------------------------------------------------------- 1 | #include // fprintf(), NULL 2 | #include // exit(), EXIT_SUCCESS 3 | 4 | #include "test.h" // PASS(), FAIL(), XPASS(), XFAIL() 5 | 6 | #include 7 | #include 8 | 9 | 10 | extern char* foo(); 11 | 12 | static char all[] = "hello"; 13 | 14 | void* operator new[](std::size_t) throw (std::bad_alloc) 15 | { 16 | return all; 17 | } 18 | 19 | 20 | int main() 21 | { 22 | char* newArray = new char[24]; 23 | char* fromFoo = foo(); 24 | 25 | if ( fromFoo == newArray ) 26 | PASS("operator-new-dylib"); 27 | else 28 | FAIL("operator-new-dylib"); 29 | return EXIT_SUCCESS; 30 | } 31 | 32 | -------------------------------------------------------------------------------- /unit-tests/test-cases/pie-dylib/Makefile: -------------------------------------------------------------------------------- 1 | TESTROOT = ../.. 2 | include ${TESTROOT}/include/common.makefile 3 | 4 | # 5 | # If pie, ignore preferred load address 6 | # 7 | # run a PIE four times and verify libfoo.dylib load address was different every time 8 | # 9 | 10 | FOO_ADDRESS = 0x10000000 11 | 12 | ifeq "x86_64" "$(ARCH)" 13 | FOO_ADDRESS = 0x300000000 14 | endif 15 | 16 | 17 | all-check: all check 18 | 19 | check: 20 | ./main > main.out 21 | ./main >> main.out 22 | ./main >> main.out 23 | ./main >> main.out 24 | if [ `sort main.out -u | wc -l` == 4 ]; \ 25 | then \ 26 | echo "PASS pie-dylib"; \ 27 | else \ 28 | echo "FAIL pie-dylib"; \ 29 | fi; \ 30 | 31 | all: main 32 | 33 | main : main.c libfoo.dylib 34 | ${CC} ${CCFLAGS} -I${TESTROOT}/include -Wl,-pie libfoo.dylib -o main main.c 35 | 36 | libfoo.dylib : foo.c 37 | ${CC} ${CCFLAGS} foo.c -dynamiclib -o libfoo.dylib -seg1addr ${FOO_ADDRESS} 38 | 39 | clean: 40 | ${RM} ${RMFLAGS} *~ main main.out libfoo.dylib 41 | 42 | -------------------------------------------------------------------------------- /unit-tests/test-cases/pie-dylib/foo.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void foo() 5 | { 6 | printf("&foo=%p\n", &foo); 7 | } 8 | -------------------------------------------------------------------------------- /unit-tests/test-cases/pie-dylib/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | extern void foo(); 5 | 6 | int main() 7 | { 8 | foo(); 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /unit-tests/test-cases/re-export-dylib/bar.c: -------------------------------------------------------------------------------- 1 | int bar() 2 | { 3 | return 1; 4 | } 5 | 6 | 7 | -------------------------------------------------------------------------------- /unit-tests/test-cases/re-export-dylib/foo.c: -------------------------------------------------------------------------------- 1 | int foo() 2 | { 3 | return 0; 4 | } 5 | 6 | -------------------------------------------------------------------------------- /unit-tests/test-cases/re-export-framework/bar.c: -------------------------------------------------------------------------------- 1 | int bar() 2 | { 3 | return 1; 4 | } 5 | 6 | 7 | -------------------------------------------------------------------------------- /unit-tests/test-cases/re-export-framework/foo.c: -------------------------------------------------------------------------------- 1 | int foo() 2 | { 3 | return 0; 4 | } 5 | 6 | -------------------------------------------------------------------------------- /unit-tests/test-cases/re-export-sub-framework/bar.c: -------------------------------------------------------------------------------- 1 | int bar() 2 | { 3 | return 1; 4 | } 5 | 6 | 7 | -------------------------------------------------------------------------------- /unit-tests/test-cases/re-export-sub-framework/foo.c: -------------------------------------------------------------------------------- 1 | int foo() 2 | { 3 | return 0; 4 | } 5 | 6 | -------------------------------------------------------------------------------- /unit-tests/test-cases/re-export-symbol-dylib/bar.c: -------------------------------------------------------------------------------- 1 | 2 | int bar(void) 3 | { 4 | return 2; 5 | } 6 | -------------------------------------------------------------------------------- /unit-tests/test-cases/re-export-symbol-dylib/baz.c: -------------------------------------------------------------------------------- 1 | int baz() 2 | { 3 | return 3; 4 | } 5 | 6 | -------------------------------------------------------------------------------- /unit-tests/test-cases/re-export-symbol-dylib/baz.exp: -------------------------------------------------------------------------------- 1 | _baz 2 | _frob 3 | -------------------------------------------------------------------------------- /unit-tests/test-cases/re-export-symbol-dylib/foo.c: -------------------------------------------------------------------------------- 1 | int foo(void) 2 | { 3 | return 1; 4 | } 5 | -------------------------------------------------------------------------------- /unit-tests/test-cases/re-export-symbol-dylib/foo.exp: -------------------------------------------------------------------------------- 1 | _foo 2 | _bar 3 | _baz 4 | _frob 5 | -------------------------------------------------------------------------------- /unit-tests/test-cases/re-export-symbol-dylib/frob.c: -------------------------------------------------------------------------------- 1 | int frob() 2 | { 3 | return 4; 4 | } 5 | 6 | -------------------------------------------------------------------------------- /unit-tests/test-cases/re-export-symbol/bar.c: -------------------------------------------------------------------------------- 1 | 2 | int bar(void) 3 | { 4 | return 10; 5 | } 6 | -------------------------------------------------------------------------------- /unit-tests/test-cases/re-export-symbol/foo.c: -------------------------------------------------------------------------------- 1 | int foo(void) 2 | { 3 | return 10; 4 | } 5 | -------------------------------------------------------------------------------- /unit-tests/test-cases/re-export-symbol/foo.exp: -------------------------------------------------------------------------------- 1 | _foo 2 | _bar 3 | -------------------------------------------------------------------------------- /unit-tests/test-cases/re-export-symbol/foo2.exp: -------------------------------------------------------------------------------- 1 | _foo 2 | _mybar 3 | -------------------------------------------------------------------------------- /unit-tests/test-cases/re-export-symbol/main1.c: -------------------------------------------------------------------------------- 1 | #include // fprintf(), NULL 2 | #include // exit(), EXIT_SUCCESS 3 | #include 4 | 5 | #include "test.h" // PASS(), FAIL(), XPASS(), XFAIL() 6 | 7 | extern int foo(); 8 | extern int bar(); 9 | 10 | int (*pbar)() = &bar; 11 | 12 | 13 | int main() 14 | { 15 | if ( foo() != 10 ) 16 | FAIL("re-export-symbol: foo() returned wrong value"); 17 | if ( bar() != 10 ) 18 | FAIL("re-export-symbol: bar() returned wrong value"); 19 | if ( (*pbar)() != 10 ) 20 | FAIL("re-export-symbol: (*pbar)() returned wrong value"); 21 | PASS("re-export-symbol"); 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /unit-tests/test-cases/re-export-symbol/main2.c: -------------------------------------------------------------------------------- 1 | 2 | #include // fprintf(), NULL 3 | #include // exit(), EXIT_SUCCESS 4 | #include 5 | 6 | #include "test.h" // PASS(), FAIL(), XPASS(), XFAIL() 7 | 8 | 9 | 10 | extern int foo(); 11 | extern int mybar(); 12 | 13 | int (*pmybar)() = &mybar; 14 | 15 | int main() 16 | { 17 | if ( foo() != 10 ) 18 | FAIL("re-export-symbol: foo() returned wrong value"); 19 | if ( mybar() != 10 ) 20 | FAIL("re-export-symbol: mybar() returned wrong value"); 21 | if ( (*pmybar)() != 10 ) 22 | FAIL("re-export-symbol: (*pmybar)() returned wrong value"); 23 | PASS("re-export-symbol"); 24 | return 0; 25 | } 26 | 27 | -------------------------------------------------------------------------------- /unit-tests/test-cases/read-only-import-shared-cache-coalesce/main.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | int main() 5 | { 6 | // dynamically load libfoo.dylib which depends on libstdc++.dylib 7 | // being re-bound to libfoo's operator new. 8 | dlopen("libfoo.dylib", RTLD_LAZY); 9 | return 0; 10 | } 11 | 12 | 13 | -------------------------------------------------------------------------------- /unit-tests/test-cases/read-only-import-shared-cache-dlopen-override/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "test.h" 4 | 5 | int main() 6 | { 7 | // dynamically load libz.dylib which imports _malloc from libSystem 8 | dlopen("/usr/lib/libz.dylib", RTLD_LAZY); 9 | 10 | 11 | PASS("read-only-import-shared-cache-dlopen-override"); 12 | return 0; 13 | } 14 | 15 | -------------------------------------------------------------------------------- /unit-tests/test-cases/read-only-import-shared-cache-dlopen-override/mymalloc.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void* mymalloc(size_t s) 5 | { 6 | return malloc(s); 7 | } 8 | 9 | DYLD_INTERPOSE(mymalloc, malloc) 10 | -------------------------------------------------------------------------------- /unit-tests/test-cases/restrict-executable_path/foo.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | int foo() { return 1; } 4 | 5 | 6 | -------------------------------------------------------------------------------- /unit-tests/test-cases/restrict-executable_path/main.c: -------------------------------------------------------------------------------- 1 | #include // fprintf(), NULL 2 | #include // exit(), EXIT_SUCCESS 3 | #include // strcmp(), strncmp() 4 | #include // issetugid 5 | #include "test.h" // PASS(), FAIL(), XPASS(), XFAIL() 6 | 7 | 8 | extern int foo(); 9 | 10 | int main(int argc, const char* argv[]) 11 | { 12 | foo(); 13 | return EXIT_SUCCESS; 14 | } 15 | -------------------------------------------------------------------------------- /unit-tests/test-cases/rpath-DYLD_ROOT_PATH/Makefile: -------------------------------------------------------------------------------- 1 | 2 | TESTROOT = ../.. 3 | include ${TESTROOT}/include/common.makefile 4 | 5 | 6 | # 7 | # DYLD_ROOT_PATH should apply to LC_RPATH rpaths 8 | # 9 | 10 | all-check: all check 11 | 12 | check: 13 | export DYLD_ROOT_PATH=`pwd` && ${PASS_IFF} ./main 14 | 15 | all: main 16 | 17 | 18 | hide/libfoo.dylib : foo.c 19 | mkdir -p hide 20 | ${CC} foo.c -dynamiclib -o hide/libfoo.dylib -install_name @rpath/libfoo.dylib 21 | 22 | 23 | main : main.c hide/libfoo.dylib 24 | ${CC} -I${TESTROOT}/include main.c -o main hide/libfoo.dylib -Wl,-rpath -Wl,/hide 25 | 26 | 27 | clean: 28 | ${RM} ${RMFLAGS} *~ main hide 29 | -------------------------------------------------------------------------------- /unit-tests/test-cases/rpath-DYLD_ROOT_PATH/foo.c: -------------------------------------------------------------------------------- 1 | int foo() 2 | { 3 | return 1; 4 | } 5 | -------------------------------------------------------------------------------- /unit-tests/test-cases/rpath-DYLD_ROOT_PATH/main.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | 6 | #include "test.h" 7 | 8 | extern int foo(); 9 | 10 | int main() 11 | { 12 | if ( foo() ) 13 | return EXIT_SUCCESS; 14 | else 15 | return EXIT_FAILURE; 16 | } 17 | -------------------------------------------------------------------------------- /unit-tests/test-cases/rpath-basic/bar.c: -------------------------------------------------------------------------------- 1 | void bar() 2 | { 3 | } 4 | -------------------------------------------------------------------------------- /unit-tests/test-cases/rpath-basic/foo.c: -------------------------------------------------------------------------------- 1 | void foo() 2 | { 3 | } 4 | -------------------------------------------------------------------------------- /unit-tests/test-cases/rpath-dlopen-in-dylib/foo.c: -------------------------------------------------------------------------------- 1 | void foo() 2 | { 3 | } 4 | -------------------------------------------------------------------------------- /unit-tests/test-cases/rpath-dlopen-indirect/bar.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | 6 | #include "test.h" 7 | 8 | void bar() 9 | { 10 | void* handle = dlopen("libfoo.dylib", RTLD_LAZY); 11 | if ( handle == NULL ) { 12 | FAIL("rpath-dlopen-indirect: %s", dlerror()); 13 | exit(EXIT_SUCCESS); 14 | } 15 | 16 | void* pFoo = dlsym(handle, "foo"); 17 | if ( pFoo == NULL ) { 18 | FAIL("rpath-dlopen-indirect: %s", dlerror()); 19 | exit(EXIT_SUCCESS); 20 | } 21 | } 22 | 23 | 24 | -------------------------------------------------------------------------------- /unit-tests/test-cases/rpath-executable_path/bar.c: -------------------------------------------------------------------------------- 1 | extern void foo(); 2 | 3 | void bar() 4 | { 5 | foo(); 6 | } 7 | 8 | 9 | -------------------------------------------------------------------------------- /unit-tests/test-cases/rpath-executable_path/foo.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | void foo() 4 | { 5 | } 6 | -------------------------------------------------------------------------------- /unit-tests/test-cases/rpath-indirect-suid/bar.c: -------------------------------------------------------------------------------- 1 | 2 | void bar() 3 | { 4 | } 5 | 6 | 7 | -------------------------------------------------------------------------------- /unit-tests/test-cases/rpath-indirect-suid/foo.c: -------------------------------------------------------------------------------- 1 | void foo() 2 | { 3 | } 4 | -------------------------------------------------------------------------------- /unit-tests/test-cases/rpath-indirect-suid/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "test.h" 6 | 7 | extern void foo(); 8 | 9 | int main() 10 | { 11 | foo(); 12 | #if DEFAULT_FAIL 13 | FAIL("rpath-indirect-setuid"); 14 | #else 15 | PASS("rpath-indirect-setuid"); 16 | #endif 17 | return EXIT_SUCCESS; 18 | } 19 | -------------------------------------------------------------------------------- /unit-tests/test-cases/rpath-introspection/foo.c: -------------------------------------------------------------------------------- 1 | void foo() 2 | { 3 | } 4 | -------------------------------------------------------------------------------- /unit-tests/test-cases/rpath-loader_path-dlopen/bar.c: -------------------------------------------------------------------------------- 1 | extern void baz(); 2 | 3 | void bar() 4 | { 5 | baz(); 6 | } 7 | 8 | 9 | -------------------------------------------------------------------------------- /unit-tests/test-cases/rpath-loader_path-dlopen/baz.c: -------------------------------------------------------------------------------- 1 | 2 | void baz() 3 | { 4 | } 5 | 6 | 7 | -------------------------------------------------------------------------------- /unit-tests/test-cases/rpath-loader_path-dlopen/foo.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | bool foo() 6 | { 7 | return (dlopen("./libbar.dylib", RTLD_NOW) != NULL); 8 | } 9 | -------------------------------------------------------------------------------- /unit-tests/test-cases/rpath-no-trailing-slash/foo.c: -------------------------------------------------------------------------------- 1 | void foo() 2 | { 3 | } 4 | -------------------------------------------------------------------------------- /unit-tests/test-cases/rpath-no-trailing-slash/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "test.h" 6 | 7 | extern void foo(); 8 | 9 | int main() 10 | { 11 | foo(); 12 | PASS("rpath-no-trailing-slash"); 13 | return EXIT_SUCCESS; 14 | } 15 | -------------------------------------------------------------------------------- /unit-tests/test-cases/shared-region-overlap/main.c: -------------------------------------------------------------------------------- 1 | #include // EXIT_SUCCESS 2 | 3 | #include "test.h" 4 | 5 | 6 | int 7 | main() 8 | { 9 | return EXIT_SUCCESS; 10 | } 11 | 12 | 13 | -------------------------------------------------------------------------------- /unit-tests/test-cases/suid-executable_path/foo.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | int foo() { return 1; } 4 | 5 | 6 | -------------------------------------------------------------------------------- /unit-tests/test-cases/symbol-resolver-interposed/foo.h: -------------------------------------------------------------------------------- 1 | 2 | extern int foo(); 3 | extern void set_foo(int); 4 | -------------------------------------------------------------------------------- /unit-tests/test-cases/symbol-resolver-interposed/myfoo.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include "foo.h" 4 | 5 | int myfoo() 6 | { 7 | foo(); 8 | return 20; 9 | } 10 | 11 | DYLD_INTERPOSE(myfoo, foo) 12 | -------------------------------------------------------------------------------- /unit-tests/test-cases/symbol-resolver-lazy-prebound/bar.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/antons/dyld-shared-cache-big-sur/abdd035bdfda33998cc80cd06b625cd99563ca33/unit-tests/test-cases/symbol-resolver-lazy-prebound/bar.o -------------------------------------------------------------------------------- /unit-tests/test-cases/text-relocs/bind.c: -------------------------------------------------------------------------------- 1 | 2 | extern int y; 3 | 4 | int test() 5 | { 6 | return y; 7 | } 8 | -------------------------------------------------------------------------------- /unit-tests/test-cases/text-relocs/space.s: -------------------------------------------------------------------------------- 1 | .text 2 | .align 2 3 | _junk: .space 1024*1024 4 | -------------------------------------------------------------------------------- /unit-tests/test-cases/threaded-flat-lookup/client.c: -------------------------------------------------------------------------------- 1 | 2 | extern void foo(); 3 | extern void bar(); 4 | extern void baz(); 5 | 6 | void doit() 7 | { 8 | foo(); 9 | bar(); 10 | baz(); 11 | } 12 | -------------------------------------------------------------------------------- /unit-tests/test-cases/threaded-flat-lookup/foo.c: -------------------------------------------------------------------------------- 1 | 2 | void foo() {} 3 | void bar() {} 4 | void baz() {} 5 | -------------------------------------------------------------------------------- /unit-tests/test-cases/threaded-lazy-bind/gen.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | int main() 5 | { 6 | int i; 7 | for (i = 0; i < 1000; ++i) { 8 | printf("int do_%03d() { return %d; }\n", i, i); 9 | } 10 | 11 | for (i = 0; i < 1000; ++i) { 12 | printf("extern int do_%03d();\n", i); 13 | } 14 | for (i = 0; i < 1000; ++i) { 15 | printf("if ( do_%03d() != %d ) { FAIL(\"iteration %d\"); exit(0); }\n", i, i, i); 16 | } 17 | 18 | return 0; 19 | } -------------------------------------------------------------------------------- /unit-tests/test-cases/tlv-dylib/foo.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | __thread int a; 5 | __thread int b = 5; 6 | 7 | 8 | int getB() { return b; } 9 | -------------------------------------------------------------------------------- /unit-tests/test-cases/tlv-initializer/get.s: -------------------------------------------------------------------------------- 1 | 2 | #if __x86_64__ 3 | 4 | # _myinit sets up TLV content 5 | .thread_init_func 6 | .quad _myinit 7 | 8 | #endif 9 | 10 | #if __i386__ 11 | 12 | # _myinit sets up TLV content 13 | .thread_init_func 14 | .long _myinit 15 | 16 | #endif 17 | 18 | .subsections_via_symbols 19 | -------------------------------------------------------------------------------- /unit-tests/test-cases/tlv-terminators/init.s: -------------------------------------------------------------------------------- 1 | 2 | # _myinit sets up TLV content 3 | .thread_init_func 4 | #if __LP64__ 5 | .quad _myinit 6 | #else 7 | .long _myinit 8 | #endif 9 | 10 | .subsections_via_symbols 11 | -------------------------------------------------------------------------------- /unit-tests/test-cases/trie-symbol-overrun/foo.c: -------------------------------------------------------------------------------- 1 | 2 | void abc() 3 | { 4 | } 5 | 6 | void abcdefghi() 7 | { 8 | } 9 | 10 | void abcdee() 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /unit-tests/test-cases/upward-dylib-init-order/b.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "common.h" 3 | 4 | 5 | 6 | static __attribute__((constructor)) void myInit() 7 | { 8 | setB(); 9 | //fprintf(stderr, "init b\n"); 10 | } 11 | -------------------------------------------------------------------------------- /unit-tests/test-cases/upward-dylib-init-order/c.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | 5 | static __attribute__((constructor)) void myInit() 6 | { 7 | //fprintf(stderr, "init c\n"); 8 | } 9 | -------------------------------------------------------------------------------- /unit-tests/test-cases/upward-dylib-init-order/common.c: -------------------------------------------------------------------------------- 1 | #include "common.h" 2 | #include 3 | 4 | static bool b = false; 5 | static bool u = false; 6 | static bool u2 = false; 7 | static bool isOk = true; 8 | 9 | void setB() 10 | { 11 | if ( u || b || u2 ) 12 | isOk = false; 13 | b = true; 14 | } 15 | 16 | void setU() 17 | { 18 | if ( u || u2 ) 19 | isOk = false; 20 | u = true; 21 | } 22 | 23 | void setU2() 24 | { 25 | if ( u2 ) 26 | isOk = false; 27 | u2 = true; 28 | } 29 | 30 | // return true iff 31 | // setB() was called, then setU() 32 | bool ok() 33 | { 34 | //fprintf(stderr, "isOk=%d, u=%d, b=%d\n", isOk, u, b); 35 | return isOk && u && b && u2; 36 | } 37 | 38 | -------------------------------------------------------------------------------- /unit-tests/test-cases/upward-dylib-init-order/common.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | extern void setB(); 4 | extern void setU(); 5 | extern void setU2(); 6 | 7 | extern bool ok(); 8 | 9 | -------------------------------------------------------------------------------- /unit-tests/test-cases/upward-dylib-init-order/main.c: -------------------------------------------------------------------------------- 1 | #include // fprintf(), NULL 2 | #include // exit(), EXIT_SUCCESS 3 | 4 | #include "test.h" // PASS(), FAIL(), XPASS(), XFAIL() 5 | 6 | 7 | #include "common.h" 8 | 9 | int main() 10 | { 11 | if ( ok() ) 12 | PASS("upward-dylib-init-order"); 13 | else 14 | FAIL("upward-dylib-init-order"); 15 | 16 | return EXIT_SUCCESS; 17 | } 18 | 19 | 20 | -------------------------------------------------------------------------------- /unit-tests/test-cases/upward-dylib-init-order/u.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "common.h" 3 | 4 | 5 | static __attribute__((constructor)) void myInit() 6 | { 7 | setU(); 8 | //fprintf(stderr, "init u\n"); 9 | } 10 | 11 | -------------------------------------------------------------------------------- /unit-tests/test-cases/upward-dylib-init-order/u2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "common.h" 3 | 4 | 5 | static __attribute__((constructor)) void myInit() 6 | { 7 | setU2(); 8 | //fprintf(stderr, "init u2\n"); 9 | } 10 | 11 | -------------------------------------------------------------------------------- /unit-tests/test-cases/upward-dylib/down.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "up.h" 3 | 4 | static int state = 0; 5 | 6 | 7 | // should run second because down.dylib is lower than up.dylib 8 | static __attribute__((constructor)) void myInit3() 9 | { 10 | //fprintf(stderr, "myInit3()\n"); 11 | state = 1; 12 | } 13 | 14 | int getdown() 15 | { 16 | return state; 17 | } 18 | 19 | int getdownsup() 20 | { 21 | return whatsup(); 22 | } -------------------------------------------------------------------------------- /unit-tests/test-cases/upward-dylib/down.h: -------------------------------------------------------------------------------- 1 | extern int getdown(); 2 | extern int getdownsup(); 3 | 4 | -------------------------------------------------------------------------------- /unit-tests/test-cases/upward-dylib/main.c: -------------------------------------------------------------------------------- 1 | #include // fprintf(), NULL 2 | #include // exit(), EXIT_SUCCESS 3 | 4 | #include "test.h" // PASS(), FAIL(), XPASS(), XFAIL() 5 | 6 | 7 | #include "up.h" 8 | #include "down.h" 9 | 10 | int main() 11 | { 12 | if ( whatsup() ) 13 | PASS("upward-dylib"); 14 | else 15 | FAIL("upward-dylib"); 16 | 17 | return EXIT_SUCCESS; 18 | } 19 | 20 | 21 | -------------------------------------------------------------------------------- /unit-tests/test-cases/upward-dylib/main2.c: -------------------------------------------------------------------------------- 1 | #include // fprintf(), NULL 2 | #include // exit(), EXIT_SUCCESS 3 | 4 | #include "test.h" // PASS(), FAIL(), XPASS(), XFAIL() 5 | 6 | 7 | #include "up.h" 8 | #include "down.h" 9 | 10 | int main() 11 | { 12 | if ( getdownsup() ) 13 | PASS("upward-dylib"); 14 | else 15 | FAIL("upward-dylib"); 16 | 17 | return EXIT_SUCCESS; 18 | } 19 | 20 | 21 | -------------------------------------------------------------------------------- /unit-tests/test-cases/upward-dylib/up.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "down.h" 3 | 4 | static int state = 0; 5 | 6 | #ifndef STUB 7 | // should run second because up.dylib is higher than down.dylib 8 | static __attribute__((constructor)) void myInit1() 9 | { 10 | //fprintf(stderr, "myInit1()\n"); 11 | if ( getdown() ) { 12 | state = 1; 13 | } 14 | } 15 | #endif 16 | 17 | int whatsup() 18 | { 19 | return state; 20 | } 21 | 22 | -------------------------------------------------------------------------------- /unit-tests/test-cases/upward-dylib/up.h: -------------------------------------------------------------------------------- 1 | 2 | extern int whatsup(); 3 | -------------------------------------------------------------------------------- /unit-tests/test-cases/weak-coalesce-c++/a1.cc: -------------------------------------------------------------------------------- 1 | #include "a.h" 2 | 3 | int get_x_1 (void) { return wrapper::x; } 4 | void set_x_1 (int x_) { wrapper::x = x_; } 5 | -------------------------------------------------------------------------------- /unit-tests/test-cases/weak-coalesce-c++/a2.cc: -------------------------------------------------------------------------------- 1 | #include "a.h" 2 | 3 | int get_x_2 (void) { return wrapper::x; } 4 | void set_x_2 (int x_) { wrapper::x = x_; } 5 | -------------------------------------------------------------------------------- /unit-tests/test-cases/weak-coalesce-c++/main.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include // exit(), EXIT_SUCCESS 3 | 4 | #include "test.h" // PASS(), FAIL(), XPASS(), XFAIL() 5 | 6 | extern void set_x_1(int); 7 | extern void set_x_2(int); 8 | extern int get_x_1(void); 9 | extern int get_x_2(void); 10 | 11 | int main() 12 | { 13 | set_x_1 (17); 14 | set_x_2 (76); 15 | 16 | if (get_x_1() == 76 && get_x_2() == 76) 17 | PASS("weak-coalesce=c++"); 18 | else 19 | FAIL("weak-coalesce=c++"); 20 | } 21 | -------------------------------------------------------------------------------- /unit-tests/test-cases/weak-coalesce-stubs/Makefile: -------------------------------------------------------------------------------- 1 | 2 | TESTROOT = ../.. 3 | include ${TESTROOT}/include/common.makefile 4 | 5 | 6 | all-check: all check 7 | 8 | check: 9 | ./main 10 | 11 | all: 12 | $(CC) $(CCFLAGS) -I${TESTROOT}/include main.c -o main 13 | $(CC) $(CCFLAGS) bar.c -dynamiclib -o libbar.dylib 14 | $(CC) $(CCFLAGS) foo.c -dynamiclib -o libfoo.dylib 15 | $(STRIP) -c -x libfoo.dylib -o libstub.dylib 16 | 17 | clean: 18 | ${RM} ${RMFLAGS} libbar.dylib libfoo.dylib libstub.dylib main 19 | -------------------------------------------------------------------------------- /unit-tests/test-cases/weak-coalesce-stubs/bar.c: -------------------------------------------------------------------------------- 1 | void bar() {} 2 | 3 | void foo() __attribute__((weak)); 4 | void foo() 5 | { 6 | } -------------------------------------------------------------------------------- /unit-tests/test-cases/weak-coalesce-stubs/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include // exit(), EXIT_SUCCESS 4 | 5 | #include "test.h" // PASS(), FAIL(), XPASS(), XFAIL() 6 | 7 | // Loading MH_DYLIB_STUB causing coalescable miscount 8 | 9 | int main() 10 | { 11 | // try to load stub many times 12 | for (int i=0; i < 10; ++i) { 13 | void* handle = dlopen("libstub.dylib", RTLD_LAZY); 14 | if ( handle != NULL ) { 15 | FAIL("weak-coalesce-stubs: load of libstub.dylib unexpectedly succeeded"); 16 | } 17 | } 18 | // try to load real dylib 19 | dlopen("libbar.dylib", RTLD_LAZY); 20 | PASS("weak-coalesce-stubs"); 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /unit-tests/test-cases/weak-external-reloc-flat/Makefile: -------------------------------------------------------------------------------- 1 | 2 | 3 | TESTROOT = ../.. 4 | include ${TESTROOT}/include/common.makefile 5 | 6 | 7 | # 8 | # flat_namespace and weak binding conflict 9 | # 10 | # Note that libfoo.dylib is built flat-namespace 11 | # 12 | 13 | all-check: all check 14 | 15 | check: 16 | ./main 17 | 18 | all: main 19 | 20 | main: main.c libfoo.dylib 21 | ${CC} ${CCFLAGS} -I${TESTROOT}/include -o main main.c libfoo.dylib 22 | 23 | libfoo.dylib: foo.c libbar.dylib 24 | ${CC} ${CCFLAGS} -I${TESTROOT}/include -dynamiclib -o libfoo.dylib foo.c libbar.dylib -flat_namespace 25 | 26 | libbar.dylib: bar.c libbaz.dylib 27 | ${CC} ${CCFLAGS} -I${TESTROOT}/include -dynamiclib -o libbar.dylib bar.c libbaz.dylib 28 | 29 | libbaz.dylib: baz.c 30 | ${CC} ${CCFLAGS} -I${TESTROOT}/include -dynamiclib -o libbaz.dylib baz.c 31 | 32 | clean: 33 | ${RM} ${RMFLAGS} *~ main libfoo.dylib libbar.dylib libbaz.dylib 34 | 35 | -------------------------------------------------------------------------------- /unit-tests/test-cases/weak-external-reloc-flat/bar.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | int bar[] = { 20, 21, 22, 23 }; 4 | 5 | 6 | int __attribute__((weak)) frob[] = { 30, 31, 32, 33 }; 7 | 8 | int bar_getfrob(int x) { return frob[x]; } 9 | -------------------------------------------------------------------------------- /unit-tests/test-cases/weak-external-reloc-flat/baz.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | int __attribute__((weak)) bar[] = { 30, 31, 32, 33 }; 7 | 8 | 9 | -------------------------------------------------------------------------------- /unit-tests/test-cases/weak-external-reloc-flat/foo.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | extern int bar_getfrob(int x); 4 | 5 | 6 | int __attribute__((weak)) foo[] = { 1, 2, 3, 4 }; 7 | int __attribute__((weak)) bar[] = { 10, 11, 12, 13 }; 8 | int __attribute__((weak)) frob[] = { 20, 21, 22, 23 }; 9 | 10 | int* pfoo = &foo[2]; 11 | 12 | int getfrob() { 13 | return bar_getfrob(2); 14 | } -------------------------------------------------------------------------------- /unit-tests/test-cases/weak-external-reloc/Makefile: -------------------------------------------------------------------------------- 1 | 2 | 3 | TESTROOT = ../.. 4 | include ${TESTROOT}/include/common.makefile 5 | 6 | all-check: all check 7 | 8 | check: 9 | ./main 10 | 11 | all: main 12 | 13 | main: main.c librealmain.dylib 14 | ${CC} ${CCFLAGS} -I${TESTROOT}/include -o main main.c librealmain.dylib 15 | 16 | librealmain.dylib: realmain.c libfoo.dylib 17 | ${CC} ${CCFLAGS} -I${TESTROOT}/include -dynamiclib -o librealmain.dylib realmain.c libfoo.dylib 18 | 19 | libfoo.dylib: foo.c libbar.dylib 20 | ${CC} ${CCFLAGS} -I${TESTROOT}/include -dynamiclib -o libfoo.dylib foo.c libbar.dylib 21 | 22 | libbar.dylib: bar.c libbaz.dylib 23 | ${CC} ${CCFLAGS} -I${TESTROOT}/include -dynamiclib -o libbar.dylib bar.c libbaz.dylib 24 | 25 | libbaz.dylib: baz.c 26 | ${CC} ${CCFLAGS} -I${TESTROOT}/include -dynamiclib -o libbaz.dylib baz.c 27 | 28 | clean: 29 | ${RM} ${RMFLAGS} *~ main libfoo.dylib libbar.dylib libbaz.dylib librealmain.dylib 30 | 31 | -------------------------------------------------------------------------------- /unit-tests/test-cases/weak-external-reloc/bar.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | int bar[] = { 20, 21, 22, 23 }; 4 | 5 | // needs something weak to join coalescing 6 | int __attribute__((weak)) junk = 5; 7 | -------------------------------------------------------------------------------- /unit-tests/test-cases/weak-external-reloc/baz.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | int __attribute__((weak)) bar[] = { 30, 31, 32, 33 }; 7 | 8 | 9 | -------------------------------------------------------------------------------- /unit-tests/test-cases/weak-external-reloc/foo.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | int __attribute__((weak)) foo[] = { 1, 2, 3, 4 }; 7 | int __attribute__((weak)) bar[] = { 10, 11, 12, 13 }; 8 | 9 | int* pfoo = &foo[2]; 10 | 11 | -------------------------------------------------------------------------------- /unit-tests/test-cases/weak-external-reloc/main.c: -------------------------------------------------------------------------------- 1 | 2 | extern void realmain(); 3 | 4 | int main() 5 | { 6 | realmain(); 7 | return 0; 8 | } 9 | 10 | 11 | -------------------------------------------------------------------------------- /unit-tests/test-cases/weak-in-dylib/Makefile: -------------------------------------------------------------------------------- 1 | 2 | 3 | TESTROOT = ../.. 4 | include ${TESTROOT}/include/common.makefile 5 | 6 | all-check: all check 7 | 8 | check: 9 | ./main 10 | 11 | all: main 12 | 13 | main: main.c libfoo.dylib 14 | ${CC} ${CCFLAGS} -I${TESTROOT}/include -o main main.c libfoo.dylib 15 | 16 | libfoo.dylib: foo.c 17 | ${CC} ${CCFLAGS} -I${TESTROOT}/include -dynamiclib -o libfoo.dylib foo.c 18 | 19 | clean: 20 | ${RM} ${RMFLAGS} *~ main libfoo.dylib 21 | 22 | -------------------------------------------------------------------------------- /unit-tests/test-cases/weak-in-dylib/foo.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | int __attribute__((weak)) foo[] = { 1, 2, 3, 4 }; 7 | 8 | -------------------------------------------------------------------------------- /unit-tests/test-cases/weak-in-dylib/main.c: -------------------------------------------------------------------------------- 1 | 2 | #include // fprintf(), NULL 3 | #include // exit(), EXIT_SUCCESS 4 | 5 | #include "test.h" // PASS(), FAIL(), XPASS(), XFAIL() 6 | 7 | // libfoo.dylib has a weak foo[] 8 | extern int foo[]; 9 | 10 | int* pfoo3 = &foo[3]; 11 | 12 | int main() 13 | { 14 | if ( *pfoo3 != 4 ) 15 | FAIL("weak-in-dylib, pfoo3=%d", *pfoo3); 16 | else if ( foo[2] != 3 ) 17 | FAIL("weak-in-dylib, foo[2]=%d", foo[2]); 18 | else 19 | PASS("weak-in-dyliby"); 20 | return 0; 21 | } 22 | 23 | -------------------------------------------------------------------------------- /unit-tests/test-cases/weak-lazy-slidable/Makefile: -------------------------------------------------------------------------------- 1 | 2 | 3 | TESTROOT = ../.. 4 | include ${TESTROOT}/include/common.makefile 5 | 6 | all-check: all check 7 | 8 | check: 9 | ./main 10 | 11 | all: main 12 | 13 | main: main.c libfoo.dylib libother.dylib 14 | ${CC} ${CCFLAGS} -I${TESTROOT}/include -o main main.c libother.dylib libfoo.dylib 15 | 16 | libother.dylib: foo.c 17 | ${CC} ${CCFLAGS} -I${TESTROOT}/include -dynamiclib -o libother.dylib other.c 18 | 19 | libfoo.dylib: foo.c libbar.dylib 20 | ${CC} ${CCFLAGS} -I${TESTROOT}/include -dynamiclib -o libfoo.dylib foo.c libbar.dylib 21 | 22 | libbar.dylib: bar.c libbar3.dylib 23 | ${CC} ${CCFLAGS} -I${TESTROOT}/include -dynamiclib -o libbar.dylib bar.c libbar3.dylib 24 | 25 | libbar3.dylib: bar3.c 26 | ${CC} ${CCFLAGS} -I${TESTROOT}/include -dynamiclib -o libbar3.dylib bar3.c 27 | 28 | 29 | clean: 30 | ${RM} ${RMFLAGS} *~ main libfoo.dylib libbar.dylib libbar3.dylib libother.dylib 31 | 32 | -------------------------------------------------------------------------------- /unit-tests/test-cases/weak-lazy-slidable/bar.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include 4 | 5 | bool bar1() 6 | { 7 | return true; 8 | } 9 | 10 | __attribute__((weak)) void junk() 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /unit-tests/test-cases/weak-lazy-slidable/bar3.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include 4 | 5 | __attribute__((weak)) bool bar1() 6 | { 7 | return false; 8 | } 9 | 10 | -------------------------------------------------------------------------------- /unit-tests/test-cases/weak-lazy-slidable/foo.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | 5 | extern bool bar1(); 6 | 7 | 8 | __attribute__((weak)) bool bar1() 9 | { 10 | return false; 11 | } 12 | 13 | __attribute__((weak)) bool bar2() 14 | { 15 | return true; 16 | } 17 | 18 | 19 | bool foo1() 20 | { 21 | return bar1(); 22 | } 23 | 24 | bool foo2() 25 | { 26 | return bar2(); 27 | } 28 | 29 | 30 | -------------------------------------------------------------------------------- /unit-tests/test-cases/weak-lazy-slidable/main.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include // fprintf(), NULL 4 | #include // exit(), EXIT_SUCCESS 5 | #include 6 | 7 | #include "test.h" // PASS(), FAIL(), XPASS(), XFAIL() 8 | 9 | 10 | extern bool foo1(); 11 | extern bool foo2(); 12 | 13 | 14 | int main() 15 | { 16 | if ( foo1() && foo2() ) 17 | PASS("weak-lazy-slidable"); 18 | else 19 | FAIL("weak-lazy-slidable"); 20 | 21 | return EXIT_SUCCESS; 22 | } 23 | 24 | 25 | -------------------------------------------------------------------------------- /unit-tests/test-cases/weak-lazy-slidable/other.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | bool bar2() 4 | { 5 | return false; 6 | } 7 | 8 | -------------------------------------------------------------------------------- /unit-tests/test-cases/weak-library/foo.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005 Apple Computer, Inc. All rights reserved. 3 | * 4 | * @APPLE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. Please obtain a copy of the License at 10 | * http://www.opensource.apple.com/apsl/ and read it before using this 11 | * file. 12 | * 13 | * The Original Code and all software distributed under the License are 14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 | * Please see the License for the specific language governing rights and 19 | * limitations under the License. 20 | * 21 | * @APPLE_LICENSE_HEADER_END@ 22 | */ 23 | extern int foo(); 24 | -------------------------------------------------------------------------------- /unit-tests/test-cases/weak-non-lazy/Makefile: -------------------------------------------------------------------------------- 1 | 2 | 3 | TESTROOT = ../.. 4 | include ${TESTROOT}/include/common.makefile 5 | 6 | all-check: all check 7 | 8 | check: 9 | ./main 10 | 11 | all: main 12 | 13 | main: main.c librealmain.dylib 14 | ${CC} ${CCFLAGS} -I${TESTROOT}/include -o main main.c librealmain.dylib 15 | 16 | librealmain.dylib: realmain.c libfoo.dylib 17 | ${CC} ${CCFLAGS} -I${TESTROOT}/include -dynamiclib -o librealmain.dylib realmain.c libfoo.dylib 18 | 19 | libfoo.dylib: foo.c libbar.dylib 20 | ${CC} ${CCFLAGS} -I${TESTROOT}/include -dynamiclib -o libfoo.dylib foo.c libbar.dylib 21 | 22 | libbar.dylib: bar.c libbaz.dylib 23 | ${CC} ${CCFLAGS} -I${TESTROOT}/include -dynamiclib -o libbar.dylib bar.c libbaz.dylib 24 | 25 | libbaz.dylib: baz.c 26 | ${CC} ${CCFLAGS} -I${TESTROOT}/include -dynamiclib -o libbaz.dylib baz.c 27 | 28 | clean: 29 | ${RM} ${RMFLAGS} *~ main libfoo.dylib libbar.dylib libbaz.dylib librealmain.dylib 30 | 31 | -------------------------------------------------------------------------------- /unit-tests/test-cases/weak-non-lazy/bar.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | int bar[] = { 20, 21, 22, 23 }; 4 | 5 | // needs something weak to join coalescing fun 6 | int __attribute__((weak)) junk = 5; 7 | -------------------------------------------------------------------------------- /unit-tests/test-cases/weak-non-lazy/baz.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | int __attribute__((weak)) bar[] = { 30, 31, 32, 33 }; 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /unit-tests/test-cases/weak-non-lazy/foo.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | int __attribute__((weak)) foo[] = { 1, 2, 3, 4 }; 7 | int __attribute__((weak)) bar[] = { 10, 11, 12, 13 }; 8 | 9 | int* getfoo() 10 | { 11 | return foo; 12 | } 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /unit-tests/test-cases/weak-non-lazy/main.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | // put test code in a dylib so that is slides 4 | extern void realmain(); 5 | 6 | int main() 7 | { 8 | realmain(); 9 | return 0; 10 | } 11 | 12 | 13 | -------------------------------------------------------------------------------- /unit-tests/test-cases/weak-non-lazy/realmain.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include // fprintf(), NULL 4 | #include // exit(), EXIT_SUCCESS 5 | 6 | #include "test.h" // PASS(), FAIL(), XPASS(), XFAIL() 7 | 8 | // getfoo() is in libfoo.dylib and uses a non-lazy pointer to reference foo 9 | // libfoo.dylib also has weak foo[] 10 | // getfoo() should be rebound to point into the foo[] in main 11 | int foo[] = { 5, 6, 7, 8 }; 12 | extern int* getfoo(); 13 | 14 | // libfoo.dylib has a weak bar[] 15 | // libbar.dylib has a strong bar[] 16 | // at build time linker only sees weak bar in libfoo.dylib 17 | // at runtime, dyld uses strong bar in libbar.dylib 18 | extern int bar[]; 19 | 20 | 21 | int __attribute__((weak)) stuff[] = { 1, 2, 3, 4, 5 }; 22 | 23 | 24 | void realmain() 25 | { 26 | if ( getfoo()[2] != 7 ) 27 | FAIL("weak-non-lazy, getfoo()[2]=%d", getfoo()[2]); 28 | else if ( bar[1] != 21 ) 29 | FAIL("weak-non-lazy, bar[1]=%d", bar[1]); 30 | else if ( stuff[3] != 4 ) 31 | FAIL("weak-external-reloc, pstuffr=%d", stuff[3]); 32 | else 33 | PASS("weak-non-lazy"); 34 | } 35 | 36 | 37 | -------------------------------------------------------------------------------- /unit-tests/test-cases/weak_import/foo.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include "foo.h" 4 | 5 | void func1() {} 6 | void func3() {} 7 | int data1 = 0; 8 | int data3; 9 | int data5 = 0; 10 | 11 | #if ALL_SYMBOLS 12 | void func2() {} 13 | void func4() {} 14 | 15 | int data2 = 0; // weak_import initialized 16 | int data4; // weak_import uninitialized 17 | int data6 = 0; // weak_import 18 | #endif 19 | 20 | -------------------------------------------------------------------------------- /unit-tests/test-cases/weak_import/foo.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | extern void func1(); 4 | extern void func2() __attribute__((weak_import)); 5 | extern void func3(); 6 | extern void func4() __attribute__((weak_import)); 7 | 8 | extern int data1; 9 | extern int data2 __attribute__((weak_import)); 10 | extern int data3; 11 | extern int data4 __attribute__((weak_import)); 12 | extern int data5; 13 | extern int data6 __attribute__((weak_import)); 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /unit-tests/test-cases/zero-fill-segment/foo.c: -------------------------------------------------------------------------------- 1 | 2 | extern int foo[]; 3 | 4 | int getfoo(int x) 5 | { 6 | return foo[x]; 7 | } 8 | 9 | -------------------------------------------------------------------------------- /unit-tests/test-cases/zero-fill-segment/zero.s: -------------------------------------------------------------------------------- 1 | 2 | .globl _foo 3 | .zerofill __MYZERO, __zero, _foo, 8192 4 | 5 | 6 | -------------------------------------------------------------------------------- /unit-tests/test-cases/zero-length-segment/foo.c: -------------------------------------------------------------------------------- 1 | void foo() {} 2 | --------------------------------------------------------------------------------