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