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