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