]> git.saurik.com Git - apple/dyld.git/blame - src/dyldLibSystemGlue.c
dyld-360.19.tar.gz
[apple/dyld.git] / src / dyldLibSystemGlue.c
CommitLineData
197008ea
A
1/* -*- mode: C++; c-basic-offset: 4; tab-width: 4 -*-
2 *
412ebb8e 3 * Copyright (c) 2009-2010 Apple Inc. All rights reserved.
2028a915
A
4 *
5 * @APPLE_LICENSE_HEADER_START@
6 *
7 * This file contains Original Code and/or Modifications of Original Code
8 * as defined in and that are subject to the Apple Public Source License
9 * Version 2.0 (the 'License'). You may not use this file except in
10 * compliance with the License. Please obtain a copy of the License at
11 * http://www.opensource.apple.com/apsl/ and read it before using this
12 * file.
13 *
14 * The Original Code and all software distributed under the License are
15 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
19 * Please see the License for the specific language governing rights and
20 * limitations under the License.
21 *
22 * @APPLE_LICENSE_HEADER_END@
23 */
24
412ebb8e 25#include <Availability.h>
832b6fce 26#include <stddef.h>
2fd3f4e8 27#include <TargetConditionals.h>
39a8cd10 28
2fd3f4e8 29
39a8cd10 30//
39a8cd10
A
31// This is the temporary private interface between libSystem.B.dylib and dyld
32//
33
832b6fce
A
34
35int NXArgc = 0;
36const char** NXArgv = NULL;
37const char** environ = NULL;
38const char* __progname = NULL;
39
40
41
412ebb8e
A
42//
43// Long ago, the compiler driver added -ldylib1.o to every dylib which caused a
44// __DATA,__dyld section to be added every dylib. The new LINKEDIT format no longer requires
45// images to have a __DATA,__dyld section. But until libdyld.dylib and dyld update
46// to some sort of vtable based interface, libdyld still needs a __DATA,__dyld section.
47// The code below adds that section.
48//
832b6fce
A
49struct __DATA__dyld {
50 long lazy;
51 int (*lookup)(const char*, void**);
52 // ProgramVars
53 const void* mh;
54 int* NXArgcPtr;
55 const char*** NXArgvPtr;
56 const char*** environPtr;
57 const char** __prognamePtr;
58};
39a8cd10 59
832b6fce
A
60static volatile struct __DATA__dyld myDyldSection __attribute__ ((section ("__DATA,__dyld")))
61 = { 0, 0, NULL, &NXArgc, &NXArgv, &environ, &__progname };
39a8cd10 62
412ebb8e
A
63#if __arm__ && __MAC_OS_X_VERSION_MIN_REQUIRED
64// <rdar://problem/8755380>
65// For historical reasons, gcc and llvm-gcc added -ldylib1.o to the link line of armv6
66// dylibs when targeting MacOSX (but not iOS). clang cleans up that mistake, but doing
67// so would break the libdyld build. Making _dyld_func_lookup weak,hidden means if
68// dylib1.o is used, it overrides this, otherwise this implementation is used.
69__attribute__((weak))
70#endif
71__attribute__((visibility("hidden")))
72int _dyld_func_lookup(const char* dyld_func_name, void **address)
39a8cd10
A
73{
74 return (*myDyldSection.lookup)(dyld_func_name, address);
75}
76