annotate src/loadso/macosx/SDL_dlcompat.c @ 3984:b74530a1dad6 SDL-1.2

Better fix for bug 419
author Sam Lantinga <slouken@libsdl.org>
date Thu, 28 Jun 2007 05:35:50 +0000
parents e308d020d315
children 782fd950bd46 c121d94672cb a1b03ba2fcd0
rev   line source
1801
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1 /*
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2 SDL - Simple DirectMedia Layer
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3 Copyright (C) 1997-2006 Sam Lantinga
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5 This library is free software; you can redistribute it and/or
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
6 modify it under the terms of the GNU Lesser General Public
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
8 version 2.1 of the License, or (at your option) any later version.
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
9
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
13 Lesser General Public License for more details.
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
14
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
15 You should have received a copy of the GNU Lesser General Public
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
16 License along with this library; if not, write to the Free Software
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
18
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
19 Sam Lantinga
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
20 slouken@libsdl.org
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
21 */
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
22 #include "SDL_config.h"
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
23
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
24 #ifdef SDL_LOADSO_DLCOMPAT
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
25
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
26 /* Please note that dlcompat apparently ships in current Mac OS X versions
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
27 * as a system library that provides compatibility with the Unix "dlopen"
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
28 * interface. In order to allow SDL to work on older OS X releases and also
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
29 * not conflict with the system lib on newer versions, we include dlcompat
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
30 * in SDL and change the symbols to prevent symbol clash with any existing
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
31 * system libraries. --ryan.
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
32 */
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
33
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
34 /* here is the dlcompat license: */
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
35
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
36 /*
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
37 Copyright (c) 2002 Jorge Acereda <jacereda@users.sourceforge.net> &
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
38 Peter O'Gorman <ogorman@users.sourceforge.net>
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
39
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
40 Portions may be copyright others, see the AUTHORS file included with this
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
41 distribution.
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
42
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
43 Maintained by Peter O'Gorman <ogorman@users.sourceforge.net>
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
44
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
45 Bug Reports and other queries should go to <ogorman@users.sourceforge.net>
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
46
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
47 Permission is hereby granted, free of charge, to any person obtaining
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
48 a copy of this software and associated documentation files (the
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
49 "Software"), to deal in the Software without restriction, including
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
50 without limitation the rights to use, copy, modify, merge, publish,
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
51 distribute, sublicense, and/or sell copies of the Software, and to
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
52 permit persons to whom the Software is furnished to do so, subject to
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
53 the following conditions:
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
54
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
55 The above copyright notice and this permission notice shall be
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
56 included in all copies or substantial portions of the Software.
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
57
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
58 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
59 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
60 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
61 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
62 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
63 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
64 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
65 */
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
66
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
67 #include <pthread.h>
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
68 #include <sys/types.h>
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
69 #include <sys/stat.h>
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
70 #include <stdarg.h>
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
71 #include <limits.h>
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
72 #include <mach-o/dyld.h>
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
73 #include <mach-o/nlist.h>
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
74 #include <mach-o/getsect.h>
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
75
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
76 #include "SDL_stdinc.h"
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
77
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
78 /* Just playing to see if it would compile with the freebsd headers, it does,
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
79 * but because of the different values for RTLD_LOCAL etc, it would break binary
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
80 * compat... oh well
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
81 */
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
82 #ifndef __BSD_VISIBLE
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
83 #define __BSD_VISIBLE 1
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
84 #endif
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
85
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
86 /*include "dlfcn.h"*/
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
87 #ifdef __cplusplus
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
88 extern "C" {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
89 #endif
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
90
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
91 #if defined (__GNUC__) && __GNUC__ > 3
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
92 #define dl_restrict __restrict
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
93 #else
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
94 #define dl_restrict
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
95 #endif
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
96
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
97 #if 0
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
98 #ifndef _POSIX_SOURCE
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
99 /*
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
100 * Structure filled in by dladdr().
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
101 */
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
102 typedef struct SDL_OSX_dl_info {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
103 const char *dli_fname; /* Pathname of shared object */
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
104 void *dli_fbase; /* Base address of shared object */
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
105 const char *dli_sname; /* Name of nearest symbol */
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
106 void *dli_saddr; /* Address of nearest symbol */
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
107 } SDL_OSX_Dl_info;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
108
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
109 static int SDL_OSX_dladdr(const void * dl_restrict, SDL_OSX_Dl_info * dl_restrict);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
110 #endif /* ! _POSIX_SOURCE */
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
111 #endif /* 0 */
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
112
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
113 static int SDL_OSX_dlclose(void * handle);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
114 static const char * SDL_OSX_dlerror(void);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
115 static void * SDL_OSX_dlopen(const char *path, int mode);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
116 static void * SDL_OSX_dlsym(void * dl_restrict handle, const char * dl_restrict symbol);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
117
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
118 #define RTLD_LAZY 0x1
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
119 #define RTLD_NOW 0x2
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
120 #define RTLD_LOCAL 0x4
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
121 #define RTLD_GLOBAL 0x8
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
122
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
123 #ifndef _POSIX_SOURCE
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
124 #define RTLD_NOLOAD 0x10
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
125 #define RTLD_NODELETE 0x80
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
126
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
127 /*
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
128 * Special handle arguments for SDL_OSX_dlsym().
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
129 */
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
130 #define RTLD_NEXT ((void *) -1) /* Search subsequent objects. */
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
131 #define RTLD_DEFAULT ((void *) -2) /* Use default search algorithm. */
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
132 #endif /* ! _POSIX_SOURCE */
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
133
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
134 #ifdef __cplusplus
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
135 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
136 #endif
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
137
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
138 #ifndef dl_restrict
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
139 #define dl_restrict __restrict
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
140 #endif
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
141 /* This is not available on 10.1 */
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
142 #ifndef LC_LOAD_WEAK_DYLIB
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
143 #define LC_LOAD_WEAK_DYLIB (0x18 | LC_REQ_DYLD)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
144 #endif
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
145
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
146 /* With this stuff here, this thing may actually compile/run on 10.0 systems
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
147 * Not that I have a 10.0 system to test it on anylonger
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
148 */
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
149 #ifndef LC_REQ_DYLD
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
150 #define LC_REQ_DYLD 0x80000000
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
151 #endif
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
152 #ifndef NSADDIMAGE_OPTION_RETURN_ONLY_IF_LOADED
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
153 #define NSADDIMAGE_OPTION_RETURN_ONLY_IF_LOADED 0x4
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
154 #endif
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
155 #ifndef NSADDIMAGE_OPTION_RETURN_ON_ERROR
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
156 #define NSADDIMAGE_OPTION_RETURN_ON_ERROR 0x1
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
157 #endif
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
158 #ifndef NSLOOKUPSYMBOLINIMAGE_OPTION_BIND
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
159 #define NSLOOKUPSYMBOLINIMAGE_OPTION_BIND 0x0
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
160 #endif
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
161 #ifndef NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
162 #define NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR 0x4
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
163 #endif
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
164 /* These symbols will be looked for in dyld */
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
165 static const struct mach_header *(*dyld_NSAddImage) (const char *, unsigned long) = 0;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
166 static int (*dyld_NSIsSymbolNameDefinedInImage) (const struct mach_header *, const char *) = 0;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
167 static NSSymbol(*dyld_NSLookupSymbolInImage)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
168 (const struct mach_header *, const char *, unsigned long) = 0;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
169
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
170 /* Define this to make dlcompat reuse data block. This way in theory we save
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
171 * a little bit of overhead. However we then couldn't correctly catch excess
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
172 * calls to SDL_OSX_dlclose(). Hence we don't use this feature
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
173 */
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
174 #undef REUSE_STATUS
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
175
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
176 /* Size of the internal error message buffer (used by dlerror()) */
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
177 #define ERR_STR_LEN 251
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
178
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
179 /* Maximum number of search paths supported by getSearchPath */
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
180 #define MAX_SEARCH_PATHS 32
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
181
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
182
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
183 #define MAGIC_DYLIB_OFI ((NSObjectFileImage) 'DYOF')
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
184 #define MAGIC_DYLIB_MOD ((NSModule) 'DYMO')
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
185
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
186 /* internal flags */
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
187 #define DL_IN_LIST 0x01
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
188
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
189 /* our mutex */
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
190 static pthread_mutex_t dlcompat_mutex;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
191 /* Our thread specific storage
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
192 */
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
193 static pthread_key_t dlerror_key;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
194
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
195 struct dlthread
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
196 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
197 int lockcnt;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
198 unsigned char errset;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
199 char errstr[ERR_STR_LEN];
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
200 };
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
201
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
202 /* This is our central data structure. Whenever a module is loaded via
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
203 * SDL_OSX_dlopen(), we create such a struct.
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
204 */
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
205 struct dlstatus
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
206 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
207 struct dlstatus *next; /* pointer to next element in the linked list */
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
208 NSModule module;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
209 const struct mach_header *lib;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
210 int refs; /* reference count */
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
211 int mode; /* mode in which this module was loaded */
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
212 dev_t device;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
213 ino_t inode;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
214 int flags; /* Any internal flags we may need */
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
215 };
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
216
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
217 /* Head node of the dlstatus list */
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
218 static struct dlstatus mainStatus = { 0, MAGIC_DYLIB_MOD, NULL, -1, RTLD_GLOBAL, 0, 0, 0 };
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
219 static struct dlstatus *stqueue = &mainStatus;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
220
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
221
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
222 /* Storage for the last error message (used by dlerror()) */
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
223 /* static char err_str[ERR_STR_LEN]; */
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
224 /* static int err_filled = 0; */
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
225
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
226 /* Prototypes to internal functions */
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
227 static void debug(const char *fmt, ...);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
228 static void error(const char *str, ...);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
229 static const char *safegetenv(const char *s);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
230 static const char *searchList(void);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
231 static const char *getSearchPath(int i);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
232 static const char *getFullPath(int i, const char *file);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
233 static const struct stat *findFile(const char *file, const char **fullPath);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
234 static int isValidStatus(struct dlstatus *status);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
235 static inline int isFlagSet(int mode, int flag);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
236 static struct dlstatus *lookupStatus(const struct stat *sbuf);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
237 static void insertStatus(struct dlstatus *dls, const struct stat *sbuf);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
238 static int promoteLocalToGlobal(struct dlstatus *dls);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
239 static void *reference(struct dlstatus *dls, int mode);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
240 static void *dlsymIntern(struct dlstatus *dls, const char *symbol, int canSetError);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
241 static struct dlstatus *allocStatus(void);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
242 static struct dlstatus *loadModule(const char *path, const struct stat *sbuf, int mode);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
243 static NSSymbol search_linked_libs(const struct mach_header *mh, const char *symbol);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
244 static const char *get_lib_name(const struct mach_header *mh);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
245 static const struct mach_header *get_mach_header_from_NSModule(NSModule mod);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
246 static void dlcompat_init_func(void);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
247 static inline void dlcompat_init_check(void);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
248 static inline void dolock(void);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
249 static inline void dounlock(void);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
250 static void dlerrorfree(void *data);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
251 static void resetdlerror(void);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
252 static const struct mach_header *my_find_image(const char *name);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
253 static const struct mach_header *image_for_address(const void *address);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
254 static inline char *dyld_error_str(void);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
255
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
256 #if FINK_BUILD
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
257 /* Two Global Functions */
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
258 static void *dlsym_prepend_underscore(void *handle, const char *symbol);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
259 static void *dlsym_auto_underscore(void *handle, const char *symbol);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
260
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
261 /* And their _intern counterparts */
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
262 static void *dlsym_prepend_underscore_intern(void *handle, const char *symbol);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
263 static void *dlsym_auto_underscore_intern(void *handle, const char *symbol);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
264 #endif
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
265
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
266 /* Functions */
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
267
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
268 static void debug(const char *fmt, ...)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
269 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
270 #if DEBUG > 1
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
271 va_list arg;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
272 va_start(arg, fmt);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
273 fprintf(stderr, "DLDEBUG: ");
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
274 vfprintf(stderr, fmt, arg);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
275 fprintf(stderr, "\n");
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
276 fflush(stderr);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
277 va_end(arg);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
278 #endif
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
279 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
280
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
281 static void error(const char *str, ...)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
282 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
283 va_list arg;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
284 struct dlthread *tss;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
285 char * err_str;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
286 va_start(arg, str);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
287 tss = pthread_getspecific(dlerror_key);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
288 err_str = tss->errstr;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
289 SDL_strlcpy(err_str, "dlcompat: ", ERR_STR_LEN);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
290 vsnprintf(err_str + 10, ERR_STR_LEN - 10, str, arg);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
291 va_end(arg);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
292 debug("ERROR: %s\n", err_str);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
293 tss->errset = 1;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
294 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
295
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
296 static void warning(const char *str)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
297 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
298 #if DEBUG > 0
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
299 fprintf(stderr, "WARNING: dlcompat: %s\n", str);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
300 #endif
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
301 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
302
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
303 static const char *safegetenv(const char *s)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
304 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
305 const char *ss = SDL_getenv(s);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
306 return ss ? ss : "";
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
307 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
308
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
309 /* because this is only used for debugging and error reporting functions, we
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
310 * don't really care about how elegant it is... it could use the load
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
311 * commands to find the install name of the library, but...
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
312 */
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
313 static const char *get_lib_name(const struct mach_header *mh)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
314 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
315 unsigned long count = _dyld_image_count();
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
316 unsigned long i;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
317 const char *val = NULL;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
318 if (mh)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
319 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
320 for (i = 0; i < count; i++)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
321 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
322 if (mh == _dyld_get_image_header(i))
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
323 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
324 val = _dyld_get_image_name(i);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
325 break;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
326 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
327 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
328 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
329 return val;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
330 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
331
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
332 /* Returns the mach_header for the module bu going through all the loaded images
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
333 * and finding the one with the same name as the module. There really ought to be
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
334 * an api for doing this, would be faster, but there isn't one right now
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
335 */
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
336 static const struct mach_header *get_mach_header_from_NSModule(NSModule mod)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
337 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
338 const char *mod_name = NSNameOfModule(mod);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
339 const struct mach_header *mh = NULL;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
340 unsigned long count = _dyld_image_count();
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
341 unsigned long i;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
342 debug("Module name: %s", mod_name);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
343 for (i = 0; i < count; i++)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
344 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
345 if (!SDL_strcmp(mod_name, _dyld_get_image_name(i)))
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
346 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
347 mh = _dyld_get_image_header(i);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
348 break;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
349 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
350 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
351 return mh;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
352 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
353
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
354
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
355 /* Compute and return a list of all directories that we should search when
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
356 * trying to locate a module. We first look at the values of LD_LIBRARY_PATH
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
357 * and DYLD_LIBRARY_PATH, and then finally fall back to looking into
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
358 * /usr/lib and /lib. Since both of the environments variables can contain a
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
359 * list of colon seperated paths, we simply concat them and the two other paths
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
360 * into one big string, which we then can easily parse.
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
361 * Splitting this string into the actual path list is done by getSearchPath()
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
362 */
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
363 static const char *searchList()
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
364 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
365 size_t buf_size;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
366 static char *buf=NULL;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
367 const char *ldlp = safegetenv("LD_LIBRARY_PATH");
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
368 const char *dyldlp = safegetenv("DYLD_LIBRARY_PATH");
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
369 const char *stdpath = SDL_getenv("DYLD_FALLBACK_LIBRARY_PATH");
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
370 if (!stdpath)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
371 stdpath = "/usr/local/lib:/lib:/usr/lib";
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
372 if (!buf)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
373 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
374 buf_size = SDL_strlen(ldlp) + SDL_strlen(dyldlp) + SDL_strlen(stdpath) + 4;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
375 buf = SDL_malloc(buf_size);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
376 SDL_snprintf(buf, buf_size, "%s%s%s%s%s%c", dyldlp, (dyldlp[0] ? ":" : ""), ldlp, (ldlp[0] ? ":" : ""),
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
377 stdpath, '\0');
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
378 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
379 return buf;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
380 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
381
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
382 /* Returns the ith search path from the list as computed by searchList() */
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
383 static const char *getSearchPath(int i)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
384 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
385 static const char *list = 0;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
386 static char **path = (char **)0;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
387 static int end = 0;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
388 static int numsize = MAX_SEARCH_PATHS;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
389 static char **tmp;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
390 /* So we can call SDL_free() in the "destructor" we use i=-1 to return the alloc'd array */
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
391 if (i == -1)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
392 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
393 return (const char*)path;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
394 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
395 if (!path)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
396 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
397 path = (char **)SDL_calloc(MAX_SEARCH_PATHS, sizeof(char **));
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
398 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
399 if (!list && !end)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
400 list = searchList();
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
401 if (i >= (numsize))
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
402 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
403 debug("Increasing size for long PATH");
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
404 tmp = (char **)SDL_calloc((MAX_SEARCH_PATHS + numsize), sizeof(char **));
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
405 if (tmp)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
406 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
407 SDL_memcpy(tmp, path, sizeof(char **) * numsize);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
408 SDL_free(path);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
409 path = tmp;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
410 numsize += MAX_SEARCH_PATHS;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
411 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
412 else
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
413 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
414 return 0;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
415 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
416 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
417
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
418 while (!path[i] && !end)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
419 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
420 path[i] = strsep((char **)&list, ":");
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
421
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
422 if (path[i][0] == 0)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
423 path[i] = 0;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
424 end = (list == 0);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
425 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
426 return path[i];
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
427 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
428
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
429 static const char *getFullPath(int i, const char *file)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
430 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
431 static char buf[PATH_MAX];
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
432 const char *path = getSearchPath(i);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
433 if (path)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
434 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
435 SDL_snprintf(buf, PATH_MAX, "%s/%s", path, file);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
436 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
437 return path ? buf : 0;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
438 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
439
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
440 /* Given a file name, try to determine the full path for that file. Starts
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
441 * its search in the current directory, and then tries all paths in the
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
442 * search list in the order they are specified there.
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
443 */
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
444 static const struct stat *findFile(const char *file, const char **fullPath)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
445 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
446 int i = 0;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
447 static struct stat sbuf;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
448 char *fileName;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
449 debug("finding file %s", file);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
450 *fullPath = file;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
451 if (0 == stat(file, &sbuf))
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
452 return &sbuf;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
453 if (SDL_strchr(file, '/'))
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
454 return 0; /* If the path had a / we don't look in env var places */
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
455 fileName = NULL;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
456 if (!fileName)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
457 fileName = (char *)file;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
458 while ((*fullPath = getFullPath(i++, fileName)))
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
459 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
460 if (0 == stat(*fullPath, &sbuf))
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
461 return &sbuf;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
462 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
463 ;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
464 return 0;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
465 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
466
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
467 /* Determine whether a given dlstatus is valid or not */
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
468 static int isValidStatus(struct dlstatus *status)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
469 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
470 /* Walk the list to verify status is contained in it */
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
471 struct dlstatus *dls = stqueue;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
472 while (dls && status != dls)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
473 dls = dls->next;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
474 if (dls == 0)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
475 error("invalid handle");
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
476 else if ((dls->module == 0) || (dls->refs == 0))
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
477 error("handle to closed library");
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
478 else
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
479 return TRUE;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
480 return FALSE;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
481 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
482
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
483 static inline int isFlagSet(int mode, int flag)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
484 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
485 return (mode & flag) == flag;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
486 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
487
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
488 static struct dlstatus *lookupStatus(const struct stat *sbuf)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
489 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
490 struct dlstatus *dls = stqueue;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
491 debug("looking for status");
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
492 while (dls && ( /* isFlagSet(dls->mode, RTLD_UNSHARED) */ 0
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
493 || sbuf->st_dev != dls->device || sbuf->st_ino != dls->inode))
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
494 dls = dls->next;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
495 return dls;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
496 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
497
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
498 static void insertStatus(struct dlstatus *dls, const struct stat *sbuf)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
499 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
500 debug("inserting status");
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
501 dls->inode = sbuf->st_ino;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
502 dls->device = sbuf->st_dev;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
503 dls->refs = 0;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
504 dls->mode = 0;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
505 if ((dls->flags & DL_IN_LIST) == 0)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
506 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
507 dls->next = stqueue;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
508 stqueue = dls;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
509 dls->flags |= DL_IN_LIST;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
510 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
511 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
512
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
513 static struct dlstatus *allocStatus()
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
514 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
515 struct dlstatus *dls;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
516 #ifdef REUSE_STATUS
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
517 dls = stqueue;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
518 while (dls && dls->module)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
519 dls = dls->next;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
520 if (!dls)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
521 #endif
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
522 dls = SDL_calloc(sizeof(*dls),1);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
523 return dls;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
524 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
525
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
526 static int promoteLocalToGlobal(struct dlstatus *dls)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
527 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
528 static int (*p) (NSModule module) = 0;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
529 debug("promoting");
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
530 if (!p)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
531 _dyld_func_lookup("__dyld_NSMakePrivateModulePublic", (void **)&p);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
532 return (dls->module == MAGIC_DYLIB_MOD) || (p && p(dls->module));
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
533 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
534
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
535 static void *reference(struct dlstatus *dls, int mode)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
536 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
537 if (dls)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
538 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
539 if (dls->module == MAGIC_DYLIB_MOD && isFlagSet(mode, RTLD_LOCAL))
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
540 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
541 warning("trying to open a .dylib with RTLD_LOCAL");
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
542 error("unable to open a .dylib with RTLD_LOCAL");
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
543 return NULL;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
544 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
545 if (isFlagSet(mode, RTLD_GLOBAL) &&
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
546 !isFlagSet(dls->mode, RTLD_GLOBAL) && !promoteLocalToGlobal(dls))
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
547 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
548 error("unable to promote local module to global");
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
549 return NULL;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
550 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
551 dls->mode |= mode;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
552 dls->refs++;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
553 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
554 else
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
555 debug("reference called with NULL argument");
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
556
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
557 return dls;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
558 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
559
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
560 static const struct mach_header *my_find_image(const char *name)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
561 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
562 const struct mach_header *mh = 0;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
563 const char *id = NULL;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
564 int i = _dyld_image_count();
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
565 int j;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
566 mh = (struct mach_header *)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
567 dyld_NSAddImage(name, NSADDIMAGE_OPTION_RETURN_ONLY_IF_LOADED |
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
568 NSADDIMAGE_OPTION_RETURN_ON_ERROR);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
569 if (!mh)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
570 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
571 for (j = 0; j < i; j++)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
572 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
573 id = _dyld_get_image_name(j);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
574 if (!SDL_strcmp(id, name))
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
575 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
576 mh = _dyld_get_image_header(j);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
577 break;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
578 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
579 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
580 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
581 return mh;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
582 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
583
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
584 /*
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
585 * dyld adds libraries by first adding the directly dependant libraries in link order, and
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
586 * then adding the dependencies for those libraries, so we should do the same... but we don't
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
587 * bother adding the extra dependencies, if the symbols are neither in the loaded image nor
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
588 * any of it's direct dependencies, then it probably isn't there.
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
589 */
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
590 static NSSymbol search_linked_libs(const struct mach_header * mh, const char *symbol)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
591 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
592 unsigned int n;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
593 struct load_command *lc = 0;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
594 struct mach_header *wh;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
595 NSSymbol nssym = 0;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
596 if (dyld_NSAddImage && dyld_NSIsSymbolNameDefinedInImage && dyld_NSLookupSymbolInImage)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
597 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
598 lc = (struct load_command *)((char *)mh + sizeof(struct mach_header));
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
599 for (n = 0; n < mh->ncmds; n++, lc = (struct load_command *)((char *)lc + lc->cmdsize))
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
600 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
601 if ((LC_LOAD_DYLIB == lc->cmd) || (LC_LOAD_WEAK_DYLIB == lc->cmd))
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
602 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
603 if ((wh = (struct mach_header *)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
604 my_find_image((char *)(((struct dylib_command *)lc)->dylib.name.offset +
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
605 (char *)lc))))
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
606 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
607 if (dyld_NSIsSymbolNameDefinedInImage(wh, symbol))
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
608 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
609 nssym = dyld_NSLookupSymbolInImage(wh,
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
610 symbol,
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
611 NSLOOKUPSYMBOLINIMAGE_OPTION_BIND |
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
612 NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
613 break;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
614 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
615 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
616 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
617 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
618 if ((!nssym) && NSIsSymbolNameDefined(symbol))
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
619 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
620 /* I've never seen this debug message...*/
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
621 debug("Symbol \"%s\" is defined but was not found", symbol);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
622 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
623 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
624 return nssym;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
625 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
626
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
627 /* Up to the caller to SDL_free() returned string */
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
628 static inline char *dyld_error_str()
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
629 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
630 NSLinkEditErrors dylder;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
631 int dylderno;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
632 const char *dylderrstr;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
633 const char *dyldfile;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
634 char* retStr = NULL;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
635 NSLinkEditError(&dylder, &dylderno, &dyldfile, &dylderrstr);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
636 if (dylderrstr && *dylderrstr)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
637 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
638 retStr = SDL_strdup(dylderrstr);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
639 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
640 return retStr;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
641 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
642
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
643 static void *dlsymIntern(struct dlstatus *dls, const char *symbol, int canSetError)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
644 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
645 NSSymbol nssym = 0;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
646 #ifdef __GCC__
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
647 void *caller = __builtin_return_address(1); /* Be *very* careful about inlining */
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
648 #else
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
649 void *caller = NULL;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
650 #endif
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
651 const struct mach_header *caller_mh = 0;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
652 char *savedErrorStr = NULL;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
653 resetdlerror();
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
654 #ifndef RTLD_SELF
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
655 #define RTLD_SELF ((void *) -3)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
656 #endif
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
657 if (NULL == dls)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
658 dls = RTLD_SELF;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
659 if ((RTLD_NEXT == dls) || (RTLD_SELF == dls))
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
660 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
661 if (dyld_NSIsSymbolNameDefinedInImage && dyld_NSLookupSymbolInImage && caller)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
662 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
663 caller_mh = image_for_address(caller);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
664 if (RTLD_SELF == dls)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
665 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
666 /* FIXME: We should be using the NSModule api, if SELF is an MH_BUNDLE
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
667 * But it appears to work anyway, and looking at the code in dyld_libfuncs.c
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
668 * this is acceptable.
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
669 */
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
670 if (dyld_NSIsSymbolNameDefinedInImage(caller_mh, symbol))
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
671 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
672 nssym = dyld_NSLookupSymbolInImage(caller_mh,
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
673 symbol,
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
674 NSLOOKUPSYMBOLINIMAGE_OPTION_BIND |
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
675 NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
676 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
677 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
678 if (!nssym)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
679 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
680 if (RTLD_SELF == dls)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
681 savedErrorStr = dyld_error_str();
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
682 nssym = search_linked_libs(caller_mh, symbol);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
683 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
684 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
685 else
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
686 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
687 if (canSetError)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
688 error("RTLD_SELF and RTLD_NEXT are not supported");
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
689 return NULL;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
690 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
691 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
692 if (!nssym)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
693 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
694
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
695 if (RTLD_DEFAULT == dls)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
696 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
697 dls = &mainStatus;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
698 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
699 if (!isValidStatus(dls))
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
700 return NULL;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
701
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
702 if (dls->module != MAGIC_DYLIB_MOD)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
703 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
704 nssym = NSLookupSymbolInModule(dls->module, symbol);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
705 if (!nssym && NSIsSymbolNameDefined(symbol))
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
706 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
707 debug("Searching dependencies");
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
708 savedErrorStr = dyld_error_str();
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
709 nssym = search_linked_libs(get_mach_header_from_NSModule(dls->module), symbol);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
710 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
711 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
712 else if (dls->lib && dyld_NSIsSymbolNameDefinedInImage && dyld_NSLookupSymbolInImage)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
713 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
714 if (dyld_NSIsSymbolNameDefinedInImage(dls->lib, symbol))
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
715 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
716 nssym = dyld_NSLookupSymbolInImage(dls->lib,
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
717 symbol,
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
718 NSLOOKUPSYMBOLINIMAGE_OPTION_BIND |
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
719 NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
720 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
721 else if (NSIsSymbolNameDefined(symbol))
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
722 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
723 debug("Searching dependencies");
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
724 savedErrorStr = dyld_error_str();
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
725 nssym = search_linked_libs(dls->lib, symbol);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
726 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
727 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
728 else if (dls->module == MAGIC_DYLIB_MOD)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
729 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
730 /* Global context, use NSLookupAndBindSymbol */
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
731 if (NSIsSymbolNameDefined(symbol))
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
732 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
733 /* There doesn't seem to be a return on error option for this call???
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
734 this is potentially broken, if binding fails, it will improperly
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
735 exit the application. */
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
736 nssym = NSLookupAndBindSymbol(symbol);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
737 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
738 else
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
739 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
740 if (savedErrorStr)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
741 SDL_free(savedErrorStr);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
742 savedErrorStr = SDL_malloc(256);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
743 SDL_snprintf(savedErrorStr, 256, "Symbol \"%s\" not in global context",symbol);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
744 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
745 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
746 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
747 /* Error reporting */
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
748 if (!nssym)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
749 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
750 if (!savedErrorStr || !SDL_strlen(savedErrorStr))
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
751 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
752 if (savedErrorStr)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
753 SDL_free(savedErrorStr);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
754 savedErrorStr = SDL_malloc(256);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
755 SDL_snprintf(savedErrorStr, 256,"Symbol \"%s\" not found",symbol);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
756 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
757 if (canSetError)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
758 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
759 error(savedErrorStr);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
760 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
761 else
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
762 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
763 debug(savedErrorStr);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
764 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
765 if (savedErrorStr)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
766 SDL_free(savedErrorStr);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
767 return NULL;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
768 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
769 return NSAddressOfSymbol(nssym);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
770 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
771
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
772 static struct dlstatus *loadModule(const char *path, const struct stat *sbuf, int mode)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
773 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
774 NSObjectFileImage ofi = 0;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
775 NSObjectFileImageReturnCode ofirc;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
776 struct dlstatus *dls;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
777 NSLinkEditErrors ler;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
778 int lerno;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
779 const char *errstr;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
780 const char *file;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
781 void (*init) (void);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
782
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
783 ofirc = NSCreateObjectFileImageFromFile(path, &ofi);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
784 switch (ofirc)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
785 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
786 case NSObjectFileImageSuccess:
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
787 break;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
788 case NSObjectFileImageInappropriateFile:
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
789 if (dyld_NSAddImage && dyld_NSIsSymbolNameDefinedInImage && dyld_NSLookupSymbolInImage)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
790 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
791 if (isFlagSet(mode, RTLD_LOCAL))
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
792 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
793 warning("trying to open a .dylib with RTLD_LOCAL");
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
794 error("unable to open this file with RTLD_LOCAL");
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
795 return NULL;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
796 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
797 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
798 else
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
799 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
800 error("opening this file is unsupported on this system");
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
801 return NULL;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
802 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
803 break;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
804 case NSObjectFileImageFailure:
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
805 error("object file setup failure");
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
806 return NULL;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
807 case NSObjectFileImageArch:
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
808 error("no object for this architecture");
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
809 return NULL;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
810 case NSObjectFileImageFormat:
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
811 error("bad object file format");
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
812 return NULL;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
813 case NSObjectFileImageAccess:
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
814 error("can't read object file");
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
815 return NULL;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
816 default:
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
817 error("unknown error from NSCreateObjectFileImageFromFile()");
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
818 return NULL;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
819 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
820 dls = lookupStatus(sbuf);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
821 if (!dls)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
822 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
823 dls = allocStatus();
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
824 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
825 if (!dls)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
826 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
827 error("unable to allocate memory");
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
828 return NULL;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
829 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
830 // dls->lib = 0;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
831 if (ofirc == NSObjectFileImageInappropriateFile)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
832 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
833 if ((dls->lib = dyld_NSAddImage(path, NSADDIMAGE_OPTION_RETURN_ON_ERROR)))
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
834 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
835 debug("Dynamic lib loaded at %ld", dls->lib);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
836 ofi = MAGIC_DYLIB_OFI;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
837 dls->module = MAGIC_DYLIB_MOD;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
838 ofirc = NSObjectFileImageSuccess;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
839 /* Although it is possible with a bit of work to modify this so it works and
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
840 functions with RTLD_NOW, I don't deem it necessary at the moment */
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
841 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
842 if (!(dls->module))
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
843 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
844 NSLinkEditError(&ler, &lerno, &file, &errstr);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
845 if (!errstr || (!SDL_strlen(errstr)))
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
846 error("Can't open this file type");
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
847 else
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
848 error(errstr);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
849 if ((dls->flags & DL_IN_LIST) == 0)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
850 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
851 SDL_free(dls);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
852 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
853 return NULL;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
854 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
855 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
856 else
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
857 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
858 dls->module = NSLinkModule(ofi, path,
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
859 NSLINKMODULE_OPTION_RETURN_ON_ERROR |
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
860 NSLINKMODULE_OPTION_PRIVATE |
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
861 (isFlagSet(mode, RTLD_NOW) ? NSLINKMODULE_OPTION_BINDNOW : 0));
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
862 NSDestroyObjectFileImage(ofi);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
863 if (dls->module)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
864 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
865 dls->lib = get_mach_header_from_NSModule(dls->module);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
866 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
867 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
868 if (!dls->module)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
869 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
870 NSLinkEditError(&ler, &lerno, &file, &errstr);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
871 if ((dls->flags & DL_IN_LIST) == 0)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
872 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
873 SDL_free(dls);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
874 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
875 error(errstr);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
876 return NULL;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
877 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
878
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
879 insertStatus(dls, sbuf);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
880 dls = reference(dls, mode);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
881 if ((init = dlsymIntern(dls, "__init", 0)))
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
882 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
883 debug("calling _init()");
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
884 init();
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
885 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
886 return dls;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
887 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
888
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
889 inline static void dlcompat_init_check(void)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
890 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
891 static pthread_mutex_t l = PTHREAD_MUTEX_INITIALIZER;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
892 static int init_done = 0;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
893
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
894 pthread_mutex_lock(&l);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
895 if (!init_done) {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
896 dlcompat_init_func();
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
897 init_done = 1;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
898 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
899 pthread_mutex_unlock(&l);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
900 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
901
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
902 static void dlcompat_init_func(void)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
903 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
904 _dyld_func_lookup("__dyld_NSAddImage", (void **)&dyld_NSAddImage);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
905 _dyld_func_lookup("__dyld_NSIsSymbolNameDefinedInImage",
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
906 (void **)&dyld_NSIsSymbolNameDefinedInImage);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
907 _dyld_func_lookup("__dyld_NSLookupSymbolInImage", (void **)&dyld_NSLookupSymbolInImage);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
908 if (pthread_mutex_init(&dlcompat_mutex, NULL))
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
909 exit(1);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
910 if (pthread_key_create(&dlerror_key, &dlerrorfree))
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
911 exit(1);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
912 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
913
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
914 static void resetdlerror()
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
915 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
916 struct dlthread *tss;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
917 tss = pthread_getspecific(dlerror_key);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
918 tss->errset = 0;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
919 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
920
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
921 static void dlerrorfree(void *data)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
922 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
923 SDL_free(data);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
924 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
925
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
926 /* We kind of want a recursive lock here, but meet a little trouble
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
927 * because they are not available pre OS X 10.2, so we fake it
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
928 * using thread specific storage to keep a lock count
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
929 */
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
930 static inline void dolock(void)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
931 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
932 int err = 0;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
933 struct dlthread *tss;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
934 dlcompat_init_check();
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
935 tss = pthread_getspecific(dlerror_key);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
936 if (!tss)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
937 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
938 tss = SDL_malloc(sizeof(struct dlthread));
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
939 tss->lockcnt = 0;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
940 tss->errset = 0;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
941 if (pthread_setspecific(dlerror_key, tss))
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
942 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
943 fprintf(stderr,"dlcompat: pthread_setspecific failed\n");
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
944 exit(1);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
945 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
946 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
947 if (!tss->lockcnt)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
948 err = pthread_mutex_lock(&dlcompat_mutex);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
949 tss->lockcnt = tss->lockcnt +1;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
950 if (err)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
951 exit(err);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
952 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
953
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
954 static inline void dounlock(void)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
955 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
956 int err = 0;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
957 struct dlthread *tss;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
958 tss = pthread_getspecific(dlerror_key);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
959 tss->lockcnt = tss->lockcnt -1;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
960 if (!tss->lockcnt)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
961 err = pthread_mutex_unlock(&dlcompat_mutex);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
962 if (err)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
963 exit(err);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
964 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
965
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
966 static void *SDL_OSX_dlopen(const char *path, int mode)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
967 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
968 const struct stat *sbuf;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
969 struct dlstatus *dls;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
970 const char *fullPath;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
971
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
972 dolock();
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
973 resetdlerror();
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
974 if (!path)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
975 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
976 dls = &mainStatus;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
977 goto dlopenok;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
978 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
979 if (!(sbuf = findFile(path, &fullPath)))
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
980 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
981 error("file \"%s\" not found", path);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
982 goto dlopenerror;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
983 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
984 /* Now checks that it hasn't been closed already */
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
985 if ((dls = lookupStatus(sbuf)) && (dls->refs > 0))
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
986 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
987 /* debug("status found"); */
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
988 dls = reference(dls, mode);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
989 goto dlopenok;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
990 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
991 #ifdef RTLD_NOLOAD
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
992 if (isFlagSet(mode, RTLD_NOLOAD))
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
993 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
994 error("no existing handle and RTLD_NOLOAD specified");
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
995 goto dlopenerror;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
996 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
997 #endif
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
998 if (isFlagSet(mode, RTLD_LAZY) && isFlagSet(mode, RTLD_NOW))
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
999 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1000 error("how can I load something both RTLD_LAZY and RTLD_NOW?");
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1001 goto dlopenerror;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1002 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1003 dls = loadModule(fullPath, sbuf, mode);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1004
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1005 dlopenok:
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1006 dounlock();
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1007 return (void *)dls;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1008 dlopenerror:
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1009 dounlock();
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1010 return NULL;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1011 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1012
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1013 #if !FINK_BUILD
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1014 static void *SDL_OSX_dlsym(void * dl_restrict handle, const char * dl_restrict symbol)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1015 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1016 int sym_len = SDL_strlen(symbol);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1017 void *value = NULL;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1018 char *malloc_sym = NULL;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1019 dolock();
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1020 malloc_sym = SDL_malloc(sym_len + 2);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1021 if (malloc_sym)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1022 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1023 SDL_snprintf(malloc_sym, sym_len+2, "_%s", symbol);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1024 value = dlsymIntern(handle, malloc_sym, 1);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1025 SDL_free(malloc_sym);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1026 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1027 else
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1028 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1029 error("Unable to allocate memory");
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1030 goto dlsymerror;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1031 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1032 dounlock();
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1033 return value;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1034 dlsymerror:
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1035 dounlock();
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1036 return NULL;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1037 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1038 #endif
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1039
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1040 #if FINK_BUILD
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1041
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1042 static void *dlsym_prepend_underscore(void *handle, const char *symbol)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1043 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1044 void *answer;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1045 dolock();
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1046 answer = dlsym_prepend_underscore_intern(handle, symbol);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1047 dounlock();
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1048 return answer;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1049 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1050
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1051 static void *dlsym_prepend_underscore_intern(void *handle, const char *symbol)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1052 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1053 /*
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1054 * A quick and easy way for porting packages which call dlsym(handle,"sym")
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1055 * If the porter adds -Ddlsym=dlsym_prepend_underscore to the CFLAGS then
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1056 * this function will be called, and will add the required underscore.
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1057 *
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1058 * Note that I haven't figured out yet which should be "standard", prepend
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1059 * the underscore always, or not at all. These global functions need to go away
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1060 * for opendarwin.
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1061 */
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1062 int sym_len = SDL_strlen(symbol);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1063 void *value = NULL;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1064 char *malloc_sym = NULL;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1065 malloc_sym = SDL_malloc(sym_len + 2);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1066 if (malloc_sym)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1067 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1068 SDL_snprintf(malloc_sym, sym_len+2, "_%s", symbol);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1069 value = dlsymIntern(handle, malloc_sym, 1);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1070 SDL_free(malloc_sym);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1071 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1072 else
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1073 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1074 error("Unable to allocate memory");
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1075 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1076 return value;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1077 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1078
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1079 static void *dlsym_auto_underscore(void *handle, const char *symbol)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1080 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1081 void *answer;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1082 dolock();
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1083 answer = dlsym_auto_underscore_intern(handle, symbol);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1084 dounlock();
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1085 return answer;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1086
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1087 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1088 static void *dlsym_auto_underscore_intern(void *handle, const char *symbol)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1089 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1090 struct dlstatus *dls = handle;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1091 void *addr = 0;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1092 addr = dlsymIntern(dls, symbol, 0);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1093 if (!addr)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1094 addr = dlsym_prepend_underscore_intern(handle, symbol);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1095 return addr;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1096 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1097
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1098
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1099 static void *SDL_OSX_dlsym(void * dl_restrict handle, const char * dl_restrict symbol)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1100 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1101 struct dlstatus *dls = handle;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1102 void *addr = 0;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1103 dolock();
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1104 addr = dlsymIntern(dls, symbol, 1);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1105 dounlock();
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1106 return addr;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1107 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1108 #endif
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1109
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1110 static int SDL_OSX_dlclose(void *handle)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1111 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1112 struct dlstatus *dls = handle;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1113 dolock();
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1114 resetdlerror();
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1115 if (!isValidStatus(dls))
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1116 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1117 goto dlcloseerror;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1118 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1119 if (dls->module == MAGIC_DYLIB_MOD)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1120 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1121 const char *name;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1122 if (!dls->lib)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1123 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1124 name = "global context";
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1125 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1126 else
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1127 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1128 name = get_lib_name(dls->lib);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1129 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1130 warning("trying to close a .dylib!");
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1131 error("Not closing \"%s\" - dynamic libraries cannot be closed", name);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1132 goto dlcloseerror;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1133 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1134 if (!dls->module)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1135 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1136 error("module already closed");
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1137 goto dlcloseerror;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1138 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1139
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1140 if (dls->refs == 1)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1141 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1142 unsigned long options = 0;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1143 void (*fini) (void);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1144 if ((fini = dlsymIntern(dls, "__fini", 0)))
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1145 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1146 debug("calling _fini()");
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1147 fini();
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1148 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1149 options |= NSUNLINKMODULE_OPTION_RESET_LAZY_REFERENCES;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1150 #ifdef RTLD_NODELETE
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1151 if (isFlagSet(dls->mode, RTLD_NODELETE))
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1152 options |= NSUNLINKMODULE_OPTION_KEEP_MEMORY_MAPPED;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1153 #endif
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1154 if (!NSUnLinkModule(dls->module, options))
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1155 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1156 error("unable to unlink module");
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1157 goto dlcloseerror;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1158 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1159 dls->refs--;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1160 dls->module = 0;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1161 /* Note: the dlstatus struct dls is neither removed from the list
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1162 * nor is the memory it occupies freed. This shouldn't pose a
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1163 * problem in mostly all cases, though.
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1164 */
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1165 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1166 dounlock();
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1167 return 0;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1168 dlcloseerror:
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1169 dounlock();
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1170 return 1;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1171 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1172
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1173 static const char *SDL_OSX_dlerror(void)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1174 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1175 struct dlthread *tss;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1176 const char * err_str = NULL;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1177 dlcompat_init_check();
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1178 tss = pthread_getspecific(dlerror_key);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1179 if (tss != NULL && tss->errset != 0) {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1180 tss->errset = 0;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1181 err_str = tss->errstr;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1182 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1183 return (err_str);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1184 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1185
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1186 /* Given an address, return the mach_header for the image containing it
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1187 * or zero if the given address is not contained in any loaded images.
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1188 */
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1189 static const struct mach_header *image_for_address(const void *address)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1190 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1191 unsigned long i;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1192 unsigned long j;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1193 unsigned long count = _dyld_image_count();
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1194 const struct mach_header *mh = 0;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1195 struct load_command *lc = 0;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1196 unsigned long addr = 0;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1197 for (i = 0; i < count; i++)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1198 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1199 addr = (unsigned long)address - _dyld_get_image_vmaddr_slide(i);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1200 mh = _dyld_get_image_header(i);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1201 if (mh)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1202 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1203 lc = (struct load_command *)((char *)mh + sizeof(struct mach_header));
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1204 for (j = 0; j < mh->ncmds; j++, lc = (struct load_command *)((char *)lc + lc->cmdsize))
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1205 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1206 if (LC_SEGMENT == lc->cmd &&
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1207 addr >= ((struct segment_command *)lc)->vmaddr &&
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1208 addr <
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1209 ((struct segment_command *)lc)->vmaddr + ((struct segment_command *)lc)->vmsize)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1210 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1211 goto image_found;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1212 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1213 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1214 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1215 mh = 0;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1216 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1217 image_found:
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1218 return mh;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1219 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1220
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1221 #if 0 /* unused */
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1222 static int SDL_OSX_dladdr(const void * dl_restrict p, SDL_OSX_Dl_info * dl_restrict info)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1223 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1224 /*
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1225 FIXME: USe the routine image_for_address.
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1226 */
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1227 unsigned long i;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1228 unsigned long j;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1229 unsigned long count = _dyld_image_count();
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1230 struct mach_header *mh = 0;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1231 struct load_command *lc = 0;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1232 unsigned long addr = NULL;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1233 unsigned long table_off = (unsigned long)0;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1234 int found = 0;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1235 if (!info)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1236 return 0;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1237 dolock();
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1238 resetdlerror();
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1239 info->dli_fname = 0;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1240 info->dli_fbase = 0;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1241 info->dli_sname = 0;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1242 info->dli_saddr = 0;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1243 /* Some of this was swiped from code posted by Douglas Davidson <ddavidso AT apple DOT com>
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1244 * to darwin-development AT lists DOT apple DOT com and slightly modified
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1245 */
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1246 for (i = 0; i < count; i++)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1247 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1248 addr = (unsigned long)p - _dyld_get_image_vmaddr_slide(i);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1249 mh = _dyld_get_image_header(i);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1250 if (mh)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1251 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1252 lc = (struct load_command *)((char *)mh + sizeof(struct mach_header));
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1253 for (j = 0; j < mh->ncmds; j++, lc = (struct load_command *)((char *)lc + lc->cmdsize))
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1254 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1255 if (LC_SEGMENT == lc->cmd &&
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1256 addr >= ((struct segment_command *)lc)->vmaddr &&
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1257 addr <
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1258 ((struct segment_command *)lc)->vmaddr + ((struct segment_command *)lc)->vmsize)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1259 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1260 info->dli_fname = _dyld_get_image_name(i);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1261 info->dli_fbase = (void *)mh;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1262 found = 1;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1263 break;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1264 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1265 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1266 if (found)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1267 break;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1268 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1269 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1270 if (!found)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1271 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1272 dounlock();
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1273 return 0;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1274 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1275 lc = (struct load_command *)((char *)mh + sizeof(struct mach_header));
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1276 for (j = 0; j < mh->ncmds; j++, lc = (struct load_command *)((char *)lc + lc->cmdsize))
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1277 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1278 if (LC_SEGMENT == lc->cmd)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1279 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1280 if (!SDL_strcmp(((struct segment_command *)lc)->segname, "__LINKEDIT"))
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1281 break;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1282 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1283 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1284 table_off =
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1285 ((unsigned long)((struct segment_command *)lc)->vmaddr) -
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1286 ((unsigned long)((struct segment_command *)lc)->fileoff) + _dyld_get_image_vmaddr_slide(i);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1287 debug("table off %x", table_off);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1288
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1289 lc = (struct load_command *)((char *)mh + sizeof(struct mach_header));
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1290 for (j = 0; j < mh->ncmds; j++, lc = (struct load_command *)((char *)lc + lc->cmdsize))
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1291 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1292 if (LC_SYMTAB == lc->cmd)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1293 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1294
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1295 struct nlist *symtable = (struct nlist *)(((struct symtab_command *)lc)->symoff + table_off);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1296 unsigned long numsyms = ((struct symtab_command *)lc)->nsyms;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1297 struct nlist *nearest = NULL;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1298 unsigned long diff = 0xffffffff;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1299 unsigned long strtable = (unsigned long)(((struct symtab_command *)lc)->stroff + table_off);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1300 debug("symtable %x", symtable);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1301 for (i = 0; i < numsyms; i++)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1302 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1303 /* Ignore the following kinds of Symbols */
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1304 if ((!symtable->n_value) /* Undefined */
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1305 || (symtable->n_type >= N_PEXT) /* Debug symbol */
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1306 || (!(symtable->n_type & N_EXT)) /* Local Symbol */
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1307 )
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1308 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1309 symtable++;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1310 continue;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1311 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1312 if ((addr >= symtable->n_value) && (diff >= (symtable->n_value - addr)))
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1313 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1314 diff = (unsigned long)symtable->n_value - addr;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1315 nearest = symtable;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1316 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1317 symtable++;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1318 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1319 if (nearest)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1320 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1321 info->dli_saddr = nearest->n_value + ((void *)p - addr);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1322 info->dli_sname = (char *)(strtable + nearest->n_un.n_strx);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1323 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1324 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1325 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1326 dounlock();
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1327 return 1;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1328 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1329 #endif
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1330
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1331 /*
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1332 * Implement the dlfunc() interface, which behaves exactly the same as
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1333 * dlsym() except that it returns a function pointer instead of a data
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1334 * pointer. This can be used by applications to avoid compiler warnings
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1335 * about undefined behavior, and is intended as prior art for future
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1336 * POSIX standardization. This function requires that all pointer types
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1337 * have the same representation, which is true on all platforms FreeBSD
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1338 * runs on, but is not guaranteed by the C standard.
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1339 */
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1340 #if 0
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1341 static dlfunc_t SDL_OSX_dlfunc(void * dl_restrict handle, const char * dl_restrict symbol)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1342 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1343 union
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1344 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1345 void *d;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1346 dlfunc_t f;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1347 } rv;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1348 int sym_len = SDL_strlen(symbol);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1349 char *malloc_sym = NULL;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1350 dolock();
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1351 malloc_sym = SDL_malloc(sym_len + 2);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1352 if (malloc_sym)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1353 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1354 SDL_snprintf(malloc_sym, sym_len+2, "_%s", symbol);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1355 rv.d = dlsymIntern(handle, malloc_sym, 1);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1356 SDL_free(malloc_sym);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1357 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1358 else
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1359 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1360 error("Unable to allocate memory");
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1361 goto dlfuncerror;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1362 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1363 dounlock();
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1364 return rv.f;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1365 dlfuncerror:
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1366 dounlock();
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1367 return NULL;
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1368 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1369 #endif
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1370
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1371
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1372
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1373 /* dlcompat ends, here's the SDL interface... --ryan. */
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1374
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1375
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1376 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1377 /* System dependent library loading routines */
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1378
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1379 #include "SDL_loadso.h"
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1380
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1381 void *SDL_LoadObject(const char *sofile)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1382 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1383 void *handle = SDL_OSX_dlopen(sofile, RTLD_NOW);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1384 const char *loaderror = SDL_OSX_dlerror();
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1385 if ( handle == NULL ) {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1386 SDL_SetError("Failed loading %s: %s", sofile, loaderror);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1387 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1388 return(handle);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1389 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1390
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1391 void *SDL_LoadFunction(void *handle, const char *name)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1392 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1393 void *symbol = SDL_OSX_dlsym(handle, name);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1394 if ( symbol == NULL ) {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1395 SDL_SetError("Failed loading %s: %s", name, SDL_OSX_dlerror());
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1396 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1397 return(symbol);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1398 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1399
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1400 void SDL_UnloadObject(void *handle)
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1401 {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1402 if ( handle != NULL ) {
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1403 SDL_OSX_dlclose(handle);
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1404 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1405 }
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1406
e308d020d315 Xcode has trouble compiling different files with the same name for two architectures
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1407 #endif /* SDL_LOADSO_DLCOMPAT */