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