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