From a4ae1c3f880bf1b52dd48d22471b38a96f3e9b40 Mon Sep 17 00:00:00 2001 From: Thomas A Date: Tue, 26 Apr 2022 08:55:31 -0700 Subject: [PATCH] Restore Undocumented Darling Specific Changes * Don't hide `_dyld_func_lookup` * Don't compile `VECTOR_NEVER_DESTRUCTED_IMPL(ImagePair);` * Restore `const char* apple[]` argument for `mach_init` and `rebaseDyld` --- src/ImageLoader.cpp | 3 ++- src/dyldInitialization.cpp | 18 ++++++++++++++++++ src/dyldLibSystemGlue.c | 2 ++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/ImageLoader.cpp b/src/ImageLoader.cpp index 764b3b8..7ff3ea8 100644 --- a/src/ImageLoader.cpp +++ b/src/ImageLoader.cpp @@ -1961,7 +1961,8 @@ void ImageLoader::forEachReExportDependent( void (^callback)(const ImageLoader*, VECTOR_NEVER_DESTRUCTED_IMPL(ImageLoader::InterposeTuple); +#ifndef DARLING VECTOR_NEVER_DESTRUCTED_IMPL(ImagePair); - +#endif diff --git a/src/dyldInitialization.cpp b/src/dyldInitialization.cpp index db7a2a9..961e9a3 100644 --- a/src/dyldInitialization.cpp +++ b/src/dyldInitialization.cpp @@ -36,7 +36,11 @@ #include "Tracing.h" // from libc.a +#ifdef DARLING +extern "C" void mach_init(const char* apple[]); +#else extern "C" void mach_init(); +#endif extern "C" void __guard_setup(const char* apple[]); extern "C" void _subsystem_init(const char* apple[]); @@ -84,7 +88,11 @@ static void runDyldInitializers(int argc, const char* argv[], const char* envp[] // On disk, all pointers in dyld's DATA segment are chained together. // They need to be fixed up to be real pointers to run. // +#ifdef DARLING +static void rebaseDyld(const dyld3::MachOLoaded* dyldMH, const char* apple[]) +#else static void rebaseDyld(const dyld3::MachOLoaded* dyldMH) +#endif { // walk all fixups chains and rebase dyld const dyld3::MachOAnalyzer* ma = (dyld3::MachOAnalyzer*)dyldMH; @@ -97,7 +105,11 @@ static void rebaseDyld(const dyld3::MachOLoaded* dyldMH) diag.assertNoError(); // now that rebasing done, initialize mach/syscall layer +#ifdef DARLING + mach_init(apple); +#else mach_init(); +#endif // mark __DATA_CONST segment in dyld as read-only (once fixups are done) ma->forEachSegment(^(const dyld3::MachOFile::SegmentInfo& info, bool& stop) { @@ -122,9 +134,11 @@ uintptr_t start(const dyld3::MachOLoaded* appsMachHeader, int argc, const char* // Emit kdebug tracepoint to indicate dyld bootstrap has started dyld3::kdebug_trace_dyld_marker(DBG_DYLD_TIMING_BOOTSTRAP_START, 0, 0, 0, 0); +#ifndef DARLING // if kernel had to slide dyld, we need to fix up load sensitive locations // we have to do this before using any global variables rebaseDyld(dyldsMachHeader); +#endif // kernel sets up env pointer to be just past end of agv array const char** envp = &argv[argc+1]; @@ -134,6 +148,10 @@ uintptr_t start(const dyld3::MachOLoaded* appsMachHeader, int argc, const char* while(*apple != NULL) { ++apple; } ++apple; +#ifdef DARLING + rebaseDyld(dyldsMachHeader, apple); +#endif + // set up random value for stack canary __guard_setup(apple); diff --git a/src/dyldLibSystemGlue.c b/src/dyldLibSystemGlue.c index bcdb1e0..de22f89 100644 --- a/src/dyldLibSystemGlue.c +++ b/src/dyldLibSystemGlue.c @@ -68,7 +68,9 @@ static volatile struct __DATA__dyld myDyldSection __attribute__ ((section ("__D // dylib1.o is used, it overrides this, otherwise this implementation is used. __attribute__((weak)) #endif +#ifndef DARLING __attribute__((visibility("hidden"))) +#endif int _dyld_func_lookup(const char* dyld_func_name, void **address) { // Cast lookup function here to resign from dyld's 0-discriminator to a real