/* -*- 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@
*
* @APPLE_LICENSE_HEADER_END@
*/
-#include <stdlib.h>
+#include <Availability.h>
+#include <stddef.h>
+#include <TargetConditionals.h>
+
//
-// <rdar://problem/6536810> 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
+// <rdar://problem/8755380>
+// 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
-
-
-