author | Claus Gittinger <cg@exept.de> |
Tue, 12 Nov 1996 13:18:57 +0100 | |
changeset 441 | fa5637faa969 |
parent 409 | 19629e650ba9 |
child 447 | 4aaa152c17c4 |
permissions | -rw-r--r-- |
0 | 1 |
" |
2 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
45 | 3 |
All Rights Reserved |
0 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
12 |
||
13 |
Object subclass:#ObjectFileLoader |
|
174 | 14 |
instanceVariableNames:'' |
15 |
classVariableNames:'MySymbolTable Verbose LastError LinkErrorMessage NextHandleID |
|
149
3dc42a5ab417
default for SearchedLibraries
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
16 |
LoadedObjects PreviouslyLoadedObjects ActuallyLoadedObjects |
321
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
17 |
SearchedLibraries LibPath' |
174 | 18 |
poolDictionaries:'' |
19 |
category:'System-Compiler' |
|
47 | 20 |
! |
21 |
||
53 | 22 |
!ObjectFileLoader primitiveDefinitions! |
0 | 23 |
%{ |
320
54bfd6fd28b9
removed old obsolete manual loader; aix fixes
Claus Gittinger <cg@exept.de>
parents:
317
diff
changeset
|
24 |
|
15 | 25 |
/* |
26 |
* by default, use whatever the system provides |
|
27 |
*/ |
|
95 | 28 |
#ifdef sunos /* sunos (pre 5.4) dlopen interface */ |
15 | 29 |
# define SUN_DL |
20 | 30 |
# define HAS_DL |
15 | 31 |
#endif |
32 |
||
95 | 33 |
#ifdef NeXT /* next rld interface */ |
15 | 34 |
# define NEXT_DL |
20 | 35 |
# define HAS_DL |
15 | 36 |
#endif |
37 |
||
182
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
180
diff
changeset
|
38 |
#if defined(SYSV4) || defined(HAS_DLOPEN) /* sys5.4 dlopen interface */ |
15 | 39 |
# define SYSV4_DL |
20 | 40 |
# define HAS_DL |
15 | 41 |
#endif |
42 |
||
95 | 43 |
#ifdef DL1_6 /* dl1.6 COFF loader */ |
44 |
# define HAS_DL |
|
45 |
#endif |
|
46 |
||
98 | 47 |
#ifdef _AIX |
97 | 48 |
# define AIX_DL |
49 |
# define HAS_DL |
|
50 |
#endif |
|
51 |
||
15 | 52 |
/* |
20 | 53 |
* but GNU_DL overwrites this - its better |
15 | 54 |
*/ |
95 | 55 |
#ifdef GNU_DL /* dld2.3.x interface */ |
20 | 56 |
# define HAS_DL |
15 | 57 |
# undef SYSV4_DL |
58 |
# undef NEXT_DL |
|
59 |
# undef SUN_DL |
|
95 | 60 |
# undef DL1_6 |
15 | 61 |
#endif |
62 |
||
20 | 63 |
#include <stdio.h> |
64 |
||
175
f94969b034c7
make it compilable (at least) on WIN32 (which defines COFF ?!)
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
65 |
#if defined(WIN32) |
f94969b034c7
make it compilable (at least) on WIN32 (which defines COFF ?!)
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
66 |
# undef COFF |
f94969b034c7
make it compilable (at least) on WIN32 (which defines COFF ?!)
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
67 |
# undef ELF |
f94969b034c7
make it compilable (at least) on WIN32 (which defines COFF ?!)
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
68 |
# undef A_DOT_OUT |
180 | 69 |
# define HAS_DL |
70 |
# define WIN_DL |
|
175
f94969b034c7
make it compilable (at least) on WIN32 (which defines COFF ?!)
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
71 |
#endif |
f94969b034c7
make it compilable (at least) on WIN32 (which defines COFF ?!)
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
72 |
|
20 | 73 |
/* |
95 | 74 |
* if no dynamic link facilities, try it the hard way ... |
20 | 75 |
*/ |
175
f94969b034c7
make it compilable (at least) on WIN32 (which defines COFF ?!)
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
76 |
#if !defined(HAS_DL) |
20 | 77 |
|
78 |
# ifdef A_DOT_OUT |
|
79 |
# include <a.out.h> |
|
80 |
# ifndef N_MAGIC |
|
81 |
# if defined(sinix) && defined(BSD) |
|
82 |
# define N_MAGIC(hdr) (hdr.a_magic & 0xFFFF) |
|
83 |
# else |
|
84 |
# define N_MAGIC(hdr) (hdr.a_magic) |
|
85 |
# endif |
|
86 |
# endif |
|
87 |
# endif /* a.out */ |
|
88 |
||
89 |
# ifdef COFF |
|
90 |
# ifdef mips |
|
91 |
# include <sys/exec.h> |
|
92 |
# else |
|
93 |
# include <a.out.h> |
|
94 |
# endif |
|
95 |
# endif /* coff */ |
|
96 |
||
97 |
# ifdef ELF |
|
98 |
# include <elf.h> |
|
99 |
# endif /* elf */ |
|
100 |
||
101 |
#endif /* not HAS_DL */ |
|
102 |
||
95 | 103 |
#ifdef NEXT_DL |
104 |
# ifndef _RLD_H_ |
|
105 |
# define _RLD_H_ |
|
125 | 106 |
# ifdef NEXT3 |
107 |
# include <mach-o/rld.h> |
|
108 |
# else |
|
109 |
# include <rld.h> |
|
110 |
# endif |
|
95 | 111 |
# endif |
112 |
#endif /* NEXT_DL */ |
|
113 |
||
28 | 114 |
#ifdef SYSV4_DL |
115 |
# include <dlfcn.h> |
|
116 |
# define dlcfn_h |
|
117 |
#endif |
|
118 |
||
45 | 119 |
#ifdef GNU_DL |
120 |
# ifndef dld_h |
|
121 |
# include "dld.h" |
|
122 |
# define dld_h |
|
123 |
# endif |
|
124 |
#endif |
|
95 | 125 |
|
126 |
#ifdef DL1_6 |
|
127 |
# ifndef dl_h |
|
128 |
# include "dl.h" |
|
129 |
# define dl_h |
|
130 |
# endif |
|
131 |
#endif |
|
132 |
||
97 | 133 |
#ifdef AIX_DL |
134 |
# include <nlist.h> |
|
100 | 135 |
# include <sys/ldr.h> |
136 |
# include <errno.h> |
|
97 | 137 |
#endif |
180 | 138 |
|
139 |
#ifdef WIN_DL |
|
140 |
||
141 |
# ifdef WIN32 |
|
142 |
# undef INT |
|
143 |
# undef Array |
|
144 |
# undef Number |
|
145 |
# undef Method |
|
146 |
||
147 |
# ifdef i386 |
|
148 |
# define _X86_ |
|
149 |
# endif |
|
150 |
||
151 |
/* # include <windows.h> /* */ |
|
152 |
# include <windef.h> /* */ |
|
153 |
# include <winbase.h> /* */ |
|
154 |
||
208 | 155 |
# ifdef __DEF_Array |
156 |
# define Array __DEF_Array |
|
180 | 157 |
# endif |
208 | 158 |
# ifdef __DEF_Number |
159 |
# define Number __DEF_Number |
|
180 | 160 |
# endif |
208 | 161 |
# ifdef __DEF_Method |
162 |
# define Method __DEF_Method |
|
180 | 163 |
# endif |
164 |
# endif |
|
165 |
||
166 |
#endif |
|
0 | 167 |
%} |
20 | 168 |
! ! |
169 |
||
369 | 170 |
!ObjectFileLoader class methodsFor:'documentation'! |
141 | 171 |
|
172 |
copyright |
|
173 |
" |
|
174 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
175 |
All Rights Reserved |
|
176 |
||
177 |
This software is furnished under a license and may be used |
|
178 |
only in accordance with the terms of that license and with the |
|
179 |
inclusion of the above copyright notice. This software may not |
|
180 |
be provided or otherwise made available to, or used by, any |
|
181 |
other person. No title to or ownership of the software is |
|
182 |
hereby transferred. |
|
183 |
" |
|
184 |
! |
|
185 |
||
186 |
documentation |
|
187 |
" |
|
188 |
This class knowns how to dynamically load in external object-modules. |
|
189 |
||
190 |
WARNING: |
|
191 |
As to date, this is completely experimental and WITHOUT ANY WARRANTY. |
|
192 |
It is still being developed and the code below needs cleanup and more |
|
193 |
robustness. |
|
194 |
||
195 |
There are basically two totally different mechanisms to do this: |
|
263 | 196 |
a) if there exists some dynamic-link facility such as: |
197 |
GNU-DL, dlopen (sparc, SYS5.4), rld_open (NeXT), |
|
198 |
this is used |
|
199 |
b) if no such facility exists, the normal linker is used to |
|
200 |
link the module to text/data address as previously malloced, |
|
201 |
and the object file loaded into that space. |
|
141 | 202 |
|
203 |
Currently, not all mechanisms work fully satisfying. |
|
204 |
For example, the sun dl*-functions do an exit on link-errors (which |
|
205 |
is certainly not what we want here :-(; the NeXT mechanism does not |
|
206 |
allow for selective unloading (only all or last). |
|
207 |
||
208 |
The only really useful packages are the GNU-dl package and the SGI/Unixware |
|
209 |
sys5.4 libdl packages. |
|
210 |
The GNU-dl package is only available for a.out file formats; |
|
211 |
i.e. only (a subset of) linux people can use it at this time. |
|
212 |
For the above reasons, dynamic object loading is currently only |
|
213 |
officially released for SYS5.4 and LINUX systems. |
|
214 |
||
215 |
Once stable, the functionality contained herein will be moved into |
|
216 |
the VM. |
|
217 |
(It is needed there, to allow reloading of objectfiles upon |
|
218 |
image restart; i.e. before any class is reinitialilized). |
|
263 | 219 |
|
220 |
[author:] |
|
221 |
Claus Gittinger |
|
141 | 222 |
" |
223 |
! ! |
|
224 |
||
369 | 225 |
!ObjectFileLoader class methodsFor:'initialization'! |
0 | 226 |
|
227 |
initialize |
|
317 | 228 |
|systemType| |
0 | 229 |
|
201 | 230 |
MySymbolTable isNil ifTrue:[ |
316
ee3426730cfc
on sunos: link dynamic objects against libc.a for unresolved symbols.
Claus Gittinger <cg@exept.de>
parents:
307
diff
changeset
|
231 |
Verbose := false. |
ee3426730cfc
on sunos: link dynamic objects against libc.a for unresolved symbols.
Claus Gittinger <cg@exept.de>
parents:
307
diff
changeset
|
232 |
NextHandleID := 1. |
ee3426730cfc
on sunos: link dynamic objects against libc.a for unresolved symbols.
Claus Gittinger <cg@exept.de>
parents:
307
diff
changeset
|
233 |
ObjectMemory addDependent:self. |
ee3426730cfc
on sunos: link dynamic objects against libc.a for unresolved symbols.
Claus Gittinger <cg@exept.de>
parents:
307
diff
changeset
|
234 |
|
ee3426730cfc
on sunos: link dynamic objects against libc.a for unresolved symbols.
Claus Gittinger <cg@exept.de>
parents:
307
diff
changeset
|
235 |
"/ name of object file, where initial symbol table is found |
ee3426730cfc
on sunos: link dynamic objects against libc.a for unresolved symbols.
Claus Gittinger <cg@exept.de>
parents:
307
diff
changeset
|
236 |
"/ not req'd for all architectures. |
ee3426730cfc
on sunos: link dynamic objects against libc.a for unresolved symbols.
Claus Gittinger <cg@exept.de>
parents:
307
diff
changeset
|
237 |
|
ee3426730cfc
on sunos: link dynamic objects against libc.a for unresolved symbols.
Claus Gittinger <cg@exept.de>
parents:
307
diff
changeset
|
238 |
MySymbolTable := 'smalltalk'. |
ee3426730cfc
on sunos: link dynamic objects against libc.a for unresolved symbols.
Claus Gittinger <cg@exept.de>
parents:
307
diff
changeset
|
239 |
|
ee3426730cfc
on sunos: link dynamic objects against libc.a for unresolved symbols.
Claus Gittinger <cg@exept.de>
parents:
307
diff
changeset
|
240 |
"/ default set of libraries to be considered when |
ee3426730cfc
on sunos: link dynamic objects against libc.a for unresolved symbols.
Claus Gittinger <cg@exept.de>
parents:
307
diff
changeset
|
241 |
"/ unresolved symbols are encountered during the load. |
321
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
242 |
"/ Only req'd for linux and sunos non-ELF systems. |
316
ee3426730cfc
on sunos: link dynamic objects against libc.a for unresolved symbols.
Claus Gittinger <cg@exept.de>
parents:
307
diff
changeset
|
243 |
"/ Can (should) be set in the smalltalk.rc file. |
ee3426730cfc
on sunos: link dynamic objects against libc.a for unresolved symbols.
Claus Gittinger <cg@exept.de>
parents:
307
diff
changeset
|
244 |
|
ee3426730cfc
on sunos: link dynamic objects against libc.a for unresolved symbols.
Claus Gittinger <cg@exept.de>
parents:
307
diff
changeset
|
245 |
SearchedLibraries := #(). |
ee3426730cfc
on sunos: link dynamic objects against libc.a for unresolved symbols.
Claus Gittinger <cg@exept.de>
parents:
307
diff
changeset
|
246 |
|
317 | 247 |
((systemType := OperatingSystem getSystemType) = 'linux' |
248 |
or:[systemType = 'sunos']) ifTrue:[ |
|
316
ee3426730cfc
on sunos: link dynamic objects against libc.a for unresolved symbols.
Claus Gittinger <cg@exept.de>
parents:
307
diff
changeset
|
249 |
'/usr/lib/libc.a' asFilename isReadable ifTrue:[ |
ee3426730cfc
on sunos: link dynamic objects against libc.a for unresolved symbols.
Claus Gittinger <cg@exept.de>
parents:
307
diff
changeset
|
250 |
SearchedLibraries := #('/usr/lib/libc.a') |
ee3426730cfc
on sunos: link dynamic objects against libc.a for unresolved symbols.
Claus Gittinger <cg@exept.de>
parents:
307
diff
changeset
|
251 |
] ifFalse:[ |
ee3426730cfc
on sunos: link dynamic objects against libc.a for unresolved symbols.
Claus Gittinger <cg@exept.de>
parents:
307
diff
changeset
|
252 |
'/lib/libc.a' asFilename isReadable ifTrue:[ |
ee3426730cfc
on sunos: link dynamic objects against libc.a for unresolved symbols.
Claus Gittinger <cg@exept.de>
parents:
307
diff
changeset
|
253 |
SearchedLibraries := #('/lib/libc.a') |
ee3426730cfc
on sunos: link dynamic objects against libc.a for unresolved symbols.
Claus Gittinger <cg@exept.de>
parents:
307
diff
changeset
|
254 |
] |
ee3426730cfc
on sunos: link dynamic objects against libc.a for unresolved symbols.
Claus Gittinger <cg@exept.de>
parents:
307
diff
changeset
|
255 |
] |
ee3426730cfc
on sunos: link dynamic objects against libc.a for unresolved symbols.
Claus Gittinger <cg@exept.de>
parents:
307
diff
changeset
|
256 |
]. |
321
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
257 |
|
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
258 |
"/ default libraryPath where shared objects are expected |
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
259 |
"/ when a sharedObject load requires other objects to be loaded. |
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
260 |
"/ Only req'd for aix. |
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
261 |
"/ For more compatibility with ELF systems, look for a shell variable |
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
262 |
"/ named LD_LIBRARY_PATH, and - if present - take that instead if a default. |
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
263 |
"/ Can (should) be set in the smalltalk.rc file. |
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
264 |
|
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
265 |
systemType = 'aix' ifTrue:[ |
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
266 |
LibPath := OperatingSystem getEnvironment:'LD_LIBRARY_PATH'. |
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
267 |
LibPath isNil ifTrue:[ |
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
268 |
LibPath := '.:/usr/local/smalltalk/lib:/usr/local/lib:/usr/lib:/lib'. |
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
269 |
] |
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
270 |
]. |
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
271 |
|
201 | 272 |
] |
107 | 273 |
|
274 |
" |
|
275 |
ObjectFileLoader initialize |
|
276 |
" |
|
316
ee3426730cfc
on sunos: link dynamic objects against libc.a for unresolved symbols.
Claus Gittinger <cg@exept.de>
parents:
307
diff
changeset
|
277 |
|
317 | 278 |
"Modified: 20.7.1996 / 15:07:43 / cg" |
0 | 279 |
! |
280 |
||
141 | 281 |
lastError |
282 |
^ LastError |
|
283 |
! |
|
284 |
||
321
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
285 |
libPath |
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
286 |
"see comment in #libPath:" |
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
287 |
|
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
288 |
^ LibPath |
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
289 |
! |
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
290 |
|
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
291 |
libPath:aSharedLibraryPath |
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
292 |
"set the pathnames of directories, where other shared objects |
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
293 |
are searched, in case a loaded module requires another module shared |
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
294 |
library object to be loaded. |
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
295 |
Currently, this is only required to be set for AIX systems; |
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
296 |
ELF based linux and solaris systems specify the libPath in the |
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
297 |
LD_LIBRARY_PATH environment variable." |
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
298 |
|
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
299 |
LibPath := aSharedLibraryPath |
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
300 |
|
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
301 |
" |
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
302 |
ObjectFileLoader libPath:'.:/usr/lib:/usr/local/lib' |
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
303 |
" |
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
304 |
! |
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
305 |
|
141 | 306 |
linkErrorMessage |
307 |
^ LinkErrorMessage |
|
308 |
! |
|
309 |
||
310 |
searchedLibraries |
|
311 |
"see comment in #searchedLibraries:" |
|
312 |
||
313 |
^ SearchedLibraries |
|
314 |
! |
|
315 |
||
125 | 316 |
searchedLibraries:aCollectionOfArchivePathNames |
317 |
"set the pathnames of archives which are to be searched |
|
318 |
when unresolved references occur while loading in an object |
|
319 |
file. On systems which support shared libraries (all SYS5.4 based |
|
320 |
systems), this is usually not required. Instead, modules which are to |
|
321 |
be filed in (.so files) are to be prelinked with the appropriate |
|
322 |
shared libraries. The dynamic loader then cares about loading those |
|
323 |
modules (keeping track of which modules are already loaded). |
|
324 |
Only systems in which the dynamic load is done 'manually' by st/x |
|
321
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
325 |
(i.e. currently only linux and a.out-sunos) need to set this." |
125 | 326 |
|
327 |
SearchedLibraries := aCollectionOfArchivePathNames |
|
328 |
! |
|
329 |
||
0 | 330 |
verbose:aBoolean |
331 |
"turn on/off debug traces" |
|
332 |
||
10 | 333 |
Verbose := aBoolean |
0 | 334 |
|
335 |
"ObjectFileLoader verbose:true" |
|
336 |
! ! |
|
337 |
||
369 | 338 |
!ObjectFileLoader class methodsFor:'change & update'! |
291 | 339 |
|
340 |
update:something with:aParameter from:changedObject |
|
107 | 341 |
"sent, when image is saved or restarted" |
342 |
||
343 |
(something == #aboutToSnapshot) ifTrue:[ |
|
226
f0771f42256d
reloadAllObjectFiles now called explicit (its too late via ObjMem changed)
Claus Gittinger <cg@exept.de>
parents:
225
diff
changeset
|
344 |
self invalidateAndRememberAllObjectFiles |
125 | 345 |
]. |
346 |
(something == #finishedSnapshot) ifTrue:[ |
|
226
f0771f42256d
reloadAllObjectFiles now called explicit (its too late via ObjMem changed)
Claus Gittinger <cg@exept.de>
parents:
225
diff
changeset
|
347 |
self revalidateAllObjectFiles |
107 | 348 |
]. |
226
f0771f42256d
reloadAllObjectFiles now called explicit (its too late via ObjMem changed)
Claus Gittinger <cg@exept.de>
parents:
225
diff
changeset
|
349 |
"/ (something == #restarted) ifTrue:[ |
f0771f42256d
reloadAllObjectFiles now called explicit (its too late via ObjMem changed)
Claus Gittinger <cg@exept.de>
parents:
225
diff
changeset
|
350 |
"/ self reloadAllRememberedObjectFiles |
f0771f42256d
reloadAllObjectFiles now called explicit (its too late via ObjMem changed)
Claus Gittinger <cg@exept.de>
parents:
225
diff
changeset
|
351 |
"/ ]. |
125 | 352 |
|
353 |
"Modified: 5.10.1995 / 15:49:14 / claus" |
|
226
f0771f42256d
reloadAllObjectFiles now called explicit (its too late via ObjMem changed)
Claus Gittinger <cg@exept.de>
parents:
225
diff
changeset
|
354 |
"Modified: 8.3.1996 / 23:34:29 / cg" |
291 | 355 |
"Created: 21.6.1996 / 19:50:01 / cg" |
107 | 356 |
! ! |
357 |
||
369 | 358 |
!ObjectFileLoader class methodsFor:'defaults'! |
115 | 359 |
|
141 | 360 |
hasValidBinaryExtension:aFilename |
361 |
"return true, if aFilename looks ok for binary loading. |
|
362 |
This checks only the extension - not its contents. |
|
363 |
(So an attempt to load the file may fail due to format errors or unresolved symbols) |
|
364 |
This is very machine specific." |
|
365 |
||
366 |
self validBinaryExtensions do:[:ext | |
|
367 |
(aFilename endsWith:ext) ifTrue:[^ true]. |
|
368 |
]. |
|
369 |
^ false |
|
370 |
||
371 |
" |
|
372 |
ObjectFileLoader hasValidBinaryExtension:'foo.st' |
|
373 |
ObjectFileLoader hasValidBinaryExtension:'foo.o' |
|
374 |
ObjectFileLoader hasValidBinaryExtension:'foo.so' |
|
375 |
" |
|
376 |
! |
|
377 |
||
188 | 378 |
loadableBinaryObjectFormat |
379 |
"return a symbol describing the expected binary format |
|
380 |
for object files to be loadable. |
|
381 |
This is very machine specific." |
|
382 |
||
383 |
%{ /* NOCONTEXT */ |
|
320
54bfd6fd28b9
removed old obsolete manual loader; aix fixes
Claus Gittinger <cg@exept.de>
parents:
317
diff
changeset
|
384 |
|
188 | 385 |
#ifdef HAS_DL |
386 |
# if defined(SYSV4) || defined(ELF) |
|
387 |
RETURN ( @symbol(elf)); |
|
388 |
# endif |
|
389 |
# if defined(GNU_DL) |
|
390 |
RETURN ( @symbol(aout)); |
|
391 |
# endif |
|
392 |
# if defined(AIX_DL) |
|
393 |
RETURN ( @symbol(xcoff)); |
|
394 |
# endif |
|
395 |
# if defined(DL1_6) |
|
396 |
RETURN ( @symbol(coff)); |
|
397 |
# endif |
|
398 |
# if defined(WIN_DL) |
|
399 |
RETURN ( @symbol(dll)); |
|
400 |
# endif |
|
401 |
#endif |
|
320
54bfd6fd28b9
removed old obsolete manual loader; aix fixes
Claus Gittinger <cg@exept.de>
parents:
317
diff
changeset
|
402 |
|
188 | 403 |
%}. |
404 |
^ nil |
|
405 |
||
406 |
" |
|
407 |
ObjectFileLoader loadableBinaryObjectFormat |
|
408 |
" |
|
409 |
! |
|
410 |
||
141 | 411 |
nm:file |
403 | 412 |
"this should return a string to list the namelist of file. |
413 |
The output of the command should be one line for each symbol, |
|
414 |
formatted as: |
|
415 |
addr segment name |
|
416 |
This is parsed and read by #namesMatching:segment:in:. |
|
417 |
||
418 |
If your default nm command cannot produce this, write a little |
|
419 |
shell or awk script, to generate this and return a corresponding command |
|
420 |
below." |
|
141 | 421 |
|
422 |
|os| |
|
423 |
||
424 |
os := OperatingSystem getSystemType. |
|
425 |
(os = 'iris') ifTrue:[ |
|
403 | 426 |
^ 'nm -B ' , file |
427 |
]. |
|
428 |
(os = 'solaris') ifTrue:[ |
|
429 |
^ 'nm -p ' , file |
|
141 | 430 |
]. |
431 |
^ 'nm ' , file |
|
403 | 432 |
|
433 |
"Modified: 30.10.1996 / 13:34:56 / cg" |
|
141 | 434 |
! |
435 |
||
115 | 436 |
sharedLibraryExtension |
437 |
"return a fileName extension used for dynamic loadable objects. |
|
438 |
This is very machine specific." |
|
439 |
||
440 |
|os| |
|
441 |
||
442 |
os := OperatingSystem getSystemType. |
|
125 | 443 |
(os = 'sys5_4') ifTrue:[^ '.so']. |
115 | 444 |
(os = 'iris') ifTrue:[^ '.so']. |
300
e351220115f5
added support to reload function object modules
Claus Gittinger <cg@exept.de>
parents:
291
diff
changeset
|
445 |
(os = 'linux') ifTrue:[ |
e351220115f5
added support to reload function object modules
Claus Gittinger <cg@exept.de>
parents:
291
diff
changeset
|
446 |
self loadableBinaryObjectFormat == #aout ifTrue:[ |
e351220115f5
added support to reload function object modules
Claus Gittinger <cg@exept.de>
parents:
291
diff
changeset
|
447 |
^ '.o' |
e351220115f5
added support to reload function object modules
Claus Gittinger <cg@exept.de>
parents:
291
diff
changeset
|
448 |
]. |
e351220115f5
added support to reload function object modules
Claus Gittinger <cg@exept.de>
parents:
291
diff
changeset
|
449 |
^ '.so' |
e351220115f5
added support to reload function object modules
Claus Gittinger <cg@exept.de>
parents:
291
diff
changeset
|
450 |
]. |
404 | 451 |
(os = 'solaris') ifTrue:[^ '.so' ]. |
115 | 452 |
(os = 'aix') ifTrue:[^ '.so']. |
453 |
(os = 'hpux') ifTrue:[^ '.sl']. |
|
180 | 454 |
(os = 'win32') ifTrue:[^ '.dll']. |
115 | 455 |
(os = 'os2') ifTrue:[^ '.dll']. |
119 | 456 |
|
457 |
"/ mhmh what is a useful default ? |
|
458 |
||
459 |
^ '.o' |
|
300
e351220115f5
added support to reload function object modules
Claus Gittinger <cg@exept.de>
parents:
291
diff
changeset
|
460 |
|
404 | 461 |
"Modified: 30.10.1996 / 14:07:50 / cg" |
115 | 462 |
! |
0 | 463 |
|
134
d93682ca90a1
more queries for valid objectfilenames
Claus Gittinger <cg@exept.de>
parents:
130
diff
changeset
|
464 |
validBinaryExtensions |
d93682ca90a1
more queries for valid objectfilenames
Claus Gittinger <cg@exept.de>
parents:
130
diff
changeset
|
465 |
"return a collection of valid filename extension for binary files. |
d93682ca90a1
more queries for valid objectfilenames
Claus Gittinger <cg@exept.de>
parents:
130
diff
changeset
|
466 |
This is very machine specific." |
d93682ca90a1
more queries for valid objectfilenames
Claus Gittinger <cg@exept.de>
parents:
130
diff
changeset
|
467 |
|
d93682ca90a1
more queries for valid objectfilenames
Claus Gittinger <cg@exept.de>
parents:
130
diff
changeset
|
468 |
|os| |
d93682ca90a1
more queries for valid objectfilenames
Claus Gittinger <cg@exept.de>
parents:
130
diff
changeset
|
469 |
|
d93682ca90a1
more queries for valid objectfilenames
Claus Gittinger <cg@exept.de>
parents:
130
diff
changeset
|
470 |
os := OperatingSystem getSystemType. |
d93682ca90a1
more queries for valid objectfilenames
Claus Gittinger <cg@exept.de>
parents:
130
diff
changeset
|
471 |
(os = 'sys5_4') ifTrue:[^ #('.so') ]. |
d93682ca90a1
more queries for valid objectfilenames
Claus Gittinger <cg@exept.de>
parents:
130
diff
changeset
|
472 |
(os = 'iris') ifTrue:[^ #('.so') ]. |
403 | 473 |
(os = 'solaris') ifTrue:[^ #('.so') ]. |
134
d93682ca90a1
more queries for valid objectfilenames
Claus Gittinger <cg@exept.de>
parents:
130
diff
changeset
|
474 |
(os = 'linux') ifTrue:[^ #('.o' '.obj' '.so') ]. |
d93682ca90a1
more queries for valid objectfilenames
Claus Gittinger <cg@exept.de>
parents:
130
diff
changeset
|
475 |
(os = 'aix') ifTrue:[^ #('.o' '.so') ]. |
d93682ca90a1
more queries for valid objectfilenames
Claus Gittinger <cg@exept.de>
parents:
130
diff
changeset
|
476 |
(os = 'hpux') ifTrue:[^ #('.o' '.sl') ]. |
180 | 477 |
(os = 'win32') ifTrue:[^ #('.dll') ]. |
134
d93682ca90a1
more queries for valid objectfilenames
Claus Gittinger <cg@exept.de>
parents:
130
diff
changeset
|
478 |
(os = 'os2') ifTrue:[^ #('.dll') ]. |
d93682ca90a1
more queries for valid objectfilenames
Claus Gittinger <cg@exept.de>
parents:
130
diff
changeset
|
479 |
|
d93682ca90a1
more queries for valid objectfilenames
Claus Gittinger <cg@exept.de>
parents:
130
diff
changeset
|
480 |
"/ mhmh what is a useful default ? |
d93682ca90a1
more queries for valid objectfilenames
Claus Gittinger <cg@exept.de>
parents:
130
diff
changeset
|
481 |
|
d93682ca90a1
more queries for valid objectfilenames
Claus Gittinger <cg@exept.de>
parents:
130
diff
changeset
|
482 |
^ #('.o') |
d93682ca90a1
more queries for valid objectfilenames
Claus Gittinger <cg@exept.de>
parents:
130
diff
changeset
|
483 |
|
d93682ca90a1
more queries for valid objectfilenames
Claus Gittinger <cg@exept.de>
parents:
130
diff
changeset
|
484 |
" |
d93682ca90a1
more queries for valid objectfilenames
Claus Gittinger <cg@exept.de>
parents:
130
diff
changeset
|
485 |
ObjectFileLoader validBinaryExtensions |
d93682ca90a1
more queries for valid objectfilenames
Claus Gittinger <cg@exept.de>
parents:
130
diff
changeset
|
486 |
" |
403 | 487 |
|
488 |
"Modified: 30.10.1996 / 13:26:38 / cg" |
|
141 | 489 |
! ! |
490 |
||
369 | 491 |
!ObjectFileLoader class methodsFor:'dynamic class loading'! |
141 | 492 |
|
493 |
loadCPlusPlusObjectFile:aFileName |
|
494 |
"load a c++ object file (.o-file) into the image" |
|
495 |
||
496 |
|handle initAddr list| |
|
497 |
||
498 |
handle := self loadDynamicObject:aFileName. |
|
499 |
handle isNil ifTrue:[ |
|
272 | 500 |
Transcript showCR:('loadDynamic: ',aFileName,' failed.'). |
501 |
^ nil |
|
141 | 502 |
]. |
503 |
||
504 |
list := self namesMatching:'__GLOBAL_$I*' segment:'[tT]' in:aFileName. |
|
505 |
list size == 1 ifTrue:[ |
|
506 |
"/ (self isCPlusPlusObject:handle) ifTrue:[ |
|
272 | 507 |
Verbose ifTrue:[ |
508 |
'a c++ object file' infoPrintNL. |
|
509 |
]. |
|
510 |
" |
|
511 |
what I would like to get is the CTOR_LIST, |
|
512 |
and call each function. |
|
513 |
But dld cannot (currently) handle SET-type symbols, therefore |
|
514 |
we search (using nm) for all __GLOBAL_$I* syms, get their values |
|
515 |
and call them each |
|
516 |
" |
|
141 | 517 |
"/ list := self namesMatching:'__GLOBAL_$I*' segment:'[tT]' in:aFileName. |
518 |
||
519 |
"/ initAddr := self getFunction:'__CTOR_LIST__' from:handle. |
|
520 |
"/ Verbose ifTrue:[ |
|
521 |
"/ ('calling CTORs at:' , (initAddr printStringRadix:16)) infoPrintNL |
|
522 |
"/ ]. |
|
523 |
||
272 | 524 |
initAddr := self getFunction:list first from:handle. |
525 |
initAddr isNil ifTrue:[ |
|
526 |
" |
|
527 |
try with added underscore |
|
528 |
" |
|
529 |
initAddr := self getFunction:('_' , list first) from:handle. |
|
530 |
]. |
|
531 |
(initAddr isNil and:[list first startsWith:'_']) ifTrue:[ |
|
532 |
" |
|
533 |
try with removed underscore |
|
534 |
" |
|
535 |
initAddr := self getFunction:(list first copyFrom:2) from:handle. |
|
536 |
]. |
|
537 |
initAddr isNil ifTrue:[ |
|
538 |
Verbose ifTrue:[ |
|
539 |
('no CTOR-func found (' , list first , ')') infoPrintNL. |
|
540 |
]. |
|
541 |
self unloadDynamicObject:aFileName. |
|
542 |
^ nil |
|
543 |
]. |
|
544 |
Verbose ifTrue:[ |
|
545 |
('calling CTORs at:' , (initAddr printStringRadix:16)) infoPrintNL |
|
546 |
]. |
|
547 |
self callInitFunctionAt:initAddr |
|
548 |
specialInit:false |
|
549 |
forceOld:false |
|
550 |
interruptable:false |
|
551 |
argument:0 |
|
552 |
identifyAs:nil |
|
553 |
returnsObject:false. |
|
554 |
||
555 |
Verbose ifTrue:[ |
|
556 |
'done with CTORs.' infoPrintNL |
|
557 |
]. |
|
558 |
||
559 |
" |
|
560 |
cannot create a CPlusPlus class automatically (there could be more than |
|
561 |
one classes in it too ...) |
|
562 |
" |
|
563 |
^ handle |
|
141 | 564 |
]. |
565 |
||
566 |
||
567 |
Verbose ifTrue:[ |
|
272 | 568 |
'unknown object file' infoPrintNL |
141 | 569 |
]. |
570 |
self unloadDynamicObject:aFileName. |
|
571 |
^ nil |
|
272 | 572 |
|
573 |
"Modified: 18.5.1996 / 15:43:50 / cg" |
|
141 | 574 |
! |
575 |
||
576 |
loadClass:aClassName fromObjectFile:aFileName |
|
577 |
"load a compiled class (.o-file) into the image" |
|
578 |
||
365
22c85186e799
Fix misspelled "interrest" to "interest".
Stefan Vogel <sv@exept.de>
parents:
346
diff
changeset
|
579 |
|handle initAddr symName newClass moreHandles info status |
141 | 580 |
otherClass knownToBeOk| |
581 |
||
582 |
handle := self loadDynamicObject:aFileName. |
|
583 |
handle isNil ifTrue:[ |
|
272 | 584 |
Transcript showCR:('loadDynamic: ', aFileName,' failed.'). |
585 |
^ nil |
|
141 | 586 |
]. |
587 |
||
588 |
" |
|
589 |
get the Init-function; let the class install itself |
|
590 |
" |
|
591 |
symName := '_' , aClassName , '_Init'. |
|
592 |
initAddr := self getFunction:symName from:handle. |
|
593 |
initAddr isNil ifTrue:[ |
|
272 | 594 |
"try with added underscore" |
595 |
symName := '__' , aClassName , '_Init'. |
|
596 |
initAddr := self getFunction:symName from:handle. |
|
141 | 597 |
]. |
598 |
||
599 |
knownToBeOk := true. |
|
600 |
||
601 |
"/ knownToBeOk ifFalse:[ |
|
365
22c85186e799
Fix misspelled "interrest" to "interest".
Stefan Vogel <sv@exept.de>
parents:
346
diff
changeset
|
602 |
"/ |list| |
22c85186e799
Fix misspelled "interrest" to "interest".
Stefan Vogel <sv@exept.de>
parents:
346
diff
changeset
|
603 |
"/ |
141 | 604 |
"/ Verbose ifTrue:[ |
605 |
"/ 'looking for undefs ...' infoPrintNL. |
|
606 |
"/ ]. |
|
607 |
"/ |
|
608 |
"/ " |
|
609 |
"/ if there are any undefined symbols, we may have to load more |
|
610 |
"/ files (libs, other modules) |
|
611 |
"/ " |
|
612 |
"/ list := self getListOfUndefinedSymbolsFrom:handle. |
|
613 |
"/ list notNil ifTrue:[ |
|
614 |
"/ moreHandles := self loadModulesFromListOfUndefined:list. |
|
615 |
"/ |
|
616 |
"/ " |
|
617 |
"/ now, try again |
|
618 |
"/ " |
|
619 |
"/ symName := '_' , aClassName , '_Init'. |
|
620 |
"/ initAddr := self getFunction:symName from:handle. |
|
621 |
"/ initAddr isNil ifTrue:[ |
|
622 |
"/ "try with added underscore" |
|
623 |
"/ symName := '__' , aClassName , '_Init'. |
|
624 |
"/ initAddr := self getFunction:symName from:handle. |
|
625 |
"/ ]. |
|
626 |
"/ ] |
|
627 |
"/ ]. |
|
628 |
||
629 |
initAddr notNil ifTrue:[ |
|
272 | 630 |
Verbose ifTrue:[ |
631 |
('calling init at: ' , (initAddr printStringRadix:16)) infoPrintNL. |
|
632 |
]. |
|
633 |
info := self performModuleInitAt:initAddr for:aClassName identifyAs:handle. |
|
634 |
status := info at:1. |
|
635 |
" |
|
636 |
if any classes are missing ... |
|
637 |
" |
|
638 |
(status == #missingClass) ifTrue:[ |
|
639 |
" |
|
640 |
... and we are loading a module ... |
|
641 |
" |
|
642 |
Transcript showCR:'try for missing class in same object ...'. |
|
643 |
Verbose ifTrue:[ |
|
644 |
'try for missing class:' infoPrint. (info at:2) infoPrintNL. |
|
645 |
]. |
|
646 |
otherClass := self loadClass:(info at:2) fromObjectFile:aFileName. |
|
647 |
otherClass notNil ifTrue:[ |
|
648 |
" |
|
649 |
try again ... |
|
650 |
" |
|
651 |
Transcript showCR:'missing class is here; try again ...'. |
|
652 |
info := self performModuleInitAt:initAddr for:aClassName identifyAs:handle. |
|
653 |
status := info at:1. |
|
654 |
] |
|
655 |
]. |
|
656 |
||
657 |
Verbose ifTrue:[ |
|
658 |
'done init status=' infoPrint. info infoPrintNL. |
|
659 |
]. |
|
660 |
(status == #unregisteredSuperclass) ifTrue:[ |
|
661 |
Transcript showCR:'superclass is not registered'. |
|
662 |
]. |
|
663 |
||
664 |
(Symbol hasInterned:aClassName) ifTrue:[ |
|
665 |
newClass := Smalltalk at:aClassName asSymbol ifAbsent:[nil]. |
|
666 |
Verbose ifTrue:[ |
|
667 |
'newClass is: ' infoPrint. newClass infoPrintNL |
|
668 |
]. |
|
669 |
newClass notNil ifTrue:[ |
|
670 |
Verbose ifTrue:[ |
|
671 |
'initialize newClass ...' infoPrintNL |
|
672 |
]. |
|
673 |
newClass initialize. |
|
674 |
"force cache flush" |
|
675 |
Smalltalk at:aClassName asSymbol put:newClass. |
|
676 |
Smalltalk isInitialized ifTrue:[ |
|
677 |
Smalltalk changed. |
|
678 |
] |
|
679 |
]. |
|
680 |
] ifFalse:[ |
|
681 |
'LOADER: class ' errorPrint. aClassName errorPrint. |
|
682 |
' did not define itself' errorPrintNL |
|
683 |
" |
|
684 |
do not unload - could have installed other classes/methods ... |
|
685 |
" |
|
686 |
]. |
|
687 |
^ newClass |
|
141 | 688 |
]. |
689 |
||
690 |
Verbose ifTrue:[ |
|
272 | 691 |
('no symbol: ', symName,' in ',aFileName) infoPrintNL. |
141 | 692 |
]. |
693 |
||
694 |
" |
|
695 |
unload |
|
696 |
" |
|
697 |
Verbose ifTrue:[ |
|
272 | 698 |
'unloading due to init failure:' infoPrint. handle pathName infoPrintNL. |
141 | 699 |
]. |
700 |
||
701 |
moreHandles notNil ifTrue:[ |
|
272 | 702 |
moreHandles do:[:aHandle | |
703 |
Verbose ifTrue:[ |
|
704 |
('unloading: ', aHandle printString) infoPrintNL. |
|
705 |
]. |
|
706 |
self unloadDynamicObject:handle. |
|
707 |
] |
|
141 | 708 |
]. |
709 |
||
710 |
Verbose ifTrue:[ |
|
272 | 711 |
('unloading: ', handle printString) infoPrintNL. |
134
d93682ca90a1
more queries for valid objectfilenames
Claus Gittinger <cg@exept.de>
parents:
130
diff
changeset
|
712 |
]. |
141 | 713 |
self unloadDynamicObject:handle. |
714 |
^ nil |
|
715 |
||
716 |
" |
|
717 |
ObjectFileLoader loadClass:'Tetris' fromObjectFile:'../clients/Tetris/Tetris.o' |
|
718 |
ObjectFileLoader loadClass:'TetrisBlock' fromObjectFile:'../clients/Tetris/TBlock.o' |
|
719 |
ObjectFileLoader loadClass:'Foo' fromObjectFile:'classList.o' |
|
720 |
" |
|
272 | 721 |
|
722 |
"Modified: 18.5.1996 / 15:45:35 / cg" |
|
141 | 723 |
! |
724 |
||
174 | 725 |
loadMethodObjectFile:aFileName |
726 |
"load an object file (.o-file) for a single method into the image; |
|
727 |
This does a slightly different initialization. |
|
728 |
Return an object handle; nil on error" |
|
729 |
||
346 | 730 |
|handle initAddr initName m| |
174 | 731 |
|
300
e351220115f5
added support to reload function object modules
Claus Gittinger <cg@exept.de>
parents:
291
diff
changeset
|
732 |
"/ |
e351220115f5
added support to reload function object modules
Claus Gittinger <cg@exept.de>
parents:
291
diff
changeset
|
733 |
"/ load the objectfile |
e351220115f5
added support to reload function object modules
Claus Gittinger <cg@exept.de>
parents:
291
diff
changeset
|
734 |
"/ |
174 | 735 |
handle := self loadDynamicObject:aFileName. |
736 |
handle isNil ifTrue:[ |
|
225 | 737 |
^ nil |
174 | 738 |
]. |
739 |
||
300
e351220115f5
added support to reload function object modules
Claus Gittinger <cg@exept.de>
parents:
291
diff
changeset
|
740 |
"/ |
e351220115f5
added support to reload function object modules
Claus Gittinger <cg@exept.de>
parents:
291
diff
changeset
|
741 |
"/ find the entry function |
e351220115f5
added support to reload function object modules
Claus Gittinger <cg@exept.de>
parents:
291
diff
changeset
|
742 |
"/ |
e351220115f5
added support to reload function object modules
Claus Gittinger <cg@exept.de>
parents:
291
diff
changeset
|
743 |
initName := aFileName asFilename withoutSuffix baseName. |
174 | 744 |
|
745 |
initAddr := self getFunction:'__' , initName , '_Init' from:handle. |
|
746 |
initAddr isNil ifTrue:[ |
|
225 | 747 |
initAddr := ObjectFileLoader getFunction:'_' , initName , '_Init' from:handle. |
748 |
initAddr isNil ifTrue:[ |
|
749 |
(self getListOfUndefinedSymbolsFrom:handle) size > 0 ifTrue:[ |
|
750 |
self listUndefinedSymbolsIn:handle. |
|
751 |
'LOADER: undefined symbols in primitive code' infoPrintNL. |
|
752 |
] ifFalse:[ |
|
753 |
('LOADER: ' , initName , '_Init() lookup failed') errorPrintNL |
|
754 |
]. |
|
755 |
||
300
e351220115f5
added support to reload function object modules
Claus Gittinger <cg@exept.de>
parents:
291
diff
changeset
|
756 |
"/ |
e351220115f5
added support to reload function object modules
Claus Gittinger <cg@exept.de>
parents:
291
diff
changeset
|
757 |
"/ not found - unload |
e351220115f5
added support to reload function object modules
Claus Gittinger <cg@exept.de>
parents:
291
diff
changeset
|
758 |
"/ |
225 | 759 |
self unloadDynamicObject:handle. |
760 |
^ nil |
|
761 |
] |
|
174 | 762 |
]. |
763 |
||
300
e351220115f5
added support to reload function object modules
Claus Gittinger <cg@exept.de>
parents:
291
diff
changeset
|
764 |
"/ |
e351220115f5
added support to reload function object modules
Claus Gittinger <cg@exept.de>
parents:
291
diff
changeset
|
765 |
"/ call it - it returns the new method object |
e351220115f5
added support to reload function object modules
Claus Gittinger <cg@exept.de>
parents:
291
diff
changeset
|
766 |
"/ |
174 | 767 |
m := self |
225 | 768 |
callInitFunctionAt:initAddr |
769 |
specialInit:true |
|
770 |
forceOld:true |
|
771 |
interruptable:false |
|
772 |
argument:2 |
|
773 |
identifyAs:handle |
|
774 |
returnsObject:true. |
|
174 | 775 |
|
776 |
handle method:m. |
|
777 |
^ handle |
|
778 |
||
779 |
"Created: 5.12.1995 / 20:59:46 / cg" |
|
300
e351220115f5
added support to reload function object modules
Claus Gittinger <cg@exept.de>
parents:
291
diff
changeset
|
780 |
"Modified: 12.7.1996 / 13:26:41 / cg" |
174 | 781 |
! |
782 |
||
141 | 783 |
loadModulesFromListOfUndefined:list |
784 |
"try to figure out what has to be loaded to resolve symbols from list. |
|
785 |
return a list of handles of loaded objects |
|
786 |
" |
|
787 |
|inits classNames| |
|
788 |
||
789 |
inits := list select:[:symbol | symbol notNil and:[symbol endsWith:'_Init']]. |
|
790 |
inits notNil ifTrue:[ |
|
182
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
180
diff
changeset
|
791 |
classNames := inits collect:[:symbol | |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
180
diff
changeset
|
792 |
(symbol startsWith:'___') ifTrue:[ |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
180
diff
changeset
|
793 |
symbol copyFrom:4 to:(symbol size - 5) |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
180
diff
changeset
|
794 |
] ifFalse:[ |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
180
diff
changeset
|
795 |
(symbol startsWith:'__') ifTrue:[ |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
180
diff
changeset
|
796 |
symbol copyFrom:3 to:(symbol size - 5) |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
180
diff
changeset
|
797 |
] ifFalse:[ |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
180
diff
changeset
|
798 |
(symbol startsWith:'_') ifTrue:[ |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
180
diff
changeset
|
799 |
symbol copyFrom:2 to:(symbol size - 5) |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
180
diff
changeset
|
800 |
] ifFalse:[ |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
180
diff
changeset
|
801 |
symbol |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
180
diff
changeset
|
802 |
] |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
180
diff
changeset
|
803 |
] |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
180
diff
changeset
|
804 |
] |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
180
diff
changeset
|
805 |
]. |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
180
diff
changeset
|
806 |
" |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
180
diff
changeset
|
807 |
autoload those classes |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
180
diff
changeset
|
808 |
" |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
180
diff
changeset
|
809 |
classNames do:[:aClassName | |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
180
diff
changeset
|
810 |
|cls| |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
180
diff
changeset
|
811 |
|
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
180
diff
changeset
|
812 |
(cls := Smalltalk classNamed:aClassName) notNil ifTrue:[ |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
180
diff
changeset
|
813 |
'autoloading ' infoPrint. aClassName infoPrintNL. |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
180
diff
changeset
|
814 |
cls autoload |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
180
diff
changeset
|
815 |
] |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
180
diff
changeset
|
816 |
] |
141 | 817 |
]. |
818 |
^ nil |
|
174 | 819 |
|
820 |
"Modified: 17.12.1995 / 16:00:27 / cg" |
|
141 | 821 |
! |
822 |
||
823 |
loadObjectFile:aFileName |
|
824 |
"load an object file (.o-file) into the image; |
|
825 |
the class name is not needed (multiple definitions may be in the file). |
|
826 |
Return false on error, true if ok." |
|
827 |
||
346 | 828 |
|handle initAddr className initNames didInit info status |
829 |
dummyHandle msg| |
|
141 | 830 |
|
831 |
handle := self loadDynamicObject:aFileName. |
|
832 |
handle isNil ifTrue:[ |
|
272 | 833 |
Transcript showCR:('loadDynamic: ',aFileName,' failed.'). |
228
be9939d96cfe
removed a wrong debug message
Claus Gittinger <cg@exept.de>
parents:
227
diff
changeset
|
834 |
^ false |
141 | 835 |
]. |
836 |
||
837 |
didInit := false. |
|
838 |
||
839 |
"/ with dld, load may have worked, even if undefined symbols |
|
840 |
"/ are to be resolved. If thats the case, load all libraries ... |
|
841 |
||
842 |
SearchedLibraries notNil ifTrue:[ |
|
228
be9939d96cfe
removed a wrong debug message
Claus Gittinger <cg@exept.de>
parents:
227
diff
changeset
|
843 |
(self hasUndefinedSymbolsIn:handle) ifTrue:[ |
be9939d96cfe
removed a wrong debug message
Claus Gittinger <cg@exept.de>
parents:
227
diff
changeset
|
844 |
SearchedLibraries do:[:libName | |
be9939d96cfe
removed a wrong debug message
Claus Gittinger <cg@exept.de>
parents:
227
diff
changeset
|
845 |
(self hasUndefinedSymbolsIn:handle) ifTrue:[ |
272 | 846 |
Transcript showCR:' ... trying ' , libName , ' to resolve undefined symbols ...'. |
228
be9939d96cfe
removed a wrong debug message
Claus Gittinger <cg@exept.de>
parents:
227
diff
changeset
|
847 |
dummyHandle := Array new:4. |
be9939d96cfe
removed a wrong debug message
Claus Gittinger <cg@exept.de>
parents:
227
diff
changeset
|
848 |
dummyHandle := self primLoadDynamicObject:libName into:dummyHandle. |
be9939d96cfe
removed a wrong debug message
Claus Gittinger <cg@exept.de>
parents:
227
diff
changeset
|
849 |
"/ dummyHandle isNil ifTrue:[ |
272 | 850 |
"/ Transcript showCR:' ... load of library ' , libName , ' failed.'. |
228
be9939d96cfe
removed a wrong debug message
Claus Gittinger <cg@exept.de>
parents:
227
diff
changeset
|
851 |
"/ ] |
be9939d96cfe
removed a wrong debug message
Claus Gittinger <cg@exept.de>
parents:
227
diff
changeset
|
852 |
] |
be9939d96cfe
removed a wrong debug message
Claus Gittinger <cg@exept.de>
parents:
227
diff
changeset
|
853 |
]. |
be9939d96cfe
removed a wrong debug message
Claus Gittinger <cg@exept.de>
parents:
227
diff
changeset
|
854 |
(self hasUndefinedSymbolsIn:handle) isNil ifTrue:[ |
272 | 855 |
Transcript showCR:('loadDynamic: still undefined symbols in ',aFileName,'.'). |
228
be9939d96cfe
removed a wrong debug message
Claus Gittinger <cg@exept.de>
parents:
227
diff
changeset
|
856 |
]. |
be9939d96cfe
removed a wrong debug message
Claus Gittinger <cg@exept.de>
parents:
227
diff
changeset
|
857 |
] |
141 | 858 |
]. |
859 |
||
860 |
" |
|
307
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
861 |
first, expect the classes-name to be the fileNames-baseName |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
862 |
(if its not, it may be a method or function module; |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
863 |
in this case, the Init function is supposed to use that naming |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
864 |
scheme as well) |
141 | 865 |
" |
307
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
866 |
className := self initFunctionBasenameForFile:aFileName. |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
867 |
|
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
868 |
"/ |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
869 |
"/ look for explicit init (xxx_Init) function |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
870 |
"/ This is used in ST object files |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
871 |
"/ |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
872 |
initAddr := self findInitFunction:className in:handle. |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
873 |
|
141 | 874 |
initAddr notNil ifTrue:[ |
228
be9939d96cfe
removed a wrong debug message
Claus Gittinger <cg@exept.de>
parents:
227
diff
changeset
|
875 |
Verbose ifTrue:[ |
be9939d96cfe
removed a wrong debug message
Claus Gittinger <cg@exept.de>
parents:
227
diff
changeset
|
876 |
('calling init at:' , (initAddr printStringRadix:16)) infoPrintNL. |
be9939d96cfe
removed a wrong debug message
Claus Gittinger <cg@exept.de>
parents:
227
diff
changeset
|
877 |
]. |
be9939d96cfe
removed a wrong debug message
Claus Gittinger <cg@exept.de>
parents:
227
diff
changeset
|
878 |
info := self performModuleInitAt:initAddr for:nil identifyAs:handle. |
be9939d96cfe
removed a wrong debug message
Claus Gittinger <cg@exept.de>
parents:
227
diff
changeset
|
879 |
status := info at:1. |
be9939d96cfe
removed a wrong debug message
Claus Gittinger <cg@exept.de>
parents:
227
diff
changeset
|
880 |
status == #ok ifTrue:[ |
be9939d96cfe
removed a wrong debug message
Claus Gittinger <cg@exept.de>
parents:
227
diff
changeset
|
881 |
didInit := true. |
be9939d96cfe
removed a wrong debug message
Claus Gittinger <cg@exept.de>
parents:
227
diff
changeset
|
882 |
] |
141 | 883 |
] ifFalse:[ |
307
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
884 |
"/ |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
885 |
"/ look for explicit C-init (xxx__Init) function |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
886 |
"/ This is used in C object files |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
887 |
"/ |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
888 |
initAddr := self findFunction:className suffix:'__Init' in:handle. |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
889 |
initAddr notNil ifTrue:[ |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
890 |
(self callInitFunctionAt:initAddr |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
891 |
specialInit:false |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
892 |
forceOld:true |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
893 |
interruptable:false |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
894 |
argument:0 |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
895 |
identifyAs:handle |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
896 |
returnsObject:false) < 0 ifTrue:[ |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
897 |
|
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
898 |
Verbose ifTrue:[ |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
899 |
'init function return failure ... unload' infoPrintNL. |
228
be9939d96cfe
removed a wrong debug message
Claus Gittinger <cg@exept.de>
parents:
227
diff
changeset
|
900 |
]. |
307
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
901 |
status := #initFailed. |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
902 |
] ifFalse:[ |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
903 |
didInit := true |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
904 |
] |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
905 |
] ifFalse:[ |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
906 |
" |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
907 |
look for any init-function(s); call them all |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
908 |
" |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
909 |
Verbose ifTrue:[ |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
910 |
'no good init functions found; looking for candidates ...' infoPrintNL. |
228
be9939d96cfe
removed a wrong debug message
Claus Gittinger <cg@exept.de>
parents:
227
diff
changeset
|
911 |
]. |
307
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
912 |
initNames := self namesMatching:'*_Init' segment:'[tT]' in:aFileName. |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
913 |
initNames notNil ifTrue:[ |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
914 |
initNames do:[:aName | |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
915 |
initAddr := self getFunction:aName from:handle. |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
916 |
initAddr isNil ifTrue:[ |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
917 |
(aName startsWith:'_') ifTrue:[ |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
918 |
initAddr := self getFunction:(aName copyFrom:2) from:handle. |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
919 |
]. |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
920 |
]. |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
921 |
initAddr isNil ifTrue:[ |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
922 |
Transcript showCR:('no symbol: ',aName,' in ',aFileName). |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
923 |
] ifFalse:[ |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
924 |
Verbose ifTrue:[ |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
925 |
('calling init at:' , (initAddr printStringRadix:16)) infoPrintNL |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
926 |
]. |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
927 |
self performModuleInitAt:initAddr for:nil identifyAs:handle. |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
928 |
didInit := true. |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
929 |
] |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
930 |
]. |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
931 |
]. |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
932 |
] |
141 | 933 |
]. |
934 |
||
935 |
didInit ifFalse:[ |
|
228
be9939d96cfe
removed a wrong debug message
Claus Gittinger <cg@exept.de>
parents:
227
diff
changeset
|
936 |
status == #registrationFailed ifTrue:[ |
272 | 937 |
Transcript showCR:'incompatible object (recompile without commonSymbols ?)' |
228
be9939d96cfe
removed a wrong debug message
Claus Gittinger <cg@exept.de>
parents:
227
diff
changeset
|
938 |
]. |
307
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
939 |
status ~~ #initFailed ifTrue:[ |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
940 |
self listUndefinedSymbolsIn:handle. |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
941 |
]. |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
942 |
|
228
be9939d96cfe
removed a wrong debug message
Claus Gittinger <cg@exept.de>
parents:
227
diff
changeset
|
943 |
self unloadDynamicObject:handle. |
252
b5612db98c13
better error message when attempting to load a sepInitCode object
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
944 |
|
307
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
945 |
status == #initFailed ifTrue:[ |
398 | 946 |
msg := 'module not loaded (init function signalled failure).' |
252
b5612db98c13
better error message when attempting to load a sepInitCode object
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
947 |
] ifFalse:[ |
307
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
948 |
(self namesMatching:'*__sepInitCode__*' segment:'[tT]' in:aFileName) notNil ifTrue:[ |
398 | 949 |
msg := 'module not loaded (no _Init entry - looks like an incomplete sepInitCode object).' |
307
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
950 |
] ifFalse:[ |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
951 |
msg := 'module not loaded (no _Init entry in object file ?).' |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
952 |
]. |
398 | 953 |
]. |
954 |
Transcript showCR:msg |
|
141 | 955 |
]. |
956 |
||
157
d7f68808a258
reload objects in the previous order
Claus Gittinger <cg@exept.de>
parents:
156
diff
changeset
|
957 |
Smalltalk isInitialized ifTrue:[ |
228
be9939d96cfe
removed a wrong debug message
Claus Gittinger <cg@exept.de>
parents:
227
diff
changeset
|
958 |
" |
be9939d96cfe
removed a wrong debug message
Claus Gittinger <cg@exept.de>
parents:
227
diff
changeset
|
959 |
really dont know, if it has changed ... |
be9939d96cfe
removed a wrong debug message
Claus Gittinger <cg@exept.de>
parents:
227
diff
changeset
|
960 |
" |
be9939d96cfe
removed a wrong debug message
Claus Gittinger <cg@exept.de>
parents:
227
diff
changeset
|
961 |
Smalltalk changed. |
157
d7f68808a258
reload objects in the previous order
Claus Gittinger <cg@exept.de>
parents:
156
diff
changeset
|
962 |
]. |
141 | 963 |
^ true |
228
be9939d96cfe
removed a wrong debug message
Claus Gittinger <cg@exept.de>
parents:
227
diff
changeset
|
964 |
|
398 | 965 |
"Modified: 24.10.1996 / 10:19:25 / cg" |
141 | 966 |
! |
967 |
||
968 |
unloadAllObsoleteObjectFiles |
|
969 |
"unload all dynamically loaded object files for which the classes/method |
|
970 |
has been already garbage collected." |
|
971 |
||
972 |
LoadedObjects notNil ifTrue:[ |
|
151
7f46f760ba45
automatically unload modules for garbage collected methods/classes
Claus Gittinger <cg@exept.de>
parents:
149
diff
changeset
|
973 |
LoadedObjects keys copy do:[:name | |
7f46f760ba45
automatically unload modules for garbage collected methods/classes
Claus Gittinger <cg@exept.de>
parents:
149
diff
changeset
|
974 |
|handle| |
7f46f760ba45
automatically unload modules for garbage collected methods/classes
Claus Gittinger <cg@exept.de>
parents:
149
diff
changeset
|
975 |
|
7f46f760ba45
automatically unload modules for garbage collected methods/classes
Claus Gittinger <cg@exept.de>
parents:
149
diff
changeset
|
976 |
handle := LoadedObjects at:name ifAbsent:nil. |
7f46f760ba45
automatically unload modules for garbage collected methods/classes
Claus Gittinger <cg@exept.de>
parents:
149
diff
changeset
|
977 |
(handle notNil and:[handle isObsolete]) ifTrue:[ |
141 | 978 |
self unloadObjectFile:name |
151
7f46f760ba45
automatically unload modules for garbage collected methods/classes
Claus Gittinger <cg@exept.de>
parents:
149
diff
changeset
|
979 |
] |
141 | 980 |
] |
981 |
]. |
|
982 |
||
983 |
" |
|
984 |
ObjectFileLoader unloadAllObsoleteObjectFiles |
|
134
d93682ca90a1
more queries for valid objectfilenames
Claus Gittinger <cg@exept.de>
parents:
130
diff
changeset
|
985 |
" |
151
7f46f760ba45
automatically unload modules for garbage collected methods/classes
Claus Gittinger <cg@exept.de>
parents:
149
diff
changeset
|
986 |
|
7f46f760ba45
automatically unload modules for garbage collected methods/classes
Claus Gittinger <cg@exept.de>
parents:
149
diff
changeset
|
987 |
"Modified: 5.12.1995 / 18:16:52 / cg" |
134
d93682ca90a1
more queries for valid objectfilenames
Claus Gittinger <cg@exept.de>
parents:
130
diff
changeset
|
988 |
! |
d93682ca90a1
more queries for valid objectfilenames
Claus Gittinger <cg@exept.de>
parents:
130
diff
changeset
|
989 |
|
141 | 990 |
unloadObjectFile:aFileName |
991 |
"unload an object file (.o-file) from the image. |
|
992 |
DANGER ALERT: currently, you have to make sure that no references to |
|
993 |
objects of this module exist - in future versions, the system will keep |
|
994 |
track of these. For now, use at your own risk. |
|
995 |
(especially critical are blocks-functions)." |
|
996 |
||
997 |
|handle| |
|
998 |
||
999 |
LoadedObjects notNil ifTrue:[ |
|
153 | 1000 |
handle := LoadedObjects at:aFileName ifAbsent:nil |
141 | 1001 |
]. |
1002 |
handle isNil ifTrue:[ |
|
153 | 1003 |
'OBJFLOADER: oops file to be unloaded was not loaded dynamically (', aFileName , ')'. |
141 | 1004 |
^ self |
1005 |
]. |
|
1006 |
||
1007 |
"/ call the modules deInit-function ... |
|
1008 |
||
1009 |
"/ unload ... |
|
1010 |
||
1011 |
self unloadDynamicObject:handle |
|
1012 |
! ! |
|
1013 |
||
369 | 1014 |
!ObjectFileLoader class methodsFor:'dynamic object access'! |
141 | 1015 |
|
307
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
1016 |
findFunction:functionName suffix:suffix in:handle |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
1017 |
"look for the init function and returns its address" |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
1018 |
|
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
1019 |
|initAddr className| |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
1020 |
|
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
1021 |
" |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
1022 |
look for explicit init function |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
1023 |
" |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
1024 |
initAddr := self getFunction:(functionName , suffix) from:handle. |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
1025 |
initAddr notNil ifTrue:[^ initAddr]. |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
1026 |
|
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
1027 |
initAddr := self getFunction:('_' , functionName , suffix) from:handle. |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
1028 |
initAddr notNil ifTrue:[^ initAddr]. |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
1029 |
|
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
1030 |
"/ |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
1031 |
"/ special for broken ultrix nlist |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
1032 |
"/ (will not find symbol with single underscore) |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
1033 |
"/ workaround: add another underscore and retry |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
1034 |
"/ |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
1035 |
initAddr := self getFunction:('__' , functionName , suffix) from:handle. |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
1036 |
initAddr notNil ifTrue:[^ initAddr]. |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
1037 |
|
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
1038 |
" |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
1039 |
look for reverse abbreviation |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
1040 |
" |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
1041 |
className := Smalltalk classNameForFile:functionName. |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
1042 |
className notNil ifTrue:[ |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
1043 |
initAddr := self getFunction:(className , suffix) from:handle. |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
1044 |
initAddr notNil ifTrue:[^ initAddr]. |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
1045 |
|
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
1046 |
initAddr := self getFunction:('_' , className , suffix) from:handle. |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
1047 |
]. |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
1048 |
^ initAddr |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
1049 |
|
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
1050 |
"Created: 13.7.1996 / 00:38:01 / cg" |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
1051 |
! |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
1052 |
|
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
1053 |
findInitFunction:functionName in:handle |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
1054 |
"look for the init function and returns its address" |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
1055 |
|
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
1056 |
^ self findFunction:functionName suffix:'_Init' in:handle |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
1057 |
|
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
1058 |
"Modified: 13.7.1996 / 00:38:33 / cg" |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
1059 |
! |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
1060 |
|
141 | 1061 |
getFunction:aString from:handle |
1062 |
"return the address of a function from a dynamically loaded object file. |
|
1063 |
Handle must be the one returned previously from loadDynamicObject. |
|
1064 |
Return the address of the function, or nil on any error." |
|
1065 |
||
321
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
1066 |
^ self getSymbol:aString function:true from:handle |
141 | 1067 |
! |
1068 |
||
1069 |
getListOfUndefinedSymbolsFrom:aHandle |
|
1070 |
"return a collection of undefined symbols in a dynamically loaded object file. |
|
1071 |
Handle must be the one returned previously from loadDynamicObject. |
|
1072 |
Not all systems allow an object with undefined symbols to be |
|
1073 |
loaded (actually, only dld does)." |
|
1074 |
||
1075 |
|list| |
|
1076 |
||
1077 |
%{ /* STACK: 20000 */ |
|
1078 |
#ifdef GNU_DL |
|
1079 |
void (*func)(); |
|
1080 |
unsigned long addr; |
|
1081 |
char *name; |
|
1082 |
int nMax; |
|
1083 |
char **undefNames; |
|
1084 |
||
1085 |
undefNames = dld_list_undefined_sym(); |
|
1086 |
if (dld_undefined_sym_count > 0) { |
|
1087 |
char **nm; |
|
1088 |
int index; |
|
1089 |
int count = dld_undefined_sym_count; |
|
1090 |
||
1091 |
if (count > 100) count = 100; |
|
1092 |
list = __ARRAY_NEW_INT(count); |
|
1093 |
if (list) { |
|
1094 |
nm = undefNames; |
|
1095 |
for (index = 0; index < count; index++) { |
|
1096 |
OBJ s; |
|
1097 |
||
238 | 1098 |
s = __MKSTRING(*nm); |
1099 |
__ArrayInstPtr(list)->a_element[index] = s; |
|
141 | 1100 |
__STORE(list, s); |
1101 |
nm++; |
|
1102 |
} |
|
1103 |
free(undefNames); |
|
1104 |
} |
|
1105 |
} |
|
1106 |
#endif |
|
1107 |
||
1108 |
#ifdef DL1_6 |
|
1109 |
/* |
|
1110 |
* dont know how to do it |
|
1111 |
*/ |
|
1112 |
#endif |
|
1113 |
||
1114 |
#ifdef SYSV4_DL |
|
1115 |
/* |
|
1116 |
* dont know how to do it |
|
1117 |
*/ |
|
1118 |
#endif |
|
1119 |
||
1120 |
#ifdef SUN_DL |
|
1121 |
/* |
|
1122 |
* dont know how to do it |
|
1123 |
*/ |
|
1124 |
#endif |
|
1125 |
||
1126 |
#ifdef NEXT_DL |
|
1127 |
/* |
|
1128 |
* dont know how to do it |
|
1129 |
*/ |
|
1130 |
#endif |
|
180 | 1131 |
|
1132 |
#ifdef WIN_DL |
|
1133 |
/* |
|
1134 |
* dont know how to do it |
|
1135 |
*/ |
|
1136 |
#endif |
|
1137 |
||
141 | 1138 |
%}. |
1139 |
^ list |
|
1140 |
! |
|
1141 |
||
1142 |
getSymbol:aString function:isFunction from:aHandle |
|
1143 |
"return the address of a symbol/function from a dynamically loaded object file. |
|
1144 |
Handle must be the one returned previously from loadDynamicObject. |
|
1145 |
Return the address of the symbol, or nil on any error." |
|
1146 |
||
320
54bfd6fd28b9
removed old obsolete manual loader; aix fixes
Claus Gittinger <cg@exept.de>
parents:
317
diff
changeset
|
1147 |
|sysHandle1 sysHandle2 pathName address| |
141 | 1148 |
|
1149 |
sysHandle1 := aHandle sysHandle1. |
|
1150 |
sysHandle2 := aHandle sysHandle2. |
|
320
54bfd6fd28b9
removed old obsolete manual loader; aix fixes
Claus Gittinger <cg@exept.de>
parents:
317
diff
changeset
|
1151 |
pathName := aHandle pathName. |
141 | 1152 |
|
1153 |
%{ /* STACK: 20000 */ |
|
1154 |
||
1155 |
#ifdef GNU_DL |
|
1156 |
{ |
|
1157 |
void (*func)(); |
|
1158 |
unsigned long addr; |
|
1159 |
char *name; |
|
1160 |
||
1161 |
if (__isString(aString)) { |
|
1162 |
name = (char *) __stringVal(aString); |
|
1163 |
if (isFunction == false) { |
|
1164 |
addr = dld_get_symbol(name); |
|
320
54bfd6fd28b9
removed old obsolete manual loader; aix fixes
Claus Gittinger <cg@exept.de>
parents:
317
diff
changeset
|
1165 |
if (addr) { |
54bfd6fd28b9
removed old obsolete manual loader; aix fixes
Claus Gittinger <cg@exept.de>
parents:
317
diff
changeset
|
1166 |
if (ObjectFileLoader_Verbose == true) { |
54bfd6fd28b9
removed old obsolete manual loader; aix fixes
Claus Gittinger <cg@exept.de>
parents:
317
diff
changeset
|
1167 |
printf("addr of %s = %x\n", name, addr); |
54bfd6fd28b9
removed old obsolete manual loader; aix fixes
Claus Gittinger <cg@exept.de>
parents:
317
diff
changeset
|
1168 |
} |
54bfd6fd28b9
removed old obsolete manual loader; aix fixes
Claus Gittinger <cg@exept.de>
parents:
317
diff
changeset
|
1169 |
address = __MKUINT( addr ); |
54bfd6fd28b9
removed old obsolete manual loader; aix fixes
Claus Gittinger <cg@exept.de>
parents:
317
diff
changeset
|
1170 |
} |
141 | 1171 |
} else { |
1172 |
func = (void (*) ()) dld_get_func(name); |
|
1173 |
if (func) { |
|
320
54bfd6fd28b9
removed old obsolete manual loader; aix fixes
Claus Gittinger <cg@exept.de>
parents:
317
diff
changeset
|
1174 |
if (ObjectFileLoader_Verbose == true) { |
141 | 1175 |
printf("addr of %s = %x\n", name, (INT)func); |
320
54bfd6fd28b9
removed old obsolete manual loader; aix fixes
Claus Gittinger <cg@exept.de>
parents:
317
diff
changeset
|
1176 |
} |
141 | 1177 |
if (dld_function_executable_p(name)) { |
320
54bfd6fd28b9
removed old obsolete manual loader; aix fixes
Claus Gittinger <cg@exept.de>
parents:
317
diff
changeset
|
1178 |
address = __MKUINT( (INT)func ); |
141 | 1179 |
} else { |
1180 |
char **undefNames; |
|
1181 |
char **nm; |
|
1182 |
int i; |
|
1183 |
||
1184 |
if (ObjectFileLoader_Verbose == true) { |
|
1185 |
printf ("function %s not executable\n", name); |
|
1186 |
dld_perror("not executable"); |
|
1187 |
||
1188 |
printf("undefined:\n"); |
|
1189 |
nm = undefNames = dld_list_undefined_sym(); |
|
1190 |
for (i=dld_undefined_sym_count; i; i--) { |
|
1191 |
printf(" %s\n", *nm++); |
|
1192 |
} |
|
1193 |
free(undefNames); |
|
1194 |
} |
|
1195 |
} |
|
1196 |
} else { |
|
1197 |
if (ObjectFileLoader_Verbose == true) { |
|
1198 |
printf ("function %s not found\n", name); |
|
1199 |
dld_perror("get_func"); |
|
1200 |
} |
|
1201 |
} |
|
1202 |
} |
|
1203 |
} |
|
1204 |
} |
|
1205 |
#endif /* GNU_DL */ |
|
1206 |
||
180 | 1207 |
#ifdef WIN_DL |
1208 |
{ |
|
1209 |
void *h; |
|
1210 |
void *addr; |
|
1211 |
int val; |
|
1212 |
FARPROC entry; |
|
1213 |
HMODULE handle; |
|
1214 |
||
1215 |
if (__bothSmallInteger(sysHandle1, sysHandle2)) { |
|
182
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
180
diff
changeset
|
1216 |
val = (_intVal(sysHandle2) << 16) + _intVal(sysHandle1); |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
180
diff
changeset
|
1217 |
handle = (HMODULE)(val); |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
180
diff
changeset
|
1218 |
if (__isString(aString)) { |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
180
diff
changeset
|
1219 |
if (ObjectFileLoader_Verbose == true) |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
180
diff
changeset
|
1220 |
printf("get sym <%s> handle = %x\n", __stringVal(aString), (int)handle); |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
180
diff
changeset
|
1221 |
entry = GetProcAddress(handle, (char *) __stringVal(aString)); |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
180
diff
changeset
|
1222 |
if (entry != NULL) { |
180 | 1223 |
addr = (void *)entry; |
182
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
180
diff
changeset
|
1224 |
if (ObjectFileLoader_Verbose == true) { |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
180
diff
changeset
|
1225 |
printf("GetProcAddr %s ok; addr = %x\n", __stringVal(aString), addr); |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
180
diff
changeset
|
1226 |
} |
320
54bfd6fd28b9
removed old obsolete manual loader; aix fixes
Claus Gittinger <cg@exept.de>
parents:
317
diff
changeset
|
1227 |
address = __MKUINT( (int)addr ); |
182
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
180
diff
changeset
|
1228 |
} else { |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
180
diff
changeset
|
1229 |
if (ObjectFileLoader_Verbose == true) { |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
180
diff
changeset
|
1230 |
printf("GetProcAddr %s error: %x\n", __stringVal(aString), GetLastError()); |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
180
diff
changeset
|
1231 |
} |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
180
diff
changeset
|
1232 |
} |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
180
diff
changeset
|
1233 |
} |
180 | 1234 |
} |
1235 |
} |
|
1236 |
#endif |
|
1237 |
||
141 | 1238 |
#ifdef DL1_6 |
1239 |
{ |
|
1240 |
void *h; |
|
1241 |
void *addr; |
|
1242 |
int val; |
|
1243 |
||
1244 |
if (__isString(aString)) { |
|
1245 |
if (__isString(sysHandle1)) { |
|
1246 |
if (ObjectFileLoader_Verbose == true) |
|
1247 |
printf("get sym <%s> handle = %x\n", |
|
1248 |
__stringVal(aString), __stringVal(sysHandle1)); |
|
1249 |
addr = dl_getsymbol(__stringVal(sysHandle1), __stringVal(aString)); |
|
1250 |
if (addr) { |
|
1251 |
if (ObjectFileLoader_Verbose == true) |
|
1252 |
printf("addr = %x\n", addr); |
|
320
54bfd6fd28b9
removed old obsolete manual loader; aix fixes
Claus Gittinger <cg@exept.de>
parents:
317
diff
changeset
|
1253 |
address = __MKUINT( (int)addr ); |
141 | 1254 |
} else { |
1255 |
if (ObjectFileLoader_Verbose == true) |
|
1256 |
printf("dl_getsymbol %s failed\n", __stringVal(aString)); |
|
1257 |
} |
|
1258 |
} |
|
1259 |
} |
|
1260 |
} |
|
1261 |
#endif |
|
1262 |
||
1263 |
#ifdef SYSV4_DL |
|
1264 |
{ |
|
1265 |
void *h; |
|
1266 |
void *addr; |
|
1267 |
int val; |
|
1268 |
OBJ low = sysHandle1, hi = sysHandle2; |
|
1269 |
||
1270 |
if (__bothSmallInteger(low, hi)) { |
|
1271 |
val = (_intVal(hi) << 16) + _intVal(low); |
|
1272 |
h = (void *)(val); |
|
1273 |
if (__isString(aString)) { |
|
320
54bfd6fd28b9
removed old obsolete manual loader; aix fixes
Claus Gittinger <cg@exept.de>
parents:
317
diff
changeset
|
1274 |
if (ObjectFileLoader_Verbose == true) { |
141 | 1275 |
printf("get sym <%s> handle = %x\n", __stringVal(aString), h); |
320
54bfd6fd28b9
removed old obsolete manual loader; aix fixes
Claus Gittinger <cg@exept.de>
parents:
317
diff
changeset
|
1276 |
} |
141 | 1277 |
addr = dlsym(h, (char *) __stringVal(aString)); |
1278 |
if (addr) { |
|
1279 |
if (ObjectFileLoader_Verbose == true) { |
|
1280 |
printf("dlsym %s ok; addr = %x\n", __stringVal(aString), addr); |
|
1281 |
} |
|
320
54bfd6fd28b9
removed old obsolete manual loader; aix fixes
Claus Gittinger <cg@exept.de>
parents:
317
diff
changeset
|
1282 |
address = __MKUINT( (int)addr ); |
141 | 1283 |
} else { |
1284 |
if (ObjectFileLoader_Verbose == true) { |
|
1285 |
printf("dlsym %s error: %s\n", __stringVal(aString), dlerror()); |
|
1286 |
} |
|
1287 |
} |
|
1288 |
} |
|
1289 |
} |
|
1290 |
} |
|
1291 |
#endif |
|
1292 |
||
1293 |
#ifdef AIX_DL |
|
1294 |
{ |
|
1295 |
void *h; |
|
1296 |
void *addr; |
|
1297 |
int val; |
|
1298 |
struct nlist nl[2]; |
|
1299 |
OBJ low = sysHandle1, hi = sysHandle2; |
|
321
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
1300 |
char nameBuffer[256]; |
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
1301 |
static struct funcDescriptor { |
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
1302 |
unsigned vaddr; |
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
1303 |
unsigned long2; |
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
1304 |
unsigned long3; |
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
1305 |
} descriptor; |
141 | 1306 |
|
1307 |
if (__bothSmallInteger(low, hi) |
|
320
54bfd6fd28b9
removed old obsolete manual loader; aix fixes
Claus Gittinger <cg@exept.de>
parents:
317
diff
changeset
|
1308 |
&& __isString(aString) && __isString(pathName)) { |
321
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
1309 |
val = (__intVal(hi) << 16) + __intVal(low); |
141 | 1310 |
h = (void *)(val); |
320
54bfd6fd28b9
removed old obsolete manual loader; aix fixes
Claus Gittinger <cg@exept.de>
parents:
317
diff
changeset
|
1311 |
|
54bfd6fd28b9
removed old obsolete manual loader; aix fixes
Claus Gittinger <cg@exept.de>
parents:
317
diff
changeset
|
1312 |
if (ObjectFileLoader_Verbose == true) { |
54bfd6fd28b9
removed old obsolete manual loader; aix fixes
Claus Gittinger <cg@exept.de>
parents:
317
diff
changeset
|
1313 |
printf("get sym <%s> handle = %x path= %s\n", |
54bfd6fd28b9
removed old obsolete manual loader; aix fixes
Claus Gittinger <cg@exept.de>
parents:
317
diff
changeset
|
1314 |
__stringVal(aString), h, __stringVal(pathName)); |
54bfd6fd28b9
removed old obsolete manual loader; aix fixes
Claus Gittinger <cg@exept.de>
parents:
317
diff
changeset
|
1315 |
} |
54bfd6fd28b9
removed old obsolete manual loader; aix fixes
Claus Gittinger <cg@exept.de>
parents:
317
diff
changeset
|
1316 |
|
321
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
1317 |
#define USE_ENTRY |
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
1318 |
#ifdef USE_ENTRY |
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
1319 |
/* |
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
1320 |
* only works, if the entry-function is the Init function |
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
1321 |
* (i.e. linked with -e _xxx_Init) |
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
1322 |
*/ |
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
1323 |
if (ObjectFileLoader_Verbose == true) { |
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
1324 |
printf("return handle as addr = %x\n", h); |
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
1325 |
} |
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
1326 |
address = __MKUINT( (int)(h) ); |
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
1327 |
#else |
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
1328 |
|
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
1329 |
# ifdef USE_DESCRIPTOR |
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
1330 |
if (isFunction == true) { |
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
1331 |
# else |
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
1332 |
if (0) { |
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
1333 |
# endif |
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
1334 |
nameBuffer[0] = '.'; |
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
1335 |
strcpy(nameBuffer+1, aString); |
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
1336 |
nl[0].n_name = nameBuffer; |
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
1337 |
} else { |
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
1338 |
nl[0].n_name = __stringVal(aString); |
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
1339 |
} |
320
54bfd6fd28b9
removed old obsolete manual loader; aix fixes
Claus Gittinger <cg@exept.de>
parents:
317
diff
changeset
|
1340 |
nl[1].n_name = ""; |
54bfd6fd28b9
removed old obsolete manual loader; aix fixes
Claus Gittinger <cg@exept.de>
parents:
317
diff
changeset
|
1341 |
|
54bfd6fd28b9
removed old obsolete manual loader; aix fixes
Claus Gittinger <cg@exept.de>
parents:
317
diff
changeset
|
1342 |
if (nlist(__stringVal(pathName), &nl) == -1) { |
54bfd6fd28b9
removed old obsolete manual loader; aix fixes
Claus Gittinger <cg@exept.de>
parents:
317
diff
changeset
|
1343 |
if (ObjectFileLoader_Verbose == true) { |
54bfd6fd28b9
removed old obsolete manual loader; aix fixes
Claus Gittinger <cg@exept.de>
parents:
317
diff
changeset
|
1344 |
printf("nlist error\n"); |
141 | 1345 |
} |
320
54bfd6fd28b9
removed old obsolete manual loader; aix fixes
Claus Gittinger <cg@exept.de>
parents:
317
diff
changeset
|
1346 |
} else { |
54bfd6fd28b9
removed old obsolete manual loader; aix fixes
Claus Gittinger <cg@exept.de>
parents:
317
diff
changeset
|
1347 |
addr = (void *)((unsigned)nl[0].n_value + (unsigned)h); |
54bfd6fd28b9
removed old obsolete manual loader; aix fixes
Claus Gittinger <cg@exept.de>
parents:
317
diff
changeset
|
1348 |
|
321
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
1349 |
if (isFunction == true) { |
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
1350 |
# ifdef USE_DESCRIPTOR |
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
1351 |
printf("daddr = %x\n", addr); |
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
1352 |
printf("daddr[0] = %x\n", ((long *)addr)[0]); |
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
1353 |
printf("daddr[1] = %x\n", ((long *)addr)[1]); |
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
1354 |
printf("daddr[2] = %x\n", ((long *)addr)[2]); |
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
1355 |
# endif |
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
1356 |
} |
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
1357 |
|
320
54bfd6fd28b9
removed old obsolete manual loader; aix fixes
Claus Gittinger <cg@exept.de>
parents:
317
diff
changeset
|
1358 |
if (ObjectFileLoader_Verbose == true) { |
54bfd6fd28b9
removed old obsolete manual loader; aix fixes
Claus Gittinger <cg@exept.de>
parents:
317
diff
changeset
|
1359 |
printf("value=%x section=%d type=%x sclass=%d\n", |
54bfd6fd28b9
removed old obsolete manual loader; aix fixes
Claus Gittinger <cg@exept.de>
parents:
317
diff
changeset
|
1360 |
nl[0].n_value, nl[0].n_scnum, nl[0].n_type, nl[0].n_sclass); |
321
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
1361 |
printf("vaddr = %x\n", addr); |
320
54bfd6fd28b9
removed old obsolete manual loader; aix fixes
Claus Gittinger <cg@exept.de>
parents:
317
diff
changeset
|
1362 |
} |
321
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
1363 |
# ifdef DOES_NOT_WORK |
320
54bfd6fd28b9
removed old obsolete manual loader; aix fixes
Claus Gittinger <cg@exept.de>
parents:
317
diff
changeset
|
1364 |
address = __MKUINT( (int)addr ); |
321
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
1365 |
# else |
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
1366 |
descriptor.vaddr = (unsigned) addr; |
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
1367 |
descriptor.long2 = 0; |
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
1368 |
descriptor.long3 = 0; |
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
1369 |
address = __MKUINT( (int)(&descriptor) ); |
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
1370 |
# endif |
141 | 1371 |
} |
321
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
1372 |
#endif /* dont USE_ENTRY */ |
141 | 1373 |
} |
1374 |
} |
|
321
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
1375 |
#endif /* AIX_DL */ |
141 | 1376 |
|
1377 |
#ifdef SUN_DL |
|
1378 |
{ |
|
1379 |
void *h; |
|
1380 |
void *addr; |
|
1381 |
int val; |
|
1382 |
OBJ low = sysHandle1, hi = sysHandle2; |
|
1383 |
||
1384 |
if (__bothSmallInteger(low, hi)) { |
|
1385 |
val = (_intVal(hi) << 16) + _intVal(low); |
|
1386 |
h = (void *)(val); |
|
1387 |
if (__isString(aString)) { |
|
320
54bfd6fd28b9
removed old obsolete manual loader; aix fixes
Claus Gittinger <cg@exept.de>
parents:
317
diff
changeset
|
1388 |
if (ObjectFileLoader_Verbose == true) { |
141 | 1389 |
printf("get sym <%s> handle = %x\n", __stringVal(aString), h); |
320
54bfd6fd28b9
removed old obsolete manual loader; aix fixes
Claus Gittinger <cg@exept.de>
parents:
317
diff
changeset
|
1390 |
} |
141 | 1391 |
addr = dlsym(h, __stringVal(aString)); |
1392 |
if (addr) { |
|
320
54bfd6fd28b9
removed old obsolete manual loader; aix fixes
Claus Gittinger <cg@exept.de>
parents:
317
diff
changeset
|
1393 |
if (ObjectFileLoader_Verbose == true) { |
141 | 1394 |
printf("addr = %x\n", addr); |
320
54bfd6fd28b9
removed old obsolete manual loader; aix fixes
Claus Gittinger <cg@exept.de>
parents:
317
diff
changeset
|
1395 |
} |
54bfd6fd28b9
removed old obsolete manual loader; aix fixes
Claus Gittinger <cg@exept.de>
parents:
317
diff
changeset
|
1396 |
address = __MKUINT( (int)addr ); |
141 | 1397 |
} else { |
320
54bfd6fd28b9
removed old obsolete manual loader; aix fixes
Claus Gittinger <cg@exept.de>
parents:
317
diff
changeset
|
1398 |
if (ObjectFileLoader_Verbose == true) { |
141 | 1399 |
printf("dlsym %s error: %s\n", __stringVal(aString), dlerror()); |
320
54bfd6fd28b9
removed old obsolete manual loader; aix fixes
Claus Gittinger <cg@exept.de>
parents:
317
diff
changeset
|
1400 |
} |
141 | 1401 |
} |
1402 |
} |
|
1403 |
} |
|
1404 |
} |
|
1405 |
#endif |
|
1406 |
||
1407 |
#ifdef NEXT_DL |
|
1408 |
{ |
|
1409 |
unsigned long addr; |
|
1410 |
long result; |
|
1411 |
NXStream *errOut; |
|
1412 |
||
1413 |
if (__isString(aString)) { |
|
320
54bfd6fd28b9
removed old obsolete manual loader; aix fixes
Claus Gittinger <cg@exept.de>
parents:
317
diff
changeset
|
1414 |
if (ObjectFileLoader_Verbose == true) { |
141 | 1415 |
printf("get sym <%s>\n", __stringVal(aString)); |
320
54bfd6fd28b9
removed old obsolete manual loader; aix fixes
Claus Gittinger <cg@exept.de>
parents:
317
diff
changeset
|
1416 |
} |
141 | 1417 |
errOut = NXOpenFile(2, 2); |
1418 |
result = rld_lookup(errOut, |
|
1419 |
(char *) __stringVal(aString), |
|
1420 |
&addr); |
|
1421 |
NXClose(errOut); |
|
1422 |
if (result) { |
|
320
54bfd6fd28b9
removed old obsolete manual loader; aix fixes
Claus Gittinger <cg@exept.de>
parents:
317
diff
changeset
|
1423 |
if (ObjectFileLoader_Verbose == true) { |
141 | 1424 |
printf("addr = %x\n", addr); |
320
54bfd6fd28b9
removed old obsolete manual loader; aix fixes
Claus Gittinger <cg@exept.de>
parents:
317
diff
changeset
|
1425 |
} |
54bfd6fd28b9
removed old obsolete manual loader; aix fixes
Claus Gittinger <cg@exept.de>
parents:
317
diff
changeset
|
1426 |
address = __MKUINT( (int)addr ); |
141 | 1427 |
} |
1428 |
} |
|
1429 |
} |
|
1430 |
#endif |
|
180 | 1431 |
|
141 | 1432 |
%}. |
320
54bfd6fd28b9
removed old obsolete manual loader; aix fixes
Claus Gittinger <cg@exept.de>
parents:
317
diff
changeset
|
1433 |
^ address |
141 | 1434 |
! |
1435 |
||
1436 |
hasUndefinedSymbolsIn:handle |
|
259 | 1437 |
"return true, if a module has undefined symbols in it. |
1438 |
This is only possible if the system supports loading |
|
1439 |
modules with undefined things in it - most do not" |
|
1440 |
||
141 | 1441 |
^ (self getListOfUndefinedSymbolsFrom:handle) size > 0 |
259 | 1442 |
|
1443 |
"Modified: 25.4.1996 / 09:47:27 / cg" |
|
141 | 1444 |
! |
1445 |
||
307
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
1446 |
initFunctionBasenameForFile:aFileName |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
1447 |
"return the expected initFunctions name, given a fileName" |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
1448 |
|
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
1449 |
|name suffixLen| |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
1450 |
|
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
1451 |
" |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
1452 |
first, expect the classes-name to be the fileName-base |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
1453 |
" |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
1454 |
name := OperatingSystem baseNameOf:aFileName. |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
1455 |
suffixLen := 0. |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
1456 |
self validBinaryExtensions do:[:suffix | |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
1457 |
suffixLen == 0 ifTrue:[ |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
1458 |
(name endsWith:suffix) ifTrue:[ |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
1459 |
suffixLen := suffix size |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
1460 |
] |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
1461 |
] |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
1462 |
]. |
403 | 1463 |
|
307
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
1464 |
suffixLen ~~ 0 ifTrue:[ |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
1465 |
name := name copyWithoutLast:suffixLen |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
1466 |
]. |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
1467 |
^ name. |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
1468 |
|
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
1469 |
" |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
1470 |
ObjectFileLoader initFunctionNameForFile:'libbasic.so' |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
1471 |
ObjectFileLoader initFunctionNameForFile:'demo.so' |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
1472 |
ObjectFileLoader initFunctionNameForFile:'demo.o' |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
1473 |
" |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
1474 |
|
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
1475 |
"Created: 13.7.1996 / 00:01:54 / cg" |
403 | 1476 |
"Modified: 30.10.1996 / 13:28:22 / cg" |
307
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
1477 |
! |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
1478 |
|
141 | 1479 |
isCPlusPlusObject:handle |
259 | 1480 |
"return true, if the loaded object is a c++ object module. |
1481 |
This is not yet fully implemented/supported." |
|
141 | 1482 |
|
1483 |
(self getSymbol:'__gnu_compiled_cplusplus' function:true from:handle) notNil ifTrue:[^ true]. |
|
1484 |
(self getSymbol:'__CTOR_LIST__' function:true from:handle) notNil ifTrue:[^ true]. |
|
1485 |
(self getSymbol:'__CTOR_LIST__' function:false from:handle) notNil ifTrue:[^ true]. |
|
1486 |
(self getSymbol:'__gnu_compiled_cplusplus' function:false from:handle) notNil ifTrue:[^ true]. |
|
6 | 1487 |
^ false |
259 | 1488 |
|
1489 |
"Modified: 25.4.1996 / 09:48:19 / cg" |
|
0 | 1490 |
! |
1491 |
||
141 | 1492 |
isObjectiveCObject:handle |
259 | 1493 |
"return true, if the loaded object is an objective-C object module. |
1494 |
This is not yet implemented/supported" |
|
141 | 1495 |
|
1496 |
^ false |
|
259 | 1497 |
|
1498 |
"Modified: 25.4.1996 / 09:47:59 / cg" |
|
141 | 1499 |
! |
1500 |
||
1501 |
isSmalltalkObject:handle |
|
1502 |
"return true, if the loaded object is a smalltalk object module" |
|
1503 |
||
1504 |
"not yet implemented - stc_compiled_smalltalk is a static symbol, |
|
1505 |
not found in list - need nm-interface, or nlist-walker |
|
1506 |
" |
|
1507 |
^ true. |
|
1508 |
||
365
22c85186e799
Fix misspelled "interrest" to "interest".
Stefan Vogel <sv@exept.de>
parents:
346
diff
changeset
|
1509 |
"/ (self getSymbol:'__stc_compiled_smalltalk' function:true from:handle) notNil ifTrue:[^ true]. |
22c85186e799
Fix misspelled "interrest" to "interest".
Stefan Vogel <sv@exept.de>
parents:
346
diff
changeset
|
1510 |
"/ (self getSymbol:'__stc_compiled_smalltalk' function:false from:handle) notNil ifTrue:[^ true]. |
22c85186e799
Fix misspelled "interrest" to "interest".
Stefan Vogel <sv@exept.de>
parents:
346
diff
changeset
|
1511 |
"/ ^ false |
141 | 1512 |
! |
1513 |
||
1514 |
listUndefinedSymbolsIn:handle |
|
259 | 1515 |
"list undefined objects in a module on the transcript" |
1516 |
||
141 | 1517 |
|undefinedNames| |
1518 |
||
1519 |
undefinedNames := self getListOfUndefinedSymbolsFrom:handle. |
|
1520 |
undefinedNames size > 0 ifTrue:[ |
|
272 | 1521 |
Transcript showCR:'undefined:'. |
259 | 1522 |
undefinedNames do:[:aName | |
272 | 1523 |
Transcript showCR:' ' , aName |
259 | 1524 |
] |
141 | 1525 |
]. |
259 | 1526 |
|
272 | 1527 |
"Modified: 18.5.1996 / 15:43:45 / cg" |
141 | 1528 |
! |
1529 |
||
1530 |
loadDynamicObject:pathName |
|
1531 |
"load an object-file (load/map into my address space). |
|
1532 |
Return a non-nil handle if ok, nil otherwise. |
|
1533 |
No bindings are done - only a pure load is performed. |
|
1534 |
This function is not supported on all architectures. |
|
1535 |
" |
|
1536 |
||
1537 |
|handle buffer| |
|
1538 |
||
1539 |
Verbose ifTrue:[ |
|
272 | 1540 |
('loadDynamic: ' , pathName , ' ...') infoPrintNL |
141 | 1541 |
]. |
1542 |
||
1543 |
"/ already loaded ? |
|
1544 |
||
1545 |
LoadedObjects notNil ifTrue:[ |
|
272 | 1546 |
handle := LoadedObjects at:pathName ifAbsent:nil. |
1547 |
handle notNil ifTrue:[ |
|
1548 |
Verbose ifTrue:[ |
|
1549 |
('... ' , pathName , ' already loaded.') infoPrintNL. |
|
1550 |
]. |
|
1551 |
^ handle |
|
1552 |
]. |
|
141 | 1553 |
]. |
1554 |
||
1555 |
"/ |
|
1556 |
"/ the 1st two entries are system dependent; |
|
1557 |
"/ entry 3 is the pathName |
|
1558 |
"/ entry 4 is a unique ID |
|
1559 |
"/ |
|
1560 |
buffer := Array new:4. |
|
1561 |
buffer at:3 put:pathName. |
|
1562 |
buffer at:4 put:NextHandleID. NextHandleID := NextHandleID + 1. |
|
1563 |
||
1564 |
buffer := self primLoadDynamicObject:pathName into:buffer. |
|
1565 |
buffer isNil ifTrue:[ |
|
272 | 1566 |
LastError == #notImplemented ifTrue:[ |
1567 |
Verbose ifTrue:[ |
|
1568 |
'no dynamic load facility or load failed.' infoPrintNL. |
|
1569 |
]. |
|
1570 |
]. |
|
1571 |
buffer isNil ifTrue:[ |
|
1572 |
LastError == #linkError ifTrue:[ |
|
1573 |
LinkErrorMessage notNil ifTrue:[ |
|
1574 |
Transcript showCR:'Load error:' , LinkErrorMessage |
|
1575 |
]. |
|
1576 |
]. |
|
1577 |
^ nil |
|
1578 |
] |
|
0 | 1579 |
]. |
141 | 1580 |
|
1581 |
" |
|
1582 |
remember loaded object for later unloading |
|
1583 |
" |
|
1584 |
handle := ObjectFileHandle new. |
|
1585 |
handle sysHandle1:(buffer at:1). |
|
1586 |
handle sysHandle2:(buffer at:2). |
|
1587 |
handle pathName:(buffer at:3). |
|
1588 |
handle moduleID:(buffer at:4). |
|
1589 |
||
1590 |
LoadedObjects isNil ifTrue:[ |
|
272 | 1591 |
LoadedObjects := Dictionary new. |
141 | 1592 |
]. |
1593 |
LoadedObjects at:pathName put:handle. |
|
1594 |
Smalltalk flushCachedClasses. |
|
1595 |
||
1596 |
Verbose ifTrue:[ |
|
272 | 1597 |
('loadDynamic ok; handle is: ' , handle printString) infoPrintNL. |
141 | 1598 |
]. |
1599 |
||
1600 |
^ handle |
|
1601 |
||
1602 |
"sys5.4: |
|
1603 |
|handle| |
|
1604 |
handle := ObjectFileLoader loadDynamicObject:'../stc/mod1.so'. |
|
1605 |
ObjectFileLoader getFunction:'module1' from:handle |
|
1606 |
" |
|
1607 |
"next: |
|
1608 |
|handle| |
|
1609 |
handle := ObjectFileLoader loadDynamicObject:'../goodies/Path/AbstrPath.o'. |
|
1610 |
ObjectFileLoader getFunction:'__AbstractPath_Init' from:handle |
|
1611 |
" |
|
1612 |
"GLD: |
|
1613 |
|handle| |
|
1614 |
handle := ObjectFileLoader loadDynamicObject:'../clients/Tetris/Tetris.o'. |
|
1615 |
ObjectFileLoader getFunction:'__TetrisBlock_Init' from:handle |
|
1616 |
" |
|
272 | 1617 |
|
1618 |
"Modified: 18.5.1996 / 15:43:56 / cg" |
|
141 | 1619 |
! |
1620 |
||
1621 |
namesMatching:aPattern segment:segmentPattern in:aFileName |
|
1622 |
"this is rubbish - it will vanish soon" |
|
1623 |
||
1624 |
|p l s addr segment name entry| |
|
1625 |
||
1626 |
OperatingSystem getSystemType = 'aix' ifTrue:[ |
|
225 | 1627 |
^ nil |
141 | 1628 |
]. |
1629 |
||
1630 |
l := OrderedCollection new. |
|
1631 |
p := PipeStream readingFrom:(self nm:aFileName). |
|
1632 |
p isNil ifTrue:[ |
|
225 | 1633 |
('LOADER: cannot read names from ' , aFileName) infoPrintNL. |
1634 |
^ nil |
|
141 | 1635 |
]. |
1636 |
[p atEnd] whileFalse:[ |
|
225 | 1637 |
entry := p nextLine. |
1638 |
Verbose ifTrue:[ |
|
1639 |
entry infoPrintNL. |
|
1640 |
]. |
|
1641 |
entry notNil ifTrue:[ |
|
1642 |
s := ReadStream on:entry. |
|
1643 |
addr := s nextAlphaNumericWord. |
|
1644 |
segment := s nextAlphaNumericWord. |
|
1645 |
name := s upToEnd withoutSeparators. |
|
1646 |
(addr notNil and:[segment notNil and:[name notNil]]) ifTrue:[ |
|
1647 |
(aPattern match:name) ifTrue:[ |
|
1648 |
(segmentPattern isNil or:[segmentPattern match:segment]) ifTrue:[ |
|
1649 |
l add:name. |
|
1650 |
Verbose ifTrue:[ |
|
1651 |
('found name: ' , name) infoPrintNL. |
|
1652 |
] |
|
1653 |
] ifFalse:[ |
|
1654 |
Verbose ifTrue:[ |
|
1655 |
name infoPrint. ' segment mismatch ' infoPrint. |
|
1656 |
segmentPattern infoPrint. ' ' infoPrint. segment infoPrintNL. |
|
1657 |
] |
|
1658 |
] |
|
1659 |
] |
|
1660 |
] |
|
1661 |
] |
|
0 | 1662 |
]. |
141 | 1663 |
p close. |
1664 |
^ l |
|
225 | 1665 |
|
1666 |
"Modified: 7.3.1996 / 19:20:01 / cg" |
|
141 | 1667 |
! |
1668 |
||
1669 |
primLoadDynamicObject:pathName into:anInfoBuffer |
|
1670 |
"load an object-file (map into my address space). |
|
1671 |
Return an OS-handle (whatever that is) - where some space |
|
1672 |
(a 3-element array) has to be passed in for this. |
|
1673 |
The first two entries are used in a machine dependent way, |
|
1674 |
and callers may not depend on what is found there |
|
1675 |
(instead, only pass around handles transparently). |
|
1676 |
This function is not supported on all architectures." |
|
1677 |
||
222 | 1678 |
%{ /* CALLSUNLIMITEDSTACK */ |
141 | 1679 |
|
1680 |
if (! __isArray(anInfoBuffer) |
|
1681 |
|| (_arraySize(anInfoBuffer) < 3)) { |
|
1682 |
return nil; |
|
1683 |
} |
|
1684 |
||
1685 |
#ifdef GNU_DL |
|
1686 |
{ |
|
1687 |
static firstCall = 1; |
|
1688 |
extern char *__myName__; |
|
1689 |
extern dld_ignore_redefinitions; |
|
1690 |
||
1691 |
if (firstCall) { |
|
1692 |
firstCall = 0; |
|
1693 |
(void) dld_init (__myName__); |
|
1694 |
dld_ignore_redefinitions = 1; |
|
1695 |
} |
|
1696 |
||
1697 |
if (__isString(pathName)) { |
|
1698 |
if (dld_link(__stringVal(pathName))) { |
|
1699 |
if (ObjectFileLoader_Verbose == true) { |
|
1700 |
printf ("link file %s failed\n", __stringVal(pathName)); |
|
1701 |
dld_perror("cant link"); |
|
1702 |
} |
|
1703 |
ObjectFileLoader_LastError = @symbol(linkError); |
|
1704 |
RETURN ( nil ); |
|
1705 |
} |
|
238 | 1706 |
__ArrayInstPtr(anInfoBuffer)->a_element[0] = pathName; |
141 | 1707 |
__STORE(anInfoBuffer, pathName); |
1708 |
RETURN ( anInfoBuffer ); |
|
1709 |
} |
|
1710 |
RETURN ( nil ); |
|
1711 |
} |
|
1712 |
#endif |
|
1713 |
||
180 | 1714 |
#ifdef WIN_DL |
1715 |
{ |
|
1716 |
HINSTANCE handle; |
|
1717 |
int err; |
|
1718 |
||
1719 |
if (__isString(pathName)) { |
|
182
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
180
diff
changeset
|
1720 |
if ((handle = LoadLibrary(__stringVal(pathName))) == NULL) { |
180 | 1721 |
err = GetLastError(); |
182
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
180
diff
changeset
|
1722 |
if (ObjectFileLoader_Verbose == true) { |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
180
diff
changeset
|
1723 |
printf ("LoadLibrary %s failed; error: %x\n", |
180 | 1724 |
__stringVal(pathName), err); |
182
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
180
diff
changeset
|
1725 |
} |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
180
diff
changeset
|
1726 |
ObjectFileLoader_LastError = __MKINT(err); |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
180
diff
changeset
|
1727 |
RETURN ( nil ); |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
180
diff
changeset
|
1728 |
} |
238 | 1729 |
__ArrayInstPtr(anInfoBuffer)->a_element[0] = __MKSMALLINT( (int)handle & 0xFFFF ); |
1730 |
__ArrayInstPtr(anInfoBuffer)->a_element[1] = __MKSMALLINT( ((int)handle >> 16) & 0xFFFF ); |
|
182
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
180
diff
changeset
|
1731 |
RETURN ( anInfoBuffer ); |
180 | 1732 |
} |
1733 |
RETURN ( nil ); |
|
1734 |
} |
|
1735 |
#endif |
|
1736 |
||
141 | 1737 |
#ifdef DL1_6 |
1738 |
{ |
|
1739 |
extern char *__myName__; |
|
1740 |
char *ldname; |
|
1741 |
OBJ tmpName; |
|
1742 |
||
1743 |
if (__isString(pathName)) { |
|
1744 |
if ( dl_loadmod_only(__myName__, __stringVal(pathName), &ldname) == 0 ) { |
|
1745 |
if (ObjectFileLoader_Verbose == true) { |
|
1746 |
printf ("link file %s failed\n", __stringVal(pathName)); |
|
1747 |
} |
|
1748 |
RETURN ( nil ); |
|
1749 |
} |
|
1750 |
/* |
|
1751 |
* returns the name of the temporary ld-file |
|
1752 |
* use that as handle ... |
|
1753 |
*/ |
|
238 | 1754 |
tmpName = __MKSTRING(ldname); |
1755 |
__ArrayInstPtr(anInfoBuffer)->a_element[0] = tmpName; |
|
141 | 1756 |
__STORE(anInfoBuffer, tmpName); |
1757 |
RETURN ( anInfoBuffer ); |
|
1758 |
} |
|
1759 |
RETURN ( nil ); |
|
1760 |
} |
|
1761 |
#endif |
|
1762 |
||
1763 |
#ifdef AIX_DL |
|
1764 |
{ |
|
1765 |
extern char *__myName__; |
|
321
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
1766 |
char *objName, *libPath; |
141 | 1767 |
int *handle; |
1768 |
extern errno; |
|
1769 |
||
1770 |
if (__isString(pathName)) { |
|
321
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
1771 |
objName = __stringVal(pathName); |
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
1772 |
|
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
1773 |
if (__isString(@global(LibPath))) { |
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
1774 |
libPath = __stringVal(@global(LibPath)); |
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
1775 |
} else { |
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
1776 |
libPath = (char *)0; |
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
1777 |
} |
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
1778 |
if ( (handle = (int *) load(objName, 0, libPath)) == 0 ) { |
141 | 1779 |
if (ObjectFileLoader_Verbose == true) { |
1780 |
char *messages[64]; |
|
1781 |
int i; |
|
1782 |
||
1783 |
printf ("load file %s failed errno=%d\n", |
|
321
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
1784 |
objName, errno); |
141 | 1785 |
switch (errno) { |
1786 |
case ENOEXEC: |
|
1787 |
printf(" load messages:\n"); |
|
1788 |
loadquery(L_GETMESSAGES, messages, sizeof(messages)); |
|
1789 |
for (i=0; messages[i]; i++) { |
|
1790 |
printf(" %s\n", messages[i]); |
|
1791 |
} |
|
1792 |
break; |
|
1793 |
} |
|
1794 |
} |
|
1795 |
RETURN ( nil ); |
|
1796 |
} |
|
1797 |
if (ObjectFileLoader_Verbose == true) { |
|
321
9428bae4c62e
dynamic loading for aix fixed
Claus Gittinger <cg@exept.de>
parents:
320
diff
changeset
|
1798 |
printf("load %s handle = %x\n", objName, handle); |
141 | 1799 |
} |
1800 |
||
238 | 1801 |
__ArrayInstPtr(anInfoBuffer)->a_element[0] = __MKSMALLINT( (int)handle & 0xFFFF ); |
1802 |
__ArrayInstPtr(anInfoBuffer)->a_element[1] = __MKSMALLINT( ((int)handle >> 16) & 0xFFFF ); |
|
141 | 1803 |
RETURN (anInfoBuffer); |
1804 |
} |
|
1805 |
RETURN ( nil ); |
|
1806 |
} |
|
1807 |
#endif |
|
1808 |
||
1809 |
#ifdef SYSV4_DL |
|
1810 |
{ |
|
1811 |
void *handle; |
|
1812 |
char *nm; |
|
1813 |
char *errMsg; |
|
1814 |
||
1815 |
if ((pathName == nil) || __isString(pathName)) { |
|
365
22c85186e799
Fix misspelled "interrest" to "interest".
Stefan Vogel <sv@exept.de>
parents:
346
diff
changeset
|
1816 |
handle = (void *)dlopen(pathName == nil ? 0 : __stringVal(pathName), RTLD_NOW); |
141 | 1817 |
|
1818 |
if (! handle) { |
|
1819 |
errMsg = dlerror(); |
|
1820 |
fprintf(stderr, "dlopen %s error:\n", __stringVal(pathName)); |
|
1821 |
fprintf(stderr, " <%s>\n", errMsg); |
|
1822 |
ObjectFileLoader_LastError = @symbol(linkError); |
|
238 | 1823 |
ObjectFileLoader_LinkErrorMessage = __MKSTRING(errMsg); |
141 | 1824 |
RETURN (nil); |
1825 |
} |
|
1826 |
||
1827 |
if (ObjectFileLoader_Verbose == true) { |
|
1828 |
printf("open %s handle = %x\n", __stringVal(pathName), handle); |
|
1829 |
} |
|
1830 |
||
238 | 1831 |
__ArrayInstPtr(anInfoBuffer)->a_element[0] = __MKSMALLINT( (int)handle & 0xFFFF ); |
1832 |
__ArrayInstPtr(anInfoBuffer)->a_element[1] = __MKSMALLINT( ((int)handle >> 16) & 0xFFFF ); |
|
141 | 1833 |
RETURN (anInfoBuffer); |
1834 |
} |
|
1835 |
} |
|
1836 |
#endif |
|
1837 |
||
1838 |
#ifdef SUN_DL |
|
1839 |
{ |
|
1840 |
void *handle; |
|
1841 |
||
1842 |
if ((pathName == nil) || __isString(pathName)) { |
|
1843 |
if (pathName == nil) |
|
1844 |
handle = dlopen((char *)0, 1); |
|
1845 |
else |
|
1846 |
handle = dlopen(__stringVal(pathName), 1); |
|
1847 |
||
1848 |
if (! handle) { |
|
1849 |
fprintf(stderr, "dlopen %s error: <%s>\n", |
|
1850 |
__stringVal(pathName), dlerror()); |
|
1851 |
ObjectFileLoader_LastError = @symbol(linkError); |
|
1852 |
RETURN (nil); |
|
1853 |
} |
|
1854 |
||
1855 |
if (ObjectFileLoader_Verbose == true) { |
|
1856 |
printf("open %s handle = %x\n", __stringVal(pathName), handle); |
|
1857 |
} |
|
1858 |
||
238 | 1859 |
__ArrayInstPtr(anInfoBuffer)->a_element[0] = __MKSMALLINT( (int)handle & 0xFFFF ); |
1860 |
__ArrayInstPtr(anInfoBuffer)->a_element[1] = __MKSMALLINT( ((int)handle >> 16) & 0xFFFF ); |
|
141 | 1861 |
RETURN (anInfoBuffer); |
1862 |
} |
|
1863 |
} |
|
1864 |
#endif |
|
1865 |
||
1866 |
#ifdef NEXT_DL |
|
1867 |
{ |
|
1868 |
long result; |
|
1869 |
char *files[2]; |
|
1870 |
NXStream *errOut; |
|
1871 |
||
1872 |
if (__isString(pathName)) { |
|
1873 |
files[0] = (char *) __stringVal(pathName); |
|
1874 |
files[1] = (char *) 0; |
|
1875 |
errOut = NXOpenFile(2, 2); |
|
1876 |
result = rld_load(errOut, |
|
1877 |
(struct mach_header **)0, |
|
1878 |
files, |
|
1879 |
(char *)0); |
|
1880 |
NXClose(errOut); |
|
1881 |
if (! result) { |
|
1882 |
ObjectFileLoader_LastError = @symbol(linkError); |
|
1883 |
fprintf(stderr, "rld_load %s failed\n", __stringVal(pathName)); |
|
1884 |
RETURN (nil); |
|
1885 |
} |
|
1886 |
||
1887 |
if (ObjectFileLoader_Verbose == true) |
|
1888 |
printf("rld_load %s ok\n", __stringVal(pathName)); |
|
1889 |
||
238 | 1890 |
__ArrayInstPtr(anInfoBuffer)->a_element[0] = pathName; |
141 | 1891 |
__STORE(anInfoBuffer, pathName); |
1892 |
RETURN ( anInfoBuffer ); |
|
1893 |
} |
|
1894 |
} |
|
1895 |
#endif |
|
1896 |
%}. |
|
1897 |
LastError := #notImplemented. |
|
1898 |
^ nil |
|
1899 |
! |
|
1900 |
||
1901 |
primUnloadDynamicObject:aHandle |
|
1902 |
"unload an object-file (unmap from my address space). |
|
1903 |
This is a low-level entry, which does not care if there are |
|
1904 |
still any code references (from blocks or methods) to this |
|
1905 |
module. Calling it for still living classes will definitely |
|
1906 |
lead to some fatal conditions to occur later." |
|
1907 |
||
1908 |
|sysHandle1 sysHandle2| |
|
1909 |
||
1910 |
sysHandle1 := aHandle sysHandle1. |
|
1911 |
sysHandle2 := aHandle sysHandle2. |
|
1912 |
||
1913 |
%{ |
|
1914 |
#ifdef GNU_DL |
|
1915 |
if (__isString(sysHandle1)) { |
|
1916 |
if (dld_unlink_by_file(__stringVal(sysHandle1), 1)) { |
|
1917 |
if (ObjectFileLoader_Verbose == true) { |
|
1918 |
printf ("unlink file %s failed\n", __stringVal(sysHandle1)); |
|
1919 |
dld_perror("cant unlink"); |
|
1920 |
} |
|
1921 |
RETURN (false); |
|
1922 |
} |
|
1923 |
RETURN (true); |
|
1924 |
} |
|
1925 |
RETURN (false); |
|
1926 |
#endif |
|
1927 |
||
180 | 1928 |
#ifdef WIN_DL |
1929 |
int val; |
|
1930 |
HINSTANCE handle; |
|
1931 |
int err; |
|
1932 |
||
1933 |
if (__bothSmallInteger(sysHandle1, sysHandle2)) { |
|
182
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
180
diff
changeset
|
1934 |
val = (_intVal(sysHandle2) << 16) + _intVal(sysHandle1); |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
180
diff
changeset
|
1935 |
handle = (HINSTANCE)(val); |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
180
diff
changeset
|
1936 |
|
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
180
diff
changeset
|
1937 |
if (FreeLibrary(handle) != TRUE) { |
180 | 1938 |
err = GetLastError(); |
182
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
180
diff
changeset
|
1939 |
if (ObjectFileLoader_Verbose == true) { |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
180
diff
changeset
|
1940 |
printf ("unlink file %s failed; error: %x\n", |
180 | 1941 |
__stringVal(sysHandle1), err); |
182
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
180
diff
changeset
|
1942 |
} |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
180
diff
changeset
|
1943 |
RETURN (false); |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
180
diff
changeset
|
1944 |
} |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
180
diff
changeset
|
1945 |
RETURN (true); |
180 | 1946 |
} |
1947 |
RETURN (false); |
|
1948 |
#endif |
|
1949 |
||
141 | 1950 |
#ifdef SYSV4_DL |
1951 |
{ |
|
1952 |
void *h; |
|
1953 |
int val; |
|
1954 |
OBJ low = sysHandle1, hi = sysHandle2; |
|
1955 |
||
1956 |
if (__bothSmallInteger(low, hi)) { |
|
1957 |
val = (_intVal(hi) << 16) + _intVal(low); |
|
1958 |
h = (void *)(val); |
|
1959 |
if (ObjectFileLoader_Verbose == true) |
|
1960 |
printf("close handle = %x\n", h); |
|
1961 |
if (dlclose(h) != 0) { |
|
1962 |
fprintf(stderr, "dlclose failed with:<%s>\n", dlerror()); |
|
1963 |
RETURN (false); |
|
1964 |
} |
|
1965 |
RETURN (true); |
|
1966 |
} |
|
1967 |
} |
|
1968 |
#endif |
|
1969 |
||
1970 |
#ifdef SUN_DL |
|
1971 |
{ |
|
1972 |
void *h; |
|
1973 |
int val; |
|
1974 |
OBJ low = sysHandle1, hi = sysHandle2; |
|
1975 |
||
1976 |
if (__bothSmallInteger(low, hi)) { |
|
1977 |
val = (_intVal(hi) << 16) + _intVal(low); |
|
1978 |
h = (void *)(val); |
|
1979 |
if (ObjectFileLoader_Verbose == true) |
|
1980 |
printf("close handle = %x\n", h); |
|
1981 |
dlclose(h); |
|
1982 |
RETURN (true); |
|
1983 |
} |
|
1984 |
} |
|
1985 |
#endif |
|
1986 |
||
1987 |
#ifdef AIX_DL |
|
1988 |
{ |
|
1989 |
int *h; |
|
1990 |
int val; |
|
1991 |
OBJ low = sysHandle1, hi = sysHandle2; |
|
1992 |
||
1993 |
if (__bothSmallInteger(low, hi)) { |
|
1994 |
val = (_intVal(hi) << 16) + _intVal(low); |
|
1995 |
h = (int *)(val); |
|
1996 |
if (ObjectFileLoader_Verbose == true) |
|
1997 |
printf("unload handle = %x\n", h); |
|
1998 |
if ( unload(h) != 0) { |
|
1999 |
fprintf(stderr, "unload failed\n"); |
|
2000 |
RETURN (false); |
|
2001 |
} |
|
2002 |
RETURN (true); |
|
2003 |
} |
|
2004 |
} |
|
2005 |
#endif |
|
2006 |
%}. |
|
2007 |
^ false |
|
2008 |
! |
|
2009 |
||
2010 |
releaseSymbolTable |
|
2011 |
"this is needed on NeXT to forget loaded names. If this wasnt done, |
|
2012 |
the same class could not be loaded in again due to multiple defines. |
|
2013 |
On other architectures, this is not needed and therefore a noop." |
|
2014 |
||
2015 |
%{ |
|
2016 |
#ifdef NEXT_DL |
|
2017 |
NXStream *errOut; |
|
2018 |
||
2019 |
errOut = NXOpenFile(2, 2); |
|
2020 |
rld_unload_all(errOut, (long)0); |
|
2021 |
rld_load_basefile(errOut, "smalltalk"); |
|
2022 |
NXClose(errOut); |
|
2023 |
#endif |
|
2024 |
%} |
|
2025 |
! |
|
2026 |
||
2027 |
unloadDynamicObject:handle |
|
2028 |
"close an object-file (unmap from my address space) |
|
2029 |
and remove the entry from the remembered object file set. |
|
2030 |
This is a low-level entry, which does not care if there are |
|
2031 |
still any code references (from blocks or methods) to this |
|
2032 |
module. Calling it for still living classes will definitely |
|
2033 |
lead to some fatal conditions to occur later." |
|
2034 |
||
369 | 2035 |
|key fileName functionName deInitAddr m| |
141 | 2036 |
|
2037 |
Verbose ifTrue:[ |
|
307
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2038 |
'unload module name=' infoPrint. handle pathName infoPrintNL. |
141 | 2039 |
]. |
2040 |
||
307
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2041 |
"/ |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2042 |
"/ fixup |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2043 |
"/ |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2044 |
|
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2045 |
handle isFunctionObjectHandle ifTrue:[ |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2046 |
handle functions do:[:f | |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2047 |
f notNil ifTrue:[ |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2048 |
f code:0 |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2049 |
] |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2050 |
]. |
141 | 2051 |
]. |
307
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2052 |
|
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2053 |
(handle isClassLibHandle |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2054 |
or:[handle isMethodHandle]) ifTrue:[ |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2055 |
self deinitializeClassesFromModule:handle. |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2056 |
self unregisterModule:handle. |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2057 |
] ifFalse:[ |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2058 |
fileName := handle pathName asFilename baseName. |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2059 |
functionName := self initFunctionBasenameForFile:fileName. |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2060 |
|
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2061 |
deInitAddr := self findFunction:functionName suffix:'__deInit' in:handle. |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2062 |
deInitAddr notNil ifTrue:[ |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2063 |
self callInitFunctionAt:deInitAddr |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2064 |
specialInit:false |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2065 |
forceOld:true |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2066 |
interruptable:false |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2067 |
argument:0 |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2068 |
identifyAs:handle |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2069 |
returnsObject:false. |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2070 |
] |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2071 |
]. |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2072 |
|
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2073 |
"/ |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2074 |
"/ now, really unload |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2075 |
"/ |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2076 |
(self primUnloadDynamicObject:handle) ifFalse:[ |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2077 |
^ self error:'unloadDynamic failed' |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2078 |
]. |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2079 |
|
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2080 |
"/ |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2081 |
"/ remove from loaded objects |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2082 |
"/ |
141 | 2083 |
LoadedObjects notNil ifTrue:[ |
307
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2084 |
key := LoadedObjects keyAtEqualValue:handle. |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2085 |
key notNil ifTrue:[ |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2086 |
LoadedObjects removeKey:key |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2087 |
] |
6 | 2088 |
]. |
141 | 2089 |
Smalltalk flushCachedClasses. |
2090 |
||
2091 |
" |
|
2092 |
for individual methods, we keep the methodObject, |
|
2093 |
but make it unexecutable. Its still visible in the browser. |
|
2094 |
" |
|
2095 |
handle isMethodHandle ifTrue:[ |
|
369 | 2096 |
((m := handle method) notNil |
2097 |
and:[m ~~ 0]) ifTrue:[ |
|
409 | 2098 |
m makeUnloaded. |
307
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2099 |
ObjectMemory flushCaches. |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2100 |
] |
141 | 2101 |
] |
307
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2102 |
|
409 | 2103 |
"Modified: 4.11.1996 / 23:05:20 / cg" |
303 | 2104 |
! ! |
2105 |
||
369 | 2106 |
!ObjectFileLoader class methodsFor:'image save/restart'! |
303 | 2107 |
|
2108 |
invalidateAndRememberAllObjectFiles |
|
2109 |
"invalidate code refs into all dynamically loaded object files. |
|
2110 |
Required before writing a snapshot image." |
|
2111 |
||
2112 |
LoadedObjects notNil ifTrue:[ |
|
2113 |
ActuallyLoadedObjects := LoadedObjects. |
|
2114 |
self rememberAllObjectFiles. |
|
2115 |
ActuallyLoadedObjects keys do:[:aFileName | |
|
2116 |
|handle| |
|
2117 |
||
2118 |
handle := ActuallyLoadedObjects at:aFileName. |
|
2119 |
handle isNil ifTrue:[ |
|
2120 |
self error:'oops, no handle'. |
|
2121 |
] ifFalse:[ |
|
2122 |
(handle isClassLibHandle or:[handle isMethodHandle]) ifTrue:[ |
|
2123 |
self invalidateModule:handle |
|
2124 |
] |
|
2125 |
] |
|
2126 |
]. |
|
2127 |
LoadedObjects := nil. |
|
2128 |
]. |
|
2129 |
||
2130 |
"Created: 5.10.1995 / 15:48:56 / claus" |
|
2131 |
"Modified: 5.10.1995 / 16:48:51 / claus" |
|
2132 |
"Modified: 12.7.1996 / 17:13:45 / cg" |
|
28 | 2133 |
! |
6 | 2134 |
|
303 | 2135 |
reloadAllRememberedObjectFiles |
2136 |
"reload all object modules as were loaded when the image was saved. |
|
2137 |
Some care has to be taken, if files are missing or otherwise corrupted." |
|
2138 |
||
406
6a4f1e3800af
use new Method>>who interface
Claus Gittinger <cg@exept.de>
parents:
405
diff
changeset
|
2139 |
|oldDummyMethod who m newHandle |
303 | 2140 |
savedOldClasses savedByteCodeMethods savedMethods |
2141 |
functions newFunction| |
|
2142 |
||
2143 |
PreviouslyLoadedObjects notNil ifTrue:[ |
|
2144 |
PreviouslyLoadedObjects do:[:entry | |
|
2145 |
|fileName handle cls sel| |
|
2146 |
||
2147 |
fileName := entry key. |
|
2148 |
handle := entry value. |
|
2149 |
handle moduleID:nil. |
|
2150 |
||
2151 |
handle isClassLibHandle ifTrue:[ |
|
2152 |
('OBJFLOADER: reloading classes in ' , fileName , ' ...') infoPrintNL. |
|
2153 |
||
2154 |
"/ |
|
2155 |
"/ remember all byteCode methods (as added in the session) |
|
2156 |
"/ |
|
2157 |
savedByteCodeMethods := IdentityDictionary new. |
|
2158 |
savedOldClasses := IdentitySet new. |
|
2159 |
||
2160 |
handle classes do:[:aClass | |
|
2161 |
savedMethods := IdentityDictionary new. |
|
2162 |
savedOldClasses add:aClass. |
|
2163 |
aClass methodDictionary keysAndValuesDo:[:sel :m | |
|
2164 |
m byteCode notNil ifTrue:[ |
|
2165 |
"/ an interpreted method - must be preserved |
|
2166 |
savedMethods at:sel put:m |
|
2167 |
] |
|
2168 |
]. |
|
2169 |
savedMethods notEmpty ifTrue:[ |
|
2170 |
savedByteCodeMethods at:(aClass name) put:savedMethods |
|
2171 |
]. |
|
2172 |
]. |
|
2173 |
"/ |
|
2174 |
"/ load the class binary |
|
2175 |
"/ |
|
2176 |
self loadObjectFile:fileName. |
|
2177 |
||
2178 |
"/ |
|
2179 |
"/ reinstall the byteCode methods |
|
2180 |
"/ |
|
2181 |
savedByteCodeMethods keysAndValuesDo:[:nm :savedMethods | |
|
2182 |
|cls| |
|
2183 |
||
2184 |
cls := Smalltalk classNamed:nm. |
|
2185 |
savedMethods keysAndValuesDo:[:sel :m | |
|
2186 |
cls primAddSelector:sel withMethod:m. |
|
2187 |
"/ ('preserved ' , cls name , '>>' , sel) printNL. |
|
2188 |
] |
|
2189 |
]. |
|
2190 |
||
2191 |
"/ |
|
2192 |
"/ validate old-classes vs. new classes. |
|
2193 |
"/ and if things look ok, get rid of old stuff |
|
2194 |
"/ and make instances become instances of the new class |
|
2195 |
"/ |
|
2196 |
savedOldClasses do:[:oldClass | |
|
2197 |
|newClass| |
|
2198 |
||
2199 |
newClass := Smalltalk classNamed:(oldClass name). |
|
399 | 2200 |
newClass == oldClass ifTrue:[ |
2201 |
"/ ('OBJFLOADER: class ' , oldClass name , ' reloaded.') errorPrintCR. |
|
303 | 2202 |
] ifFalse:[ |
399 | 2203 |
(newClass isNil or:[newClass == oldClass]) ifTrue:[ |
2204 |
('OBJFLOADER: reload of ' , oldClass name , ' seemed to fail.') errorPrintCR. |
|
2205 |
] ifFalse:[ |
|
303 | 2206 |
"/'oldSize: ' print. oldClass instSize print. ' (' print. oldClass instSize class name print. ') ' print. |
2207 |
"/'newSize: ' print. newClass instSize print. ' (' print. oldClass instSize class name print. ') ' printCR. |
|
2208 |
||
399 | 2209 |
oldClass instSize ~~ newClass instSize ifTrue:[ |
2210 |
('OBJFLOADER: ' , oldClass name , ' has changed its size.') errorPrintCR. |
|
303 | 2211 |
] ifFalse:[ |
399 | 2212 |
oldClass class instSize ~~ newClass class instSize ifTrue:[ |
2213 |
('OBJFLOADER: ' , oldClass name , ' class has changed its size.') errorPrintCR. |
|
2214 |
] ifFalse:[ |
|
2215 |
('OBJFLOADER: migrating ' , oldClass name) errorPrintCR. |
|
2216 |
oldClass becomeSameAs:newClass |
|
2217 |
] |
|
303 | 2218 |
] |
2219 |
] |
|
2220 |
] |
|
2221 |
] |
|
2222 |
||
2223 |
] ifFalse:[ |
|
2224 |
handle isMethodHandle ifTrue:[ |
|
2225 |
oldDummyMethod := handle method. |
|
2226 |
(oldDummyMethod isKindOf:Method) ifFalse:[ |
|
2227 |
('OBJFLOADER: ignore obsolete (already collected) method in ' , fileName) infoPrintNL |
|
2228 |
] ifTrue:[ |
|
2229 |
('OBJFLOADER: reloading method in ' , fileName , ' ...') infoPrintNL. |
|
406
6a4f1e3800af
use new Method>>who interface
Claus Gittinger <cg@exept.de>
parents:
405
diff
changeset
|
2230 |
who := oldDummyMethod who. |
303 | 2231 |
newHandle := self loadMethodObjectFile:fileName. |
2232 |
newHandle isNil ifTrue:[ |
|
306 | 2233 |
('OBJFLOADER: failed to reload method in ' , fileName , ' ...') errorPrintNL. |
2234 |
handle moduleID:nil. |
|
303 | 2235 |
] ifFalse:[ |
2236 |
m := newHandle method. |
|
2237 |
m source:(oldDummyMethod source). |
|
2238 |
m package:(oldDummyMethod package). |
|
406
6a4f1e3800af
use new Method>>who interface
Claus Gittinger <cg@exept.de>
parents:
405
diff
changeset
|
2239 |
who notNil ifTrue:[ |
6a4f1e3800af
use new Method>>who interface
Claus Gittinger <cg@exept.de>
parents:
405
diff
changeset
|
2240 |
cls := who methodClass. |
6a4f1e3800af
use new Method>>who interface
Claus Gittinger <cg@exept.de>
parents:
405
diff
changeset
|
2241 |
sel := who methodSelector. |
303 | 2242 |
m == (cls compiledMethodAt:sel) ifFalse:[ |
2243 |
'LOADER: oops - loaded method installed wrong' errorPrintNL. |
|
2244 |
] ifTrue:[ |
|
2245 |
"/ cls changed:#methodDictionary with:(Array with:sel with:oldDummyMethod). |
|
2246 |
] |
|
2247 |
]. |
|
2248 |
] |
|
2249 |
] |
|
2250 |
] ifFalse:[ |
|
2251 |
handle isFunctionObjectHandle ifTrue:[ |
|
2252 |
functions := handle functions. |
|
2253 |
functions isEmpty ifTrue:[ |
|
2254 |
('OBJFLOADER: ignore obsolete (unreferenced) functions in ' , fileName) infoPrintNL |
|
2255 |
] ifFalse:[ |
|
305 | 2256 |
newHandle := self loadDynamicObject:fileName. |
306 | 2257 |
newHandle isNil ifTrue:[ |
2258 |
('OBJFLOADER: failed to reload ' , fileName , ' ...') errorPrintNL. |
|
2259 |
handle moduleID:nil. |
|
2260 |
] ifFalse:[ |
|
2261 |
('OBJFLOADER: reloading ' , fileName , ' ...') infoPrintNL. |
|
2262 |
functions do:[:oldFunction | |
|
2263 |
newFunction := newHandle getFunction:(oldFunction name). |
|
2264 |
newFunction isNil ifTrue:[ |
|
2265 |
('OBJFLOADER: function: ''' , oldFunction name , ''' no longer present.') errorPrintNL. |
|
2266 |
oldFunction code:nil. |
|
2267 |
oldFunction setName:oldFunction name moduleHandle:nil. |
|
2268 |
] ifFalse:[ |
|
2269 |
oldFunction code:(newFunction code). |
|
2270 |
oldFunction setName:oldFunction name moduleHandle:newHandle. |
|
2271 |
('OBJFLOADER: rebound function: ''' , oldFunction name , '''.') infoPrintNL. |
|
2272 |
] |
|
2273 |
]. |
|
2274 |
handle becomeSameAs:newHandle. "/ the old handle is now void |
|
2275 |
] |
|
303 | 2276 |
] |
2277 |
] ifFalse:[ |
|
306 | 2278 |
('OBJFLOADER: ignored invalid (obsolete) objectFile handle: ' , handle printString) infoPrintNL. |
303 | 2279 |
] |
2280 |
] |
|
2281 |
] |
|
2282 |
]. |
|
2283 |
PreviouslyLoadedObjects := nil |
|
2284 |
] |
|
2285 |
||
406
6a4f1e3800af
use new Method>>who interface
Claus Gittinger <cg@exept.de>
parents:
405
diff
changeset
|
2286 |
"Modified: 1.11.1996 / 16:28:50 / cg" |
303 | 2287 |
! |
2288 |
||
2289 |
rememberAllObjectFiles |
|
2290 |
"remember all loaded objectModules in the |
|
2291 |
PreviouslyLoadedObjects classVariable. |
|
2292 |
Called when an image is restarted to reload all modules which |
|
2293 |
were loaded in the previous life" |
|
2294 |
||
2295 |
LoadedObjects notNil ifTrue:[ |
|
2296 |
PreviouslyLoadedObjects := OrderedCollection new. |
|
2297 |
LoadedObjects keysAndValuesDo:[:name :handle | |
|
2298 |
handle isForCollectedObject ifTrue:[ |
|
2299 |
('OBJFLOADER: ignore object for already collected objects in ' , name) infoPrintNL |
|
2300 |
] ifFalse:[ |
|
2301 |
PreviouslyLoadedObjects add:(name -> handle) |
|
2302 |
] |
|
2303 |
]. |
|
2304 |
PreviouslyLoadedObjects sort:[:a :b | a value moduleID < b value moduleID]. |
|
2305 |
] |
|
2306 |
||
2307 |
"Created: 5.12.1995 / 20:51:07 / cg" |
|
2308 |
"Modified: 25.4.1996 / 09:46:08 / cg" |
|
2309 |
! |
|
2310 |
||
2311 |
revalidateAllObjectFiles |
|
2312 |
"revalidate code refs into all dynamically loaded object files. |
|
2313 |
Required after writing a snapshot image." |
|
2314 |
||
2315 |
ActuallyLoadedObjects notNil ifTrue:[ |
|
2316 |
ActuallyLoadedObjects keys do:[:aFileName | |
|
2317 |
|handle| |
|
2318 |
||
2319 |
handle := ActuallyLoadedObjects at:aFileName. |
|
2320 |
handle isNil ifTrue:[ |
|
2321 |
self error:'oops, no handle'. |
|
2322 |
] ifFalse:[ |
|
2323 |
(handle isClassLibHandle or:[handle isMethodHandle]) ifTrue:[ |
|
2324 |
self revalidateModule:handle |
|
2325 |
] |
|
2326 |
] |
|
2327 |
]. |
|
2328 |
LoadedObjects := ActuallyLoadedObjects. |
|
2329 |
ActuallyLoadedObjects := PreviouslyLoadedObjects := nil. |
|
28 | 2330 |
]. |
141 | 2331 |
|
303 | 2332 |
"Created: 5.10.1995 / 15:49:08 / claus" |
2333 |
"Modified: 5.10.1995 / 16:49:18 / claus" |
|
2334 |
"Modified: 12.7.1996 / 17:14:48 / cg" |
|
2335 |
! |
|
2336 |
||
2337 |
unloadAllObjectFiles |
|
2338 |
"unload all dynamically loaded object files from the image. |
|
2339 |
see DANGER ALERT in ObjectFileLoader>>unloadObjectFile:" |
|
2340 |
||
2341 |
LoadedObjects notNil ifTrue:[ |
|
2342 |
LoadedObjects keys copy do:[:aFileName | |
|
2343 |
self unloadObjectFile:aFileName |
|
2344 |
] |
|
2345 |
]. |
|
2346 |
||
2347 |
" |
|
2348 |
ObjectFileLoader unloadAllObjectFiles |
|
2349 |
" |
|
2350 |
! |
|
2351 |
||
2352 |
unloadAndRememberAllObjectFiles |
|
2353 |
"remember all modules and unload them" |
|
2354 |
||
2355 |
LoadedObjects notNil ifTrue:[ |
|
2356 |
self rememberAllObjectFiles. |
|
2357 |
self unloadAllObjectFiles |
|
2358 |
] |
|
2359 |
||
2360 |
"Modified: 25.4.1996 / 09:46:27 / cg" |
|
0 | 2361 |
! ! |
2362 |
||
369 | 2363 |
!ObjectFileLoader class methodsFor:'linking objects'! |
182
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
180
diff
changeset
|
2364 |
|
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
180
diff
changeset
|
2365 |
createLoadableObjectFor:baseFileName |
259 | 2366 |
"given an oFile, arrange for it to be loadable. |
2367 |
On ELF systems, this means that it has to be linked with the |
|
2368 |
-shared option into a .so file; |
|
2369 |
DLD based loaders (linux a.out) can directly load a .o file; |
|
2370 |
Other systems may require more ..." |
|
2371 |
||
322
a844e84b16fd
on aix: create an exports file when loading modules
Claus Gittinger <cg@exept.de>
parents:
321
diff
changeset
|
2372 |
|oFileName soFileName expFileName librunExpFileName |
a844e84b16fd
on aix: create an exports file when loading modules
Claus Gittinger <cg@exept.de>
parents:
321
diff
changeset
|
2373 |
needSharedObject ld ldArg expFile| |
320
54bfd6fd28b9
removed old obsolete manual loader; aix fixes
Claus Gittinger <cg@exept.de>
parents:
317
diff
changeset
|
2374 |
|
324 | 2375 |
ld := 'ld'. |
188 | 2376 |
needSharedObject := false. |
182
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
180
diff
changeset
|
2377 |
OperatingSystem getOSType = 'irix' ifTrue:[ |
259 | 2378 |
" |
2379 |
link it to a shared object with 'ld -shared' |
|
2380 |
" |
|
2381 |
needSharedObject := true. |
|
2382 |
ldArg := '-shared'. |
|
182
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
180
diff
changeset
|
2383 |
]. |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
180
diff
changeset
|
2384 |
|
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
180
diff
changeset
|
2385 |
OperatingSystem getOSType = 'sys5_4' ifTrue:[ |
259 | 2386 |
" |
2387 |
link it to a shared object with 'ld -G' |
|
2388 |
" |
|
2389 |
needSharedObject := true. |
|
2390 |
ldArg := '-G'. |
|
182
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
180
diff
changeset
|
2391 |
]. |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
180
diff
changeset
|
2392 |
|
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
180
diff
changeset
|
2393 |
OperatingSystem getOSType = 'linux' ifTrue:[ |
259 | 2394 |
ObjectFileLoader loadableBinaryObjectFormat == #elf ifTrue:[ |
2395 |
" |
|
2396 |
link it to a shared object with 'ld -shared' |
|
2397 |
" |
|
2398 |
needSharedObject := true. |
|
2399 |
ldArg := '-shared'. |
|
2400 |
] |
|
182
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
180
diff
changeset
|
2401 |
]. |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
180
diff
changeset
|
2402 |
|
320
54bfd6fd28b9
removed old obsolete manual loader; aix fixes
Claus Gittinger <cg@exept.de>
parents:
317
diff
changeset
|
2403 |
OperatingSystem getOSType = 'aix' ifTrue:[ |
322
a844e84b16fd
on aix: create an exports file when loading modules
Claus Gittinger <cg@exept.de>
parents:
321
diff
changeset
|
2404 |
"/ create an exports file. |
a844e84b16fd
on aix: create an exports file when loading modules
Claus Gittinger <cg@exept.de>
parents:
321
diff
changeset
|
2405 |
expFileName := './' , baseFileName , '.exp'. |
a844e84b16fd
on aix: create an exports file when loading modules
Claus Gittinger <cg@exept.de>
parents:
321
diff
changeset
|
2406 |
|
a844e84b16fd
on aix: create an exports file when loading modules
Claus Gittinger <cg@exept.de>
parents:
321
diff
changeset
|
2407 |
expFile := expFileName asFilename writeStream. |
a844e84b16fd
on aix: create an exports file when loading modules
Claus Gittinger <cg@exept.de>
parents:
321
diff
changeset
|
2408 |
expFile notNil ifTrue:[ |
a844e84b16fd
on aix: create an exports file when loading modules
Claus Gittinger <cg@exept.de>
parents:
321
diff
changeset
|
2409 |
expFile nextPutAll:'#!! ./' , baseFileName , '.so'. |
a844e84b16fd
on aix: create an exports file when loading modules
Claus Gittinger <cg@exept.de>
parents:
321
diff
changeset
|
2410 |
expFile cr. |
a844e84b16fd
on aix: create an exports file when loading modules
Claus Gittinger <cg@exept.de>
parents:
321
diff
changeset
|
2411 |
expFile nextPutAll:'_' , baseFileName , '_Init'. |
a844e84b16fd
on aix: create an exports file when loading modules
Claus Gittinger <cg@exept.de>
parents:
321
diff
changeset
|
2412 |
expFile close. |
a844e84b16fd
on aix: create an exports file when loading modules
Claus Gittinger <cg@exept.de>
parents:
321
diff
changeset
|
2413 |
]. |
a844e84b16fd
on aix: create an exports file when loading modules
Claus Gittinger <cg@exept.de>
parents:
321
diff
changeset
|
2414 |
|
320
54bfd6fd28b9
removed old obsolete manual loader; aix fixes
Claus Gittinger <cg@exept.de>
parents:
317
diff
changeset
|
2415 |
" |
54bfd6fd28b9
removed old obsolete manual loader; aix fixes
Claus Gittinger <cg@exept.de>
parents:
317
diff
changeset
|
2416 |
link it to a shared object with 'cc -bI:...librun.exp -bE -bMSRE' |
54bfd6fd28b9
removed old obsolete manual loader; aix fixes
Claus Gittinger <cg@exept.de>
parents:
317
diff
changeset
|
2417 |
" |
54bfd6fd28b9
removed old obsolete manual loader; aix fixes
Claus Gittinger <cg@exept.de>
parents:
317
diff
changeset
|
2418 |
needSharedObject := true. |
322
a844e84b16fd
on aix: create an exports file when loading modules
Claus Gittinger <cg@exept.de>
parents:
321
diff
changeset
|
2419 |
ld := 'cc'. |
a844e84b16fd
on aix: create an exports file when loading modules
Claus Gittinger <cg@exept.de>
parents:
321
diff
changeset
|
2420 |
librunExpFileName := Smalltalk getSystemFileName:'lib/librun_aix.exp'. |
a844e84b16fd
on aix: create an exports file when loading modules
Claus Gittinger <cg@exept.de>
parents:
321
diff
changeset
|
2421 |
librunExpFileName isNil ifTrue:[ |
a844e84b16fd
on aix: create an exports file when loading modules
Claus Gittinger <cg@exept.de>
parents:
321
diff
changeset
|
2422 |
LastError := 'missing exports file: ''lib/librun_aix.exp'' - cannot link'. |
a844e84b16fd
on aix: create an exports file when loading modules
Claus Gittinger <cg@exept.de>
parents:
321
diff
changeset
|
2423 |
^ nil |
a844e84b16fd
on aix: create an exports file when loading modules
Claus Gittinger <cg@exept.de>
parents:
321
diff
changeset
|
2424 |
]. |
a844e84b16fd
on aix: create an exports file when loading modules
Claus Gittinger <cg@exept.de>
parents:
321
diff
changeset
|
2425 |
|
a844e84b16fd
on aix: create an exports file when loading modules
Claus Gittinger <cg@exept.de>
parents:
321
diff
changeset
|
2426 |
ldArg := '-bI:' , librunExpFileName , |
a844e84b16fd
on aix: create an exports file when loading modules
Claus Gittinger <cg@exept.de>
parents:
321
diff
changeset
|
2427 |
' -bE:' , baseFileName , '.exp' , |
a844e84b16fd
on aix: create an exports file when loading modules
Claus Gittinger <cg@exept.de>
parents:
321
diff
changeset
|
2428 |
' -bM:SRE -e _' , baseFileName , '_Init'. |
320
54bfd6fd28b9
removed old obsolete manual loader; aix fixes
Claus Gittinger <cg@exept.de>
parents:
317
diff
changeset
|
2429 |
]. |
54bfd6fd28b9
removed old obsolete manual loader; aix fixes
Claus Gittinger <cg@exept.de>
parents:
317
diff
changeset
|
2430 |
|
188 | 2431 |
oFileName := './' , baseFileName , '.o'. |
182
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
180
diff
changeset
|
2432 |
needSharedObject ifTrue:[ |
259 | 2433 |
soFileName := './' , baseFileName , '.so'. |
2434 |
OperatingSystem executeCommand:'rm -f ' , soFileName. |
|
322
a844e84b16fd
on aix: create an exports file when loading modules
Claus Gittinger <cg@exept.de>
parents:
321
diff
changeset
|
2435 |
Verbose ifTrue:[ |
a844e84b16fd
on aix: create an exports file when loading modules
Claus Gittinger <cg@exept.de>
parents:
321
diff
changeset
|
2436 |
'linking with:' infoPrintCR. |
a844e84b16fd
on aix: create an exports file when loading modules
Claus Gittinger <cg@exept.de>
parents:
321
diff
changeset
|
2437 |
' ' infoPrint. |
a844e84b16fd
on aix: create an exports file when loading modules
Claus Gittinger <cg@exept.de>
parents:
321
diff
changeset
|
2438 |
(ld , ' ' , ldArg , ' -o ' , soFileName , ' ' , oFileName) infoPrintCR. |
a844e84b16fd
on aix: create an exports file when loading modules
Claus Gittinger <cg@exept.de>
parents:
321
diff
changeset
|
2439 |
]. |
320
54bfd6fd28b9
removed old obsolete manual loader; aix fixes
Claus Gittinger <cg@exept.de>
parents:
317
diff
changeset
|
2440 |
OperatingSystem executeCommand:ld , ' ' , ldArg , ' -o ' , soFileName , ' ' , oFileName. |
259 | 2441 |
OperatingSystem removeFile:oFileName. |
322
a844e84b16fd
on aix: create an exports file when loading modules
Claus Gittinger <cg@exept.de>
parents:
321
diff
changeset
|
2442 |
expFileName notNil ifTrue:[ |
a844e84b16fd
on aix: create an exports file when loading modules
Claus Gittinger <cg@exept.de>
parents:
321
diff
changeset
|
2443 |
OperatingSystem removeFile:expFileName |
a844e84b16fd
on aix: create an exports file when loading modules
Claus Gittinger <cg@exept.de>
parents:
321
diff
changeset
|
2444 |
]. |
259 | 2445 |
^ soFileName. |
182
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
180
diff
changeset
|
2446 |
]. |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
180
diff
changeset
|
2447 |
|
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
180
diff
changeset
|
2448 |
" |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
180
diff
changeset
|
2449 |
assume we can load an ordinary binary |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
180
diff
changeset
|
2450 |
" |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
180
diff
changeset
|
2451 |
^ oFileName |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
180
diff
changeset
|
2452 |
|
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
180
diff
changeset
|
2453 |
"Created: 3.1.1996 / 16:04:45 / cg" |
322
a844e84b16fd
on aix: create an exports file when loading modules
Claus Gittinger <cg@exept.de>
parents:
321
diff
changeset
|
2454 |
"Modified: 29.7.1996 / 13:20:30 / cg" |
182
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
180
diff
changeset
|
2455 |
! ! |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
180
diff
changeset
|
2456 |
|
369 | 2457 |
!ObjectFileLoader class methodsFor:'queries'! |
141 | 2458 |
|
2459 |
canLoadObjectFiles |
|
259 | 2460 |
"return true, if dynamic loading is possible. |
2461 |
Currently, only ELF based systems and linux a.out can do this." |
|
141 | 2462 |
|
2463 |
self primCanLoadObjectFiles ifTrue:[^true]. |
|
2464 |
||
2465 |
"/ can add a return true here, if I ever get manual loading to work |
|
2466 |
"/ for some specific machine |
|
2467 |
^ false |
|
259 | 2468 |
|
2469 |
"Modified: 25.4.1996 / 09:51:39 / cg" |
|
141 | 2470 |
! |
2471 |
||
2472 |
loadedObjectFiles |
|
2473 |
"return a collection containing the names of all |
|
2474 |
dynamically loaded objects." |
|
2475 |
||
2476 |
LoadedObjects isNil ifTrue:[^ #()]. |
|
2477 |
^ LoadedObjects keys copy |
|
2478 |
||
2479 |
" |
|
2480 |
ObjectFileLoader loadedObjectFiles |
|
2481 |
" |
|
2482 |
! |
|
2483 |
||
2484 |
loadedObjectHandles |
|
2485 |
"return a collection of all handles" |
|
2486 |
||
2487 |
LoadedObjects isNil ifTrue:[^ #()]. |
|
2488 |
^ LoadedObjects |
|
2489 |
||
2490 |
" |
|
2491 |
ObjectFileLoader loadedObjectHandles |
|
2492 |
" |
|
2493 |
||
2494 |
"Created: 17.9.1995 / 14:28:55 / claus" |
|
2495 |
"Modified: 17.9.1995 / 16:13:48 / claus" |
|
2496 |
! |
|
2497 |
||
2498 |
loadedObjectHandlesDo:aBlock |
|
2499 |
"enumerate all handles" |
|
2500 |
||
2501 |
LoadedObjects notNil ifTrue:[ |
|
2502 |
LoadedObjects copy do:aBlock. |
|
2503 |
]. |
|
2504 |
||
2505 |
" |
|
2506 |
ObjectFileLoader loadedObjectHandlesDo:[:h | h pathName printNL] |
|
2507 |
" |
|
2508 |
||
2509 |
"Created: 14.9.1995 / 22:03:13 / claus" |
|
2510 |
"Modified: 14.9.1995 / 22:32:48 / claus" |
|
2511 |
! |
|
2512 |
||
2513 |
pathNameFromID:id |
|
2514 |
"given an id, return the pathName, or nil for static modules" |
|
2515 |
||
2516 |
LoadedObjects notNil ifTrue:[ |
|
2517 |
LoadedObjects keysAndValuesDo:[:name :handle | |
|
2518 |
handle moduleID == id ifTrue:[ |
|
2519 |
^ handle pathName |
|
2520 |
] |
|
2521 |
]. |
|
2522 |
]. |
|
2523 |
^ nil |
|
2524 |
||
2525 |
" |
|
2526 |
ObjectFileLoader pathNameFromID:1 |
|
2527 |
" |
|
2528 |
||
2529 |
"Modified: 28.8.1995 / 18:08:28 / claus" |
|
2530 |
! |
|
2531 |
||
2532 |
primCanLoadObjectFiles |
|
2533 |
"return true, if loading is possible using a standard mechanism" |
|
2534 |
%{ /* NOCONTEXT */ |
|
2535 |
#ifdef HAS_DL |
|
2536 |
# if !defined(OS_DEFINE) || defined(unknownOS) |
|
2537 |
fprintf(stderr, "*** OS_DEFINE not correct\n"); |
|
2538 |
# else |
|
2539 |
# if !defined(CPU_DEFINE) || defined(unknownCPU) |
|
2540 |
fprintf(stderr, "*** CPU_DEFINE not correct\n"); |
|
2541 |
# else |
|
2542 |
RETURN (true); |
|
2543 |
# endif |
|
2544 |
# endif |
|
2545 |
#endif |
|
2546 |
%}. |
|
2547 |
^ false |
|
20 | 2548 |
! ! |
2549 |
||
369 | 2550 |
!ObjectFileLoader class methodsFor:'st object file handling'! |
303 | 2551 |
|
2552 |
callInitFunctionAt:address specialInit:special forceOld:forceOld interruptable:interruptable argument:argument identifyAs:handle returnsObject:returnsObject |
|
2553 |
"call a function at address - a very dangerous operation. |
|
2554 |
This is needed to call the classes init-function after loading in a |
|
2555 |
class-object file or to call the CTORS when c++ modules are loaded. |
|
2556 |
ForceOld (if true) will have the memory manager |
|
2557 |
allocate things in oldSpace instead of newSpace. |
|
2558 |
If special is true, this is a smalltalk moduleInit (i.e. pass the vm-entries table); |
|
2559 |
otherwise, its called without arguments. |
|
2560 |
If its a smalltalk-moduleInit, it may be either for a classPackage (which should |
|
2561 |
install all of its classes) or for a single incrementally compiled methdod |
|
2562 |
(it should then NOT install it, but return the method object instead). |
|
2563 |
||
2564 |
DANGER: Internal & highly specialized. Dont use in your programs. |
|
307
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2565 |
This interface may change without notice." |
303 | 2566 |
|
320
54bfd6fd28b9
removed old obsolete manual loader; aix fixes
Claus Gittinger <cg@exept.de>
parents:
317
diff
changeset
|
2567 |
|moduleID retVal| |
54bfd6fd28b9
removed old obsolete manual loader; aix fixes
Claus Gittinger <cg@exept.de>
parents:
317
diff
changeset
|
2568 |
|
303 | 2569 |
handle notNil ifTrue:[ |
307
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2570 |
moduleID := handle moduleID |
303 | 2571 |
]. |
320
54bfd6fd28b9
removed old obsolete manual loader; aix fixes
Claus Gittinger <cg@exept.de>
parents:
317
diff
changeset
|
2572 |
|
303 | 2573 |
%{ /* CALLSSTACK: 32000 */ |
2574 |
OBJ (*addr)(); |
|
2575 |
unsigned val; |
|
2576 |
int savInt; |
|
2577 |
int prevSpace, force; |
|
307
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2578 |
int arg = 0, ret = 0; |
303 | 2579 |
int wasBlocked = 1; |
2580 |
extern int __oldSpaceSize(), __oldSpaceUsed(); |
|
2581 |
||
320
54bfd6fd28b9
removed old obsolete manual loader; aix fixes
Claus Gittinger <cg@exept.de>
parents:
317
diff
changeset
|
2582 |
if (__isInteger(address)) { |
307
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2583 |
if (_isSmallInteger(argument)) { |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2584 |
arg = __intVal(argument); |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2585 |
|
320
54bfd6fd28b9
removed old obsolete manual loader; aix fixes
Claus Gittinger <cg@exept.de>
parents:
317
diff
changeset
|
2586 |
val = (unsigned)(__longIntVal(address)); |
307
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2587 |
addr = (OBJFUNC) val; |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2588 |
|
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2589 |
/* |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2590 |
* allow function to be interrupted |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2591 |
*/ |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2592 |
if (interruptable != true) { |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2593 |
wasBlocked = (__BLOCKINTERRUPTS() == true); |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2594 |
} |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2595 |
|
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2596 |
force = (forceOld == true); |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2597 |
if (force) { |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2598 |
if ((__oldSpaceSize() - __oldSpaceUsed()) < (256*1024)) { |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2599 |
__moreOldSpace(__thisContext, 256*1024); |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2600 |
} |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2601 |
prevSpace = __allocForceSpace(OLDSPACE); |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2602 |
} |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2603 |
|
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2604 |
if (special == true) { |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2605 |
if (__isSmallInteger(moduleID)) { |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2606 |
__SET_MODULE_ID(__intVal(moduleID)); |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2607 |
} |
345
3727b0b6f62f
removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents:
339
diff
changeset
|
2608 |
retVal = (*addr)(arg, __pRT__); |
307
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2609 |
__SET_MODULE_ID(0); |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2610 |
if (returnsObject != true) { |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2611 |
retVal = nil; |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2612 |
} |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2613 |
} else { |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2614 |
if (returnsObject == true) { |
345
3727b0b6f62f
removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents:
339
diff
changeset
|
2615 |
retVal = (*addr)(arg); |
307
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2616 |
} else { |
345
3727b0b6f62f
removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents:
339
diff
changeset
|
2617 |
ret = (int) ((*addr)(arg)); |
307
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2618 |
retVal = __MKSMALLINT(ret); |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2619 |
} |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2620 |
} |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2621 |
|
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2622 |
if (force) { |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2623 |
__allocForceSpace(prevSpace); |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2624 |
} |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2625 |
|
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2626 |
if (! wasBlocked) { |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2627 |
__UNBLOCKINTERRUPTS(); |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2628 |
} |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2629 |
RETURN (retVal); |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2630 |
} |
303 | 2631 |
} |
2632 |
%}. |
|
2633 |
self primitiveFailed |
|
2634 |
! |
|
2635 |
||
2636 |
deinitializeClassesFromModule:handle |
|
307
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2637 |
"send #deinitialize and an #aboutToUnload notification |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2638 |
to all classes of a module." |
303 | 2639 |
|
2640 |
|classes| |
|
2641 |
||
2642 |
classes := handle classes. |
|
2643 |
classes notNil ifTrue:[ |
|
307
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2644 |
classes do:[:aClass | |
339 | 2645 |
aClass notNil ifTrue:[ |
2646 |
aClass isMeta ifFalse:[ |
|
2647 |
Verbose ifTrue:[ |
|
2648 |
'send #deinitialize to:' infoPrint. aClass name infoPrintNL. |
|
2649 |
]. |
|
2650 |
aClass deinitialize. |
|
2651 |
aClass update:#aboutToUnload with:nil from:self |
|
2652 |
] |
|
307
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2653 |
] |
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2654 |
] |
303 | 2655 |
] |
307
2552fd5e8592
give cModule a chance to signal failure (return -1 from __Init);
Claus Gittinger <cg@exept.de>
parents:
306
diff
changeset
|
2656 |
|
339 | 2657 |
"Modified: 12.9.1996 / 08:07:28 / cg" |
303 | 2658 |
! |
2659 |
||
2660 |
invalidateModule:handle |
|
2661 |
"invalidate all of the classes code objects ..." |
|
2662 |
||
2663 |
|id| |
|
2664 |
||
2665 |
Verbose ifTrue:[ |
|
2666 |
'invalidate module; name=' infoPrint. handle pathName infoPrint. |
|
2667 |
' id=' infoPrint. handle moduleID infoPrintNL. |
|
2668 |
]. |
|
2669 |
||
2670 |
id := handle moduleID. |
|
2671 |
%{ |
|
2672 |
__INVALIDATE_BY_ID(__intVal(id)); |
|
2673 |
%} |
|
2674 |
! |
|
2675 |
||
2676 |
loadStatusFor:className |
|
2677 |
"ask VM if class-hierarchy has been completely loaded, and return the status." |
|
2678 |
||
2679 |
|checker checkSymbol statusCode status badClassName| |
|
2680 |
||
2681 |
checker := self. |
|
2682 |
checkSymbol := #'superClassCheck:'. |
|
2683 |
||
2684 |
%{ /* NOREGISTER */ |
|
2685 |
char *badName; |
|
365
22c85186e799
Fix misspelled "interrest" to "interest".
Stefan Vogel <sv@exept.de>
parents:
346
diff
changeset
|
2686 |
char *interestingClassName; |
303 | 2687 |
|
2688 |
if (__isString(className) || __isSymbol(className)) { |
|
365
22c85186e799
Fix misspelled "interrest" to "interest".
Stefan Vogel <sv@exept.de>
parents:
346
diff
changeset
|
2689 |
interestingClassName = __stringVal(className); |
303 | 2690 |
} else { |
365
22c85186e799
Fix misspelled "interrest" to "interest".
Stefan Vogel <sv@exept.de>
parents:
346
diff
changeset
|
2691 |
interestingClassName = (char *)0; |
303 | 2692 |
} |
365
22c85186e799
Fix misspelled "interrest" to "interest".
Stefan Vogel <sv@exept.de>
parents:
346
diff
changeset
|
2693 |
statusCode = __MKSMALLINT(__check_registration__(interestingClassName, |
303 | 2694 |
&checker, &checkSymbol, &badName)); |
2695 |
if (badName) { |
|
2696 |
badClassName = __MKSTRING(badName); |
|
2697 |
} |
|
2698 |
%}. |
|
2699 |
statusCode == 0 ifTrue:[ |
|
2700 |
status := #ok |
|
2701 |
] ifFalse:[ |
|
2702 |
statusCode == -1 ifTrue:[ |
|
2703 |
status := #missingClass |
|
2704 |
] ifFalse:[ |
|
2705 |
statusCode == -2 ifTrue:[ |
|
2706 |
status := #versionMismatch |
|
2707 |
] ifFalse:[ |
|
2708 |
statusCode == -3 ifTrue:[ |
|
2709 |
status := #unregisteredSuperclass |
|
2710 |
] ifFalse:[ |
|
2711 |
status := #loadFailed |
|
2712 |
] |
|
2713 |
] |
|
2714 |
] |
|
2715 |
]. |
|
2716 |
^ Array with:status with:badClassName. |
|
2717 |
! |
|
2718 |
||
2719 |
moduleInit:phase forceOld:forceOld interruptable:interruptable |
|
2720 |
"initialization phases after registration. |
|
2721 |
DANGER: Pure magic; internal only -> dont use in your programs." |
|
2722 |
||
2723 |
%{ |
|
2724 |
int savInt; |
|
2725 |
int prevSpace, force; |
|
2726 |
int arg = 0; |
|
2727 |
int wasBlocked = 1; |
|
2728 |
||
2729 |
if (_isSmallInteger(phase)) { |
|
2730 |
if (interruptable != true) { |
|
2731 |
wasBlocked = (__BLOCKINTERRUPTS() == true); |
|
2732 |
} |
|
2733 |
||
2734 |
force = (forceOld == true); |
|
2735 |
if (force) { |
|
2736 |
prevSpace = __allocForceSpace(OLDSPACE); |
|
2737 |
} |
|
2738 |
||
345
3727b0b6f62f
removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents:
339
diff
changeset
|
2739 |
__init_registered_modules__(__intVal(phase)); |
303 | 2740 |
|
2741 |
if (force) { |
|
2742 |
__allocForceSpace(prevSpace); |
|
2743 |
} |
|
2744 |
||
2745 |
if (! wasBlocked) { |
|
2746 |
__UNBLOCKINTERRUPTS(); |
|
2747 |
} |
|
2748 |
RETURN (self); |
|
2749 |
} |
|
2750 |
%}. |
|
2751 |
self primitiveFailed |
|
2752 |
! |
|
2753 |
||
2754 |
performModuleInitAt:initAddr for:className identifyAs:handle |
|
2755 |
"Initialize a loaded smalltalk module." |
|
2756 |
||
2757 |
|status badClassName infoCollection info classNames classes| |
|
2758 |
||
2759 |
" |
|
2760 |
need 4 passes to init: 0: let module register itself & create its pools/globals |
|
2761 |
0b check if modules superclasses are all loaded |
|
2762 |
1: let it get var-refs to other pools/globals |
|
2763 |
2: let it install install class, methods and literals |
|
2764 |
3: let it send #initialize to its class object |
|
2765 |
" |
|
2766 |
||
2767 |
"/ |
|
2768 |
"/ let it register itself |
|
2769 |
"/ and define its globals |
|
2770 |
"/ |
|
2771 |
Verbose ifTrue:[ |
|
2772 |
'phase 0 ...' infoPrintNL |
|
2773 |
]. |
|
2774 |
self callInitFunctionAt:initAddr |
|
2775 |
specialInit:true |
|
2776 |
forceOld:true |
|
2777 |
interruptable:false |
|
2778 |
argument:0 |
|
2779 |
identifyAs:handle |
|
2780 |
returnsObject:false. |
|
2781 |
||
2782 |
"/ |
|
2783 |
"/ check if superclasses are present |
|
2784 |
"/ |
|
2785 |
info := self loadStatusFor:className. |
|
2786 |
status := info at:1. |
|
2787 |
badClassName := info at:2. |
|
2788 |
||
2789 |
Verbose ifTrue:[ |
|
2790 |
'... status is ' infoPrint. info infoPrintNL |
|
2791 |
]. |
|
2792 |
||
2793 |
(status ~~ #ok) ifTrue:[ |
|
2794 |
(status == #missingClass) ifTrue:[ |
|
2795 |
Transcript showCR:'load failed - missing class: ' , badClassName. |
|
2796 |
^ info |
|
2797 |
]. |
|
2798 |
(status == #versionMismatch) ifTrue:[ |
|
2799 |
Transcript showCR:'load failed - version mismatch: ' , badClassName. |
|
2800 |
^ info |
|
2801 |
]. |
|
2802 |
(status == #unregisteredSuperclass) ifTrue:[ |
|
2803 |
Transcript showCR:'load failed - unregistered: ' , badClassName. |
|
2804 |
^ info |
|
2805 |
]. |
|
2806 |
Transcript showCR:'load failed'. |
|
2807 |
^ Array with:#loadFailed with:nil |
|
2808 |
]. |
|
2809 |
||
2810 |
"/ |
|
2811 |
"/ remaining initialization |
|
2812 |
"/ |
|
2813 |
Verbose ifTrue:[ |
|
2814 |
'phase 1 ...' infoPrintNL |
|
2815 |
]. |
|
2816 |
self moduleInit:1 forceOld:true interruptable:false. |
|
2817 |
||
2818 |
Verbose ifTrue:[ |
|
2819 |
'phase 2 ...' infoPrintNL |
|
2820 |
]. |
|
2821 |
self moduleInit:2 forceOld:true interruptable:false. |
|
2822 |
||
2823 |
Verbose ifTrue:[ |
|
2824 |
'phase 3 ...' infoPrintNL |
|
2825 |
]. |
|
2826 |
ObjectMemory flushCaches. |
|
2827 |
self moduleInit:3 forceOld:false interruptable:true. |
|
2828 |
||
2829 |
"/ ask objectMemory for the classes we have just loaded |
|
2830 |
"/ and register them in the handle |
|
2831 |
||
2832 |
infoCollection := ObjectMemory binaryModuleInfo. |
|
2833 |
info := infoCollection at:handle moduleID ifAbsent:nil. |
|
2834 |
info isNil ifTrue:[ |
|
2835 |
"/ mhmh registration failed - |
|
2836 |
^ Array with:#registrationFailed with:nil |
|
2837 |
]. |
|
2838 |
||
405
92cb91b82cf7
changes for new moduleInfo reply
Claus Gittinger <cg@exept.de>
parents:
404
diff
changeset
|
2839 |
classNames := info classNames. |
303 | 2840 |
classNames size > 0 ifTrue:[ |
2841 |
classes := classNames collect:[:nm | Smalltalk classNamed:nm]. |
|
2842 |
]. |
|
2843 |
classes size > 0 ifTrue:[ |
|
2844 |
classes := classes asArray. |
|
2845 |
classes := classes , (classes collect:[:aClass | aClass class]). |
|
2846 |
]. |
|
2847 |
handle classes:classes. |
|
2848 |
||
2849 |
^ Array with:#ok with:nil |
|
2850 |
||
405
92cb91b82cf7
changes for new moduleInfo reply
Claus Gittinger <cg@exept.de>
parents:
404
diff
changeset
|
2851 |
"Modified: 31.10.1996 / 14:02:35 / cg" |
303 | 2852 |
! |
2853 |
||
2854 |
revalidateModule:handle |
|
2855 |
"revalidate all of the classes code objects ..." |
|
2856 |
||
2857 |
|id| |
|
2858 |
||
2859 |
Verbose ifTrue:[ |
|
2860 |
'revalidate module; name=' infoPrint. handle pathName infoPrint. |
|
2861 |
' id=' infoPrint. handle moduleID infoPrintNL. |
|
2862 |
]. |
|
2863 |
||
2864 |
id := handle moduleID. |
|
2865 |
%{ |
|
2866 |
__REVALIDATE_BY_ID(__intVal(id)); |
|
2867 |
%} |
|
2868 |
! |
|
2869 |
||
2870 |
superClassCheck:aClass |
|
320
54bfd6fd28b9
removed old obsolete manual loader; aix fixes
Claus Gittinger <cg@exept.de>
parents:
317
diff
changeset
|
2871 |
"callBack from class registration code in VM: |
54bfd6fd28b9
removed old obsolete manual loader; aix fixes
Claus Gittinger <cg@exept.de>
parents:
317
diff
changeset
|
2872 |
make certain, that aClass is loaded too ... |
54bfd6fd28b9
removed old obsolete manual loader; aix fixes
Claus Gittinger <cg@exept.de>
parents:
317
diff
changeset
|
2873 |
(req'd if a subclass of an autoloaded class has been loaded)" |
303 | 2874 |
|
2875 |
Verbose ifTrue:[ |
|
2876 |
'checkCall for:' infoPrint. aClass name infoPrint. ' -> ' infoPrint. |
|
2877 |
]. |
|
2878 |
aClass isBehavior ifFalse:[ |
|
2879 |
Verbose ifTrue:[ |
|
2880 |
'false' infoPrintNL. |
|
2881 |
]. |
|
2882 |
'LOADER: check failed - no behavior' infoPrintNL. |
|
2883 |
^ false |
|
2884 |
]. |
|
2885 |
Verbose ifTrue:[ |
|
2886 |
'true' infoPrintNL. |
|
2887 |
]. |
|
2888 |
('LOADER: check for ' , aClass name , ' being loaded') infoPrintNL. |
|
2889 |
aClass autoload. |
|
2890 |
(aClass isBehavior and:[aClass isLoaded]) ifTrue:[ |
|
2891 |
('LOADER: ok, loaded. continue registration of actual class') infoPrintNL. |
|
2892 |
aClass signature. "/ req'd in VM for validation |
|
2893 |
^ true |
|
2894 |
]. |
|
2895 |
('LOADER: nope - not loaded. fail registration of actual class') infoPrintNL. |
|
2896 |
^ false |
|
2897 |
! |
|
2898 |
||
2899 |
unregisterModule:handle |
|
2900 |
"unregister classes in the VM. |
|
2901 |
This invalidates all of the classes code objects ..." |
|
2902 |
||
2903 |
|id| |
|
2904 |
||
2905 |
Verbose ifTrue:[ |
|
2906 |
'unregister module; name=' infoPrint. handle pathName infoPrint. |
|
2907 |
' id=' infoPrint. handle moduleID infoPrintNL. |
|
2908 |
]. |
|
2909 |
||
2910 |
id := handle moduleID. |
|
2911 |
%{ |
|
2912 |
__UNREGISTER_BY_ID(__intVal(id)); |
|
2913 |
%} |
|
2914 |
! ! |
|
2915 |
||
369 | 2916 |
!ObjectFileLoader class methodsFor:'documentation'! |
148 | 2917 |
|
2918 |
version |
|
409 | 2919 |
^ '$Header: /cvs/stx/stx/libcomp/Attic/ObjFLoader.st,v 1.121 1996-11-04 23:14:30 cg Exp $' |
148 | 2920 |
! ! |
0 | 2921 |
ObjectFileLoader initialize! |