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`
This commit is contained in:
Thomas A 2022-04-26 08:55:31 -07:00
parent bc37c99380
commit a4ae1c3f88
3 changed files with 22 additions and 1 deletions

View File

@ -1961,7 +1961,8 @@ void ImageLoader::forEachReExportDependent( void (^callback)(const ImageLoader*,
VECTOR_NEVER_DESTRUCTED_IMPL(ImageLoader::InterposeTuple); VECTOR_NEVER_DESTRUCTED_IMPL(ImageLoader::InterposeTuple);
#ifndef DARLING
VECTOR_NEVER_DESTRUCTED_IMPL(ImagePair); VECTOR_NEVER_DESTRUCTED_IMPL(ImagePair);
#endif

View File

@ -36,7 +36,11 @@
#include "Tracing.h" #include "Tracing.h"
// from libc.a // from libc.a
#ifdef DARLING
extern "C" void mach_init(const char* apple[]);
#else
extern "C" void mach_init(); extern "C" void mach_init();
#endif
extern "C" void __guard_setup(const char* apple[]); extern "C" void __guard_setup(const char* apple[]);
extern "C" void _subsystem_init(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. // On disk, all pointers in dyld's DATA segment are chained together.
// They need to be fixed up to be real pointers to run. // 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) static void rebaseDyld(const dyld3::MachOLoaded* dyldMH)
#endif
{ {
// walk all fixups chains and rebase dyld // walk all fixups chains and rebase dyld
const dyld3::MachOAnalyzer* ma = (dyld3::MachOAnalyzer*)dyldMH; const dyld3::MachOAnalyzer* ma = (dyld3::MachOAnalyzer*)dyldMH;
@ -97,7 +105,11 @@ static void rebaseDyld(const dyld3::MachOLoaded* dyldMH)
diag.assertNoError(); diag.assertNoError();
// now that rebasing done, initialize mach/syscall layer // now that rebasing done, initialize mach/syscall layer
#ifdef DARLING
mach_init(apple);
#else
mach_init(); mach_init();
#endif
// <rdar://47805386> mark __DATA_CONST segment in dyld as read-only (once fixups are done) // <rdar://47805386> mark __DATA_CONST segment in dyld as read-only (once fixups are done)
ma->forEachSegment(^(const dyld3::MachOFile::SegmentInfo& info, bool& stop) { 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 <rdar://46878536> // Emit kdebug tracepoint to indicate dyld bootstrap has started <rdar://46878536>
dyld3::kdebug_trace_dyld_marker(DBG_DYLD_TIMING_BOOTSTRAP_START, 0, 0, 0, 0); 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 // if kernel had to slide dyld, we need to fix up load sensitive locations
// we have to do this before using any global variables // we have to do this before using any global variables
rebaseDyld(dyldsMachHeader); rebaseDyld(dyldsMachHeader);
#endif
// kernel sets up env pointer to be just past end of agv array // kernel sets up env pointer to be just past end of agv array
const char** envp = &argv[argc+1]; 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; } while(*apple != NULL) { ++apple; }
++apple; ++apple;
#ifdef DARLING
rebaseDyld(dyldsMachHeader, apple);
#endif
// set up random value for stack canary // set up random value for stack canary
__guard_setup(apple); __guard_setup(apple);

View File

@ -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. // dylib1.o is used, it overrides this, otherwise this implementation is used.
__attribute__((weak)) __attribute__((weak))
#endif #endif
#ifndef DARLING
__attribute__((visibility("hidden"))) __attribute__((visibility("hidden")))
#endif
int _dyld_func_lookup(const char* dyld_func_name, void **address) 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 // Cast lookup function here to resign from dyld's 0-discriminator to a real