X-Git-Url: https://git.saurik.com/apple/dyld.git/blobdiff_plain/39a8cd101b922f08058746122efff58c14b57605..4f17e7a6e9f7d1db9fed2c9e01feed490a9f0303:/src/dyldLibSystemGlue.c diff --git a/src/dyldLibSystemGlue.c b/src/dyldLibSystemGlue.c index 2628673..4b6a638 100644 --- a/src/dyldLibSystemGlue.c +++ b/src/dyldLibSystemGlue.c @@ -1,6 +1,6 @@ /* -*- mode: C++; c-basic-offset: 4; tab-width: 4 -*- * - * Copyright (c) 2009 Apple Inc. All rights reserved. + * Copyright (c) 2009-2010 Apple Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -22,28 +22,55 @@ * @APPLE_LICENSE_HEADER_END@ */ -#include +#include +#include +#include + // -// Alter libdyld.a to not need libsystem to link with dylib1.o // This is the temporary private interface between libSystem.B.dylib and dyld // -#if __i386__ || __x86_64__ -// The compiler driver will continue to add -ldylib1.o to ppc and arm links -// so only i386 and x86_64 need this extra glue. -struct __DATA__dyld { long lazy; int (*lookup)(const char*, void**); }; +int NXArgc = 0; +const char** NXArgv = NULL; +const char** environ = NULL; +const char* __progname = NULL; -static struct __DATA__dyld myDyldSection __attribute__ ((section ("__DATA,__dyld"))) = { 0, NULL }; -__attribute__((weak, visibility("hidden"))) int _dyld_func_lookup(const char* dyld_func_name, void **address) +// +// Long ago, the compiler driver added -ldylib1.o to every dylib which caused a +// __DATA,__dyld section to be added every dylib. The new LINKEDIT format no longer requires +// images to have a __DATA,__dyld section. But until libdyld.dylib and dyld update +// to some sort of vtable based interface, libdyld still needs a __DATA,__dyld section. +// The code below adds that section. +// +struct __DATA__dyld { + long lazy; + int (*lookup)(const char*, void**); + // ProgramVars + const void* mh; + int* NXArgcPtr; + const char*** NXArgvPtr; + const char*** environPtr; + const char** __prognamePtr; +}; + +static volatile struct __DATA__dyld myDyldSection __attribute__ ((section ("__DATA,__dyld"))) + = { 0, 0, NULL, &NXArgc, &NXArgv, &environ, &__progname }; + +#if __arm__ && __MAC_OS_X_VERSION_MIN_REQUIRED +// +// For historical reasons, gcc and llvm-gcc added -ldylib1.o to the link line of armv6 +// dylibs when targeting MacOSX (but not iOS). clang cleans up that mistake, but doing +// so would break the libdyld build. Making _dyld_func_lookup weak,hidden means if +// dylib1.o is used, it overrides this, otherwise this implementation is used. +__attribute__((weak)) +#endif +__attribute__((visibility("hidden"))) +int _dyld_func_lookup(const char* dyld_func_name, void **address) { return (*myDyldSection.lookup)(dyld_func_name, address); } -#endif - - -