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);
#ifndef DARLING
VECTOR_NEVER_DESTRUCTED_IMPL(ImagePair);
#endif

View File

@ -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
// <rdar://47805386> 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 <rdar://46878536>
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);

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.
__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