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