ObjectFileLoader.st
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--
on sunos: link dynamic objects against libc.a for unresolved symbols.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
     1
"
7ad01559b262 Initial revision
claus
parents:
diff changeset
     2
 COPYRIGHT (c) 1993 by Claus Gittinger
45
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
     3
	      All Rights Reserved
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
     4
7ad01559b262 Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
7ad01559b262 Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
7ad01559b262 Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
7ad01559b262 Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
7ad01559b262 Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
7ad01559b262 Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
7ad01559b262 Initial revision
claus
parents:
diff changeset
    11
"
7ad01559b262 Initial revision
claus
parents:
diff changeset
    12
7ad01559b262 Initial revision
claus
parents:
diff changeset
    13
Object subclass:#ObjectFileLoader
174
3be731572be7 prints replaced by infoPrint
Claus Gittinger <cg@exept.de>
parents: 160
diff changeset
    14
	instanceVariableNames:''
3be731572be7 prints replaced by infoPrint
Claus Gittinger <cg@exept.de>
parents: 160
diff changeset
    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
3be731572be7 prints replaced by infoPrint
Claus Gittinger <cg@exept.de>
parents: 160
diff changeset
    18
	poolDictionaries:''
3be731572be7 prints replaced by infoPrint
Claus Gittinger <cg@exept.de>
parents: 160
diff changeset
    19
	category:'System-Compiler'
47
f861ad42703e *** empty log message ***
claus
parents: 45
diff changeset
    20
!
f861ad42703e *** empty log message ***
claus
parents: 45
diff changeset
    21
53
c5dd7abf8431 *** empty log message ***
claus
parents: 51
diff changeset
    22
!ObjectFileLoader primitiveDefinitions!
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
    23
%{
15
992c3d87edbf *** empty log message ***
claus
parents: 10
diff changeset
    24
/*
992c3d87edbf *** empty log message ***
claus
parents: 10
diff changeset
    25
 * by default, use whatever the system provides
992c3d87edbf *** empty log message ***
claus
parents: 10
diff changeset
    26
 */
95
claus
parents: 94
diff changeset
    27
#ifdef sunos    /* sunos (pre 5.4) dlopen interface */
15
992c3d87edbf *** empty log message ***
claus
parents: 10
diff changeset
    28
# define SUN_DL
20
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    29
# define HAS_DL
15
992c3d87edbf *** empty log message ***
claus
parents: 10
diff changeset
    30
#endif
992c3d87edbf *** empty log message ***
claus
parents: 10
diff changeset
    31
95
claus
parents: 94
diff changeset
    32
#ifdef NeXT     /* next rld interface */
15
992c3d87edbf *** empty log message ***
claus
parents: 10
diff changeset
    33
# define NEXT_DL
20
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    34
# define HAS_DL
15
992c3d87edbf *** empty log message ***
claus
parents: 10
diff changeset
    35
#endif
992c3d87edbf *** empty log message ***
claus
parents: 10
diff changeset
    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
992c3d87edbf *** empty log message ***
claus
parents: 10
diff changeset
    38
# define SYSV4_DL
20
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    39
# define HAS_DL
15
992c3d87edbf *** empty log message ***
claus
parents: 10
diff changeset
    40
#endif
992c3d87edbf *** empty log message ***
claus
parents: 10
diff changeset
    41
95
claus
parents: 94
diff changeset
    42
#ifdef DL1_6    /* dl1.6 COFF loader */
claus
parents: 94
diff changeset
    43
# define HAS_DL
claus
parents: 94
diff changeset
    44
#endif
claus
parents: 94
diff changeset
    45
98
claus
parents: 97
diff changeset
    46
#ifdef _AIX
97
claus
parents: 96
diff changeset
    47
# define AIX_DL
claus
parents: 96
diff changeset
    48
# define HAS_DL
claus
parents: 96
diff changeset
    49
#endif
claus
parents: 96
diff changeset
    50
15
992c3d87edbf *** empty log message ***
claus
parents: 10
diff changeset
    51
/*
20
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    52
 * but GNU_DL overwrites this - its better
15
992c3d87edbf *** empty log message ***
claus
parents: 10
diff changeset
    53
 */
95
claus
parents: 94
diff changeset
    54
#ifdef GNU_DL   /* dld2.3.x interface */
20
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    55
# define HAS_DL
15
992c3d87edbf *** empty log message ***
claus
parents: 10
diff changeset
    56
# undef SYSV4_DL
992c3d87edbf *** empty log message ***
claus
parents: 10
diff changeset
    57
# undef NEXT_DL
992c3d87edbf *** empty log message ***
claus
parents: 10
diff changeset
    58
# undef SUN_DL
95
claus
parents: 94
diff changeset
    59
# undef DL1_6
15
992c3d87edbf *** empty log message ***
claus
parents: 10
diff changeset
    60
#endif
992c3d87edbf *** empty log message ***
claus
parents: 10
diff changeset
    61
20
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    62
#include <stdio.h>
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    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
a38d34ef8bde dynamic load works on NT !
Claus Gittinger <cg@exept.de>
parents: 178
diff changeset
    68
# define HAS_DL
a38d34ef8bde dynamic load works on NT !
Claus Gittinger <cg@exept.de>
parents: 178
diff changeset
    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
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    72
/*
95
claus
parents: 94
diff changeset
    73
 * if no dynamic link facilities, try it the hard way ...
20
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    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
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    76
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    77
# ifdef A_DOT_OUT
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    78
#  include <a.out.h>
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    79
#  ifndef N_MAGIC
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    80
#   if defined(sinix) && defined(BSD)
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    81
#    define N_MAGIC(hdr) (hdr.a_magic & 0xFFFF)
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    82
#   else
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    83
#    define N_MAGIC(hdr) (hdr.a_magic)
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    84
#   endif
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    85
#  endif
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    86
# endif /* a.out */
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    87
 
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    88
# ifdef COFF
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    89
#  ifdef mips
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    90
#    include <sys/exec.h>
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    91
#  else
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    92
#    include <a.out.h>
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    93
#  endif
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    94
# endif /* coff */
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    95
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    96
# ifdef ELF
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    97
#  include <elf.h>
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    98
# endif /* elf */
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    99
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
   100
#endif /* not HAS_DL */
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
   101
95
claus
parents: 94
diff changeset
   102
#ifdef NEXT_DL
claus
parents: 94
diff changeset
   103
# ifndef _RLD_H_
claus
parents: 94
diff changeset
   104
#  define _RLD_H_
125
Claus Gittinger <cg@exept.de>
parents: 124
diff changeset
   105
#  ifdef NEXT3
Claus Gittinger <cg@exept.de>
parents: 124
diff changeset
   106
#   include <mach-o/rld.h>
Claus Gittinger <cg@exept.de>
parents: 124
diff changeset
   107
#  else
Claus Gittinger <cg@exept.de>
parents: 124
diff changeset
   108
#   include <rld.h>
Claus Gittinger <cg@exept.de>
parents: 124
diff changeset
   109
#  endif
95
claus
parents: 94
diff changeset
   110
# endif
claus
parents: 94
diff changeset
   111
#endif /* NEXT_DL */
claus
parents: 94
diff changeset
   112
28
a9d33ea0692d loads objces on iris5
claus
parents: 20
diff changeset
   113
#ifdef SYSV4_DL
a9d33ea0692d loads objces on iris5
claus
parents: 20
diff changeset
   114
# include <dlfcn.h>
a9d33ea0692d loads objces on iris5
claus
parents: 20
diff changeset
   115
# define dlcfn_h
a9d33ea0692d loads objces on iris5
claus
parents: 20
diff changeset
   116
#endif
a9d33ea0692d loads objces on iris5
claus
parents: 20
diff changeset
   117
45
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
   118
#ifdef GNU_DL
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
   119
#  ifndef dld_h
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
   120
#   include "dld.h"
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
   121
#   define dld_h
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
   122
#  endif
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
   123
#endif
95
claus
parents: 94
diff changeset
   124
claus
parents: 94
diff changeset
   125
#ifdef DL1_6
claus
parents: 94
diff changeset
   126
#  ifndef dl_h
claus
parents: 94
diff changeset
   127
#   include "dl.h"
claus
parents: 94
diff changeset
   128
#   define dl_h
claus
parents: 94
diff changeset
   129
#  endif
claus
parents: 94
diff changeset
   130
#endif
claus
parents: 94
diff changeset
   131
97
claus
parents: 96
diff changeset
   132
#ifdef AIX_DL
claus
parents: 96
diff changeset
   133
# include <nlist.h>
100
claus
parents: 98
diff changeset
   134
# include <sys/ldr.h>
claus
parents: 98
diff changeset
   135
# include <errno.h>
97
claus
parents: 96
diff changeset
   136
#endif
180
a38d34ef8bde dynamic load works on NT !
Claus Gittinger <cg@exept.de>
parents: 178
diff changeset
   137
a38d34ef8bde dynamic load works on NT !
Claus Gittinger <cg@exept.de>
parents: 178
diff changeset
   138
#ifdef WIN_DL
a38d34ef8bde dynamic load works on NT !
Claus Gittinger <cg@exept.de>
parents: 178
diff changeset
   139
a38d34ef8bde dynamic load works on NT !
Claus Gittinger <cg@exept.de>
parents: 178
diff changeset
   140
# ifdef WIN32
a38d34ef8bde dynamic load works on NT !
Claus Gittinger <cg@exept.de>
parents: 178
diff changeset
   141
#   undef INT
a38d34ef8bde dynamic load works on NT !
Claus Gittinger <cg@exept.de>
parents: 178
diff changeset
   142
#   undef Array
a38d34ef8bde dynamic load works on NT !
Claus Gittinger <cg@exept.de>
parents: 178
diff changeset
   143
#   undef Number
a38d34ef8bde dynamic load works on NT !
Claus Gittinger <cg@exept.de>
parents: 178
diff changeset
   144
#   undef Method
a38d34ef8bde dynamic load works on NT !
Claus Gittinger <cg@exept.de>
parents: 178
diff changeset
   145
a38d34ef8bde dynamic load works on NT !
Claus Gittinger <cg@exept.de>
parents: 178
diff changeset
   146
#   ifdef i386
a38d34ef8bde dynamic load works on NT !
Claus Gittinger <cg@exept.de>
parents: 178
diff changeset
   147
#    define _X86_
a38d34ef8bde dynamic load works on NT !
Claus Gittinger <cg@exept.de>
parents: 178
diff changeset
   148
#   endif
a38d34ef8bde dynamic load works on NT !
Claus Gittinger <cg@exept.de>
parents: 178
diff changeset
   149
a38d34ef8bde dynamic load works on NT !
Claus Gittinger <cg@exept.de>
parents: 178
diff changeset
   150
/* #  include <windows.h> /* */
a38d34ef8bde dynamic load works on NT !
Claus Gittinger <cg@exept.de>
parents: 178
diff changeset
   151
#  include <windef.h> /* */
a38d34ef8bde dynamic load works on NT !
Claus Gittinger <cg@exept.de>
parents: 178
diff changeset
   152
#  include <winbase.h> /* */
a38d34ef8bde dynamic load works on NT !
Claus Gittinger <cg@exept.de>
parents: 178
diff changeset
   153
208
346c1e056231 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 201
diff changeset
   154
#   ifdef __DEF_Array
346c1e056231 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 201
diff changeset
   155
#    define Array __DEF_Array
180
a38d34ef8bde dynamic load works on NT !
Claus Gittinger <cg@exept.de>
parents: 178
diff changeset
   156
#   endif
208
346c1e056231 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 201
diff changeset
   157
#   ifdef __DEF_Number
346c1e056231 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 201
diff changeset
   158
#    define Number __DEF_Number
180
a38d34ef8bde dynamic load works on NT !
Claus Gittinger <cg@exept.de>
parents: 178
diff changeset
   159
#   endif
208
346c1e056231 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 201
diff changeset
   160
#   ifdef __DEF_Method
346c1e056231 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 201
diff changeset
   161
#    define Method __DEF_Method
180
a38d34ef8bde dynamic load works on NT !
Claus Gittinger <cg@exept.de>
parents: 178
diff changeset
   162
#   endif
a38d34ef8bde dynamic load works on NT !
Claus Gittinger <cg@exept.de>
parents: 178
diff changeset
   163
# endif
a38d34ef8bde dynamic load works on NT !
Claus Gittinger <cg@exept.de>
parents: 178
diff changeset
   164
a38d34ef8bde dynamic load works on NT !
Claus Gittinger <cg@exept.de>
parents: 178
diff changeset
   165
#endif
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   166
%}
20
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
   167
! !
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
   168
291
c0d5159014be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 286
diff changeset
   169
!ObjectFileLoader  class methodsFor:'documentation'!
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   170
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   171
copyright
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   172
"
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   173
 COPYRIGHT (c) 1993 by Claus Gittinger
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   174
	      All Rights Reserved
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   175
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   176
 This software is furnished under a license and may be used
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   177
 only in accordance with the terms of that license and with the
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   178
 inclusion of the above copyright notice.   This software may not
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   179
 be provided or otherwise made available to, or used by, any
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   180
 other person.  No title to or ownership of the software is
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   181
 hereby transferred.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   182
"
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   183
!
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   184
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   185
documentation
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   186
"
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   187
    This class knowns how to dynamically load in external object-modules.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   188
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   189
    WARNING:
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   190
      As to date, this is completely experimental and WITHOUT ANY WARRANTY.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   191
      It is still being developed and the code below needs cleanup and more
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   192
      robustness.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   193
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   194
    There are basically two totally different mechanisms to do this:
263
3b21d0991eff documentation
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   195
        a) if there exists some dynamic-link facility such as:
3b21d0991eff documentation
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   196
           GNU-DL, dlopen (sparc, SYS5.4), rld_open (NeXT),
3b21d0991eff documentation
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   197
           this is used
3b21d0991eff documentation
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   198
        b) if no such facility exists, the normal linker is used to
3b21d0991eff documentation
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   199
           link the module to text/data address as previously malloced,
3b21d0991eff documentation
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   200
           and the object file loaded into that space.
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   201
           
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   202
    Currently, not all mechanisms work fully satisfying.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   203
    For example, the sun dl*-functions do an exit on link-errors (which
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   204
    is certainly not what we want here :-(; the NeXT mechanism does not
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   205
    allow for selective unloading (only all or last).
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   206
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   207
    The only really useful packages are the GNU-dl package and the SGI/Unixware
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   208
    sys5.4 libdl packages. 
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   209
    The GNU-dl package is only available for a.out file formats; 
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   210
    i.e. only (a subset of) linux people can use it at this time.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   211
    For the above reasons, dynamic object loading is currently only
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   212
    officially released for SYS5.4 and LINUX systems.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   213
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   214
    Once stable, the functionality contained herein will be moved into
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   215
    the VM. 
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   216
    (It is needed there, to allow reloading of objectfiles upon
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   217
     image restart; i.e. before any class is reinitialilized).
263
3b21d0991eff documentation
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   218
3b21d0991eff documentation
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   219
    [author:]
3b21d0991eff documentation
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   220
        Claus Gittinger
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   221
"
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   222
! !
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   223
291
c0d5159014be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 286
diff changeset
   224
!ObjectFileLoader  class methodsFor:'initialization'!
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   225
7ad01559b262 Initial revision
claus
parents:
diff changeset
   226
initialize
7ad01559b262 Initial revision
claus
parents:
diff changeset
   227
201
66bd5f9c781c only init once
Claus Gittinger <cg@exept.de>
parents: 198
diff changeset
   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
66bd5f9c781c only init once
Claus Gittinger <cg@exept.de>
parents: 198
diff changeset
   263
    ]
107
claus
parents: 106
diff changeset
   264
claus
parents: 106
diff changeset
   265
    "
claus
parents: 106
diff changeset
   266
     ObjectFileLoader initialize
claus
parents: 106
diff changeset
   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
7ad01559b262 Initial revision
claus
parents:
diff changeset
   270
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
   271
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   272
lastError
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   273
    ^ LastError
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   274
!
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   275
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   276
linkErrorMessage
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   277
    ^ LinkErrorMessage
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   278
!
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   279
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   280
searchedLibraries
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   281
    "see comment in #searchedLibraries:"
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   282
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   283
    ^ SearchedLibraries
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   284
!
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   285
125
Claus Gittinger <cg@exept.de>
parents: 124
diff changeset
   286
searchedLibraries:aCollectionOfArchivePathNames
Claus Gittinger <cg@exept.de>
parents: 124
diff changeset
   287
    "set the pathnames of archives which are to be searched
Claus Gittinger <cg@exept.de>
parents: 124
diff changeset
   288
     when unresolved references occur while loading in an object
Claus Gittinger <cg@exept.de>
parents: 124
diff changeset
   289
     file. On systems which support shared libraries (all SYS5.4 based
Claus Gittinger <cg@exept.de>
parents: 124
diff changeset
   290
     systems), this is usually not required. Instead, modules which are to
Claus Gittinger <cg@exept.de>
parents: 124
diff changeset
   291
     be filed in (.so files) are to be prelinked with the appropriate
Claus Gittinger <cg@exept.de>
parents: 124
diff changeset
   292
     shared libraries. The dynamic loader then cares about loading those
Claus Gittinger <cg@exept.de>
parents: 124
diff changeset
   293
     modules (keeping track of which modules are already loaded).
Claus Gittinger <cg@exept.de>
parents: 124
diff changeset
   294
     Only systems in which the dynamic load is done 'manually' by st/x
Claus Gittinger <cg@exept.de>
parents: 124
diff changeset
   295
     (i.e. currently only linux) need to set this."
Claus Gittinger <cg@exept.de>
parents: 124
diff changeset
   296
Claus Gittinger <cg@exept.de>
parents: 124
diff changeset
   297
    SearchedLibraries := aCollectionOfArchivePathNames
Claus Gittinger <cg@exept.de>
parents: 124
diff changeset
   298
!
Claus Gittinger <cg@exept.de>
parents: 124
diff changeset
   299
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   300
verbose:aBoolean
7ad01559b262 Initial revision
claus
parents:
diff changeset
   301
    "turn on/off debug traces"
7ad01559b262 Initial revision
claus
parents:
diff changeset
   302
10
73e97b6175c4 *** empty log message ***
claus
parents: 6
diff changeset
   303
    Verbose := aBoolean
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   304
7ad01559b262 Initial revision
claus
parents:
diff changeset
   305
    "ObjectFileLoader verbose:true"
7ad01559b262 Initial revision
claus
parents:
diff changeset
   306
! !
7ad01559b262 Initial revision
claus
parents:
diff changeset
   307
291
c0d5159014be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 286
diff changeset
   308
!ObjectFileLoader  class methodsFor:'change & update'!
c0d5159014be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 286
diff changeset
   309
c0d5159014be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 286
diff changeset
   310
update:something with:aParameter from:changedObject
107
claus
parents: 106
diff changeset
   311
    "sent, when image is saved or restarted"
claus
parents: 106
diff changeset
   312
claus
parents: 106
diff changeset
   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
Claus Gittinger <cg@exept.de>
parents: 124
diff changeset
   315
    ].
Claus Gittinger <cg@exept.de>
parents: 124
diff changeset
   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
claus
parents: 106
diff changeset
   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
Claus Gittinger <cg@exept.de>
parents: 124
diff changeset
   322
Claus Gittinger <cg@exept.de>
parents: 124
diff changeset
   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
c0d5159014be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 286
diff changeset
   325
    "Created: 21.6.1996 / 19:50:01 / cg"
107
claus
parents: 106
diff changeset
   326
! !
claus
parents: 106
diff changeset
   327
291
c0d5159014be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 286
diff changeset
   328
!ObjectFileLoader  class methodsFor:'defaults'!
115
claus
parents: 114
diff changeset
   329
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   330
absLd:file text:textAddr
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   331
   "this should return a string to link file.o to absolute address.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   332
    This is only needed if no dynamic-link facilitiy exists."
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   333
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   334
    |os cpu|
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   335
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   336
    os := OperatingSystem getSystemType.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   337
    cpu := OperatingSystem getCPUType.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   338
    (os = 'sunos') ifTrue:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   339
	(cpu = 'sparc') ifTrue:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   340
	    ^ ('ld -A ' , MySymbolTable , ' -T ',
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   341
			  (textAddr printStringRadix:16),
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   342
			  ' -N -x ' , file)
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   343
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   344
	]
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   345
    ].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   346
    self error:'do not know how to link absolute'
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   347
!
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   348
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   349
absLd:file text:textAddr data:dataAddr
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   350
   "this should return a string to link file.o to absolute address.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   351
    This is only needed if no dynamic-link facilitiy exists."
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   352
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   353
    |os cpu|
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   354
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   355
    os := OperatingSystem getSystemType.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   356
    cpu := OperatingSystem getCPUType.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   357
    (os = 'sunos') ifTrue:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   358
	(cpu = 'sparc') ifTrue:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   359
" "
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   360
	    ^ ('ld -A ' , MySymbolTable , ' -x -Bstatic' ,
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   361
	       ' -Ttext ' , (textAddr printStringRadix:16) , 
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   362
	       ' -Tdata ' , (dataAddr printStringRadix:16) , ' ' , file)
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   363
" "
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   364
"
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   365
	    ^ ('ld -A ' , MySymbolTable , ' -T ',
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   366
			  (textAddr printStringRadix:16),
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   367
			  ' -N -x ' , file)
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   368
"
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   369
	]
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   370
    ].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   371
"
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   372
    (os = 'ultrix') ifTrue:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   373
	(cpu = 'mips') ifTrue:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   374
	    ^ ('ld -A ' , MySymbolTable , ' -x -N -T ' , (textAddr printStringRadix:16) , ' ' , file)
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   375
	]
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   376
    ].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   377
"
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   378
    self error:'do not know how to link absolute'
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   379
!
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   380
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   381
hasValidBinaryExtension:aFilename
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   382
    "return true, if aFilename looks ok for binary loading.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   383
     This checks only the extension - not its contents. 
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   384
     (So an attempt to load the file may fail due to format errors or unresolved symbols)
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   385
     This is very machine specific."
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   386
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   387
    self validBinaryExtensions do:[:ext |
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   388
	(aFilename endsWith:ext) ifTrue:[^ true].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   389
    ].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   390
    ^ false
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   391
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   392
    "
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   393
     ObjectFileLoader hasValidBinaryExtension:'foo.st'
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   394
     ObjectFileLoader hasValidBinaryExtension:'foo.o'
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   395
     ObjectFileLoader hasValidBinaryExtension:'foo.so'
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   396
    "
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   397
!
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   398
188
fef1879d2fcf linux-a.out fixes
ca
parents: 183
diff changeset
   399
loadableBinaryObjectFormat
fef1879d2fcf linux-a.out fixes
ca
parents: 183
diff changeset
   400
    "return a symbol describing the expected binary format
fef1879d2fcf linux-a.out fixes
ca
parents: 183
diff changeset
   401
     for object files to be loadable.
fef1879d2fcf linux-a.out fixes
ca
parents: 183
diff changeset
   402
     This is very machine specific."
fef1879d2fcf linux-a.out fixes
ca
parents: 183
diff changeset
   403
fef1879d2fcf linux-a.out fixes
ca
parents: 183
diff changeset
   404
%{  /* NOCONTEXT */
fef1879d2fcf linux-a.out fixes
ca
parents: 183
diff changeset
   405
#ifdef HAS_DL
fef1879d2fcf linux-a.out fixes
ca
parents: 183
diff changeset
   406
# if defined(SYSV4) || defined(ELF)
fef1879d2fcf linux-a.out fixes
ca
parents: 183
diff changeset
   407
    RETURN ( @symbol(elf));
fef1879d2fcf linux-a.out fixes
ca
parents: 183
diff changeset
   408
# endif
fef1879d2fcf linux-a.out fixes
ca
parents: 183
diff changeset
   409
# if defined(GNU_DL)
fef1879d2fcf linux-a.out fixes
ca
parents: 183
diff changeset
   410
    RETURN ( @symbol(aout));
fef1879d2fcf linux-a.out fixes
ca
parents: 183
diff changeset
   411
# endif
fef1879d2fcf linux-a.out fixes
ca
parents: 183
diff changeset
   412
# if defined(AIX_DL)
fef1879d2fcf linux-a.out fixes
ca
parents: 183
diff changeset
   413
    RETURN ( @symbol(xcoff));
fef1879d2fcf linux-a.out fixes
ca
parents: 183
diff changeset
   414
# endif
fef1879d2fcf linux-a.out fixes
ca
parents: 183
diff changeset
   415
# if defined(DL1_6)
fef1879d2fcf linux-a.out fixes
ca
parents: 183
diff changeset
   416
    RETURN ( @symbol(coff));
fef1879d2fcf linux-a.out fixes
ca
parents: 183
diff changeset
   417
# endif
fef1879d2fcf linux-a.out fixes
ca
parents: 183
diff changeset
   418
# if defined(WIN_DL)
fef1879d2fcf linux-a.out fixes
ca
parents: 183
diff changeset
   419
    RETURN ( @symbol(dll));
fef1879d2fcf linux-a.out fixes
ca
parents: 183
diff changeset
   420
# endif
fef1879d2fcf linux-a.out fixes
ca
parents: 183
diff changeset
   421
#endif
fef1879d2fcf linux-a.out fixes
ca
parents: 183
diff changeset
   422
%}.
fef1879d2fcf linux-a.out fixes
ca
parents: 183
diff changeset
   423
    ^ nil
fef1879d2fcf linux-a.out fixes
ca
parents: 183
diff changeset
   424
fef1879d2fcf linux-a.out fixes
ca
parents: 183
diff changeset
   425
    "
fef1879d2fcf linux-a.out fixes
ca
parents: 183
diff changeset
   426
     ObjectFileLoader loadableBinaryObjectFormat
fef1879d2fcf linux-a.out fixes
ca
parents: 183
diff changeset
   427
    "
fef1879d2fcf linux-a.out fixes
ca
parents: 183
diff changeset
   428
!
fef1879d2fcf linux-a.out fixes
ca
parents: 183
diff changeset
   429
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   430
needSeparateIDSpaces
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   431
    "return true, if we need separate I and D spaces.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   432
     This is only needed if no dynamic-link facilitiy exists."
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   433
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   434
    |os cpu|
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   435
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   436
    os := OperatingSystem getSystemType.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   437
    cpu := OperatingSystem getCPUType.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   438
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   439
    (os = 'sunos') ifTrue:[
225
122d8ff18aff nicer message
Claus Gittinger <cg@exept.de>
parents: 222
diff changeset
   440
        (cpu = 'sparc') ifTrue:[ ^ true ]
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   441
    ].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   442
225
122d8ff18aff nicer message
Claus Gittinger <cg@exept.de>
parents: 222
diff changeset
   443
    'LOADER: dont know if we need sepId - assume no' errorPrintNL.
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   444
    ^ false
225
122d8ff18aff nicer message
Claus Gittinger <cg@exept.de>
parents: 222
diff changeset
   445
122d8ff18aff nicer message
Claus Gittinger <cg@exept.de>
parents: 222
diff changeset
   446
    "Modified: 7.3.1996 / 19:20:08 / cg"
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   447
!
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   448
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   449
nm:file
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   450
   "this should return a string to list the namelist of file"
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   451
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   452
    |os|
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   453
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   454
    os := OperatingSystem getSystemType.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   455
    (os = 'iris') ifTrue:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   456
	^ 'nm -B ' , file
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   457
    ].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   458
    ^ 'nm ' , file
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   459
!
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   460
115
claus
parents: 114
diff changeset
   461
sharedLibraryExtension
claus
parents: 114
diff changeset
   462
    "return a fileName extension used for dynamic loadable objects.
claus
parents: 114
diff changeset
   463
     This is very machine specific."
claus
parents: 114
diff changeset
   464
claus
parents: 114
diff changeset
   465
    |os|
claus
parents: 114
diff changeset
   466
claus
parents: 114
diff changeset
   467
    os := OperatingSystem getSystemType.
125
Claus Gittinger <cg@exept.de>
parents: 124
diff changeset
   468
    (os = 'sys5_4') ifTrue:[^ '.so'].
115
claus
parents: 114
diff changeset
   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
claus
parents: 114
diff changeset
   476
    (os = 'aix') ifTrue:[^ '.so'].
claus
parents: 114
diff changeset
   477
    (os = 'hpux') ifTrue:[^ '.sl'].
180
a38d34ef8bde dynamic load works on NT !
Claus Gittinger <cg@exept.de>
parents: 178
diff changeset
   478
    (os = 'win32') ifTrue:[^ '.dll'].
115
claus
parents: 114
diff changeset
   479
    (os = 'os2') ifTrue:[^ '.dll'].
119
claus
parents: 118
diff changeset
   480
claus
parents: 118
diff changeset
   481
    "/ mhmh what is a useful default ?
claus
parents: 118
diff changeset
   482
claus
parents: 118
diff changeset
   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
claus
parents: 114
diff changeset
   486
!
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   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
a38d34ef8bde dynamic load works on NT !
Claus Gittinger <cg@exept.de>
parents: 178
diff changeset
   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
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   510
! !
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   511
291
c0d5159014be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 286
diff changeset
   512
!ObjectFileLoader  class methodsFor:'dynamic class loading'!
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   513
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   514
loadCPlusPlusObjectFile:aFileName
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   515
    "load a c++ object file (.o-file) into the image"
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   516
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   517
    |handle initAddr list|
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   518
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   519
    handle := self loadDynamicObject:aFileName.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   520
    handle isNil ifTrue:[
272
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   521
        Transcript showCR:('loadDynamic: ',aFileName,' failed.').
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   522
        ^ nil
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   523
    ].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   524
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   525
    list := self namesMatching:'__GLOBAL_$I*' segment:'[tT]' in:aFileName.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   526
list size == 1 ifTrue:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   527
"/    (self isCPlusPlusObject:handle) ifTrue:[
272
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   528
        Verbose ifTrue:[
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   529
            'a c++ object file' infoPrintNL.
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   530
        ].
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   531
        "
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   532
         what I would like to get is the CTOR_LIST,
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   533
         and call each function.
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   534
         But dld cannot (currently) handle SET-type symbols, therefore
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   535
         we search (using nm) for all __GLOBAL_$I* syms, get their values
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   536
         and call them each
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   537
        "
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   538
"/        list := self namesMatching:'__GLOBAL_$I*' segment:'[tT]' in:aFileName.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   539
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   540
"/        initAddr := self getFunction:'__CTOR_LIST__' from:handle.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   541
"/        Verbose ifTrue:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   542
"/            ('calling CTORs at:' , (initAddr printStringRadix:16)) infoPrintNL
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   543
"/        ].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   544
272
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   545
        initAddr := self getFunction:list first from:handle.
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   546
        initAddr isNil ifTrue:[
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   547
            "
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   548
             try with added underscore
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   549
            "
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   550
            initAddr := self getFunction:('_' , list first) from:handle.
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   551
        ].
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   552
        (initAddr isNil and:[list first startsWith:'_']) ifTrue:[
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   553
            "
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   554
             try with removed underscore
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   555
            "
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   556
            initAddr := self getFunction:(list first copyFrom:2) from:handle.
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   557
        ].
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   558
        initAddr isNil ifTrue:[
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   559
            Verbose ifTrue:[
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   560
                ('no CTOR-func found (' , list first , ')') infoPrintNL.
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   561
            ].
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   562
            self unloadDynamicObject:aFileName.
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   563
            ^ nil
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   564
        ].
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   565
        Verbose ifTrue:[
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   566
            ('calling CTORs at:' , (initAddr printStringRadix:16)) infoPrintNL
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   567
        ].
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   568
        self callInitFunctionAt:initAddr 
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   569
             specialInit:false 
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   570
             forceOld:false 
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   571
             interruptable:false
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   572
             argument:0
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   573
             identifyAs:nil
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   574
             returnsObject:false.
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   575
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   576
        Verbose ifTrue:[
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   577
            'done with CTORs.' infoPrintNL
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   578
        ].
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   579
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   580
        "
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   581
         cannot create a CPlusPlus class automatically (there could be more than
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   582
         one classes in it too ...)
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   583
        "
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   584
        ^ handle
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   585
    ].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   586
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   587
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   588
    Verbose ifTrue:[
272
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   589
        'unknown object file' infoPrintNL
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   590
    ].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   591
    self unloadDynamicObject:aFileName.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   592
    ^ nil
272
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   593
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   594
    "Modified: 18.5.1996 / 15:43:50 / cg"
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   595
!
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   596
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   597
loadClass:aClassName fromObjectFile:aFileName
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   598
    "load a compiled class (.o-file) into the image"
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   599
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   600
    |handle initAddr symName newClass list moreHandles info status 
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   601
     otherClass knownToBeOk|
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   602
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   603
    handle := self loadDynamicObject:aFileName.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   604
    handle isNil ifTrue:[
272
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   605
        Transcript showCR:('loadDynamic: ', aFileName,' failed.').
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   606
        ^ nil
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   607
    ].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   608
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   609
    "
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   610
     get the Init-function; let the class install itself
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   611
    "
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   612
    symName := '_' , aClassName , '_Init'.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   613
    initAddr := self getFunction:symName from:handle.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   614
    initAddr isNil ifTrue:[
272
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   615
        "try with added underscore"
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   616
        symName := '__' , aClassName , '_Init'.
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   617
        initAddr := self getFunction:symName from:handle.
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   618
        initAddr isNil ifTrue:[
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   619
            "try with added period (AIX)"
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   620
            symName := '._' , aClassName , '_Init'.
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   621
            initAddr := self getFunction:symName from:handle.
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   622
        ]
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   623
    ].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   624
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   625
    knownToBeOk := true.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   626
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   627
"/    knownToBeOk ifFalse:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   628
"/        Verbose ifTrue:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   629
"/            'looking for undefs ...' infoPrintNL.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   630
"/        ].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   631
"/
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   632
"/        "
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   633
"/         if there are any undefined symbols, we may have to load more
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   634
"/         files (libs, other modules)
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   635
"/        "
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   636
"/        list := self getListOfUndefinedSymbolsFrom:handle.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   637
"/        list notNil ifTrue:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   638
"/            moreHandles := self loadModulesFromListOfUndefined:list.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   639
"/
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   640
"/            "
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   641
"/             now, try again
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   642
"/            "
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   643
"/            symName := '_' , aClassName , '_Init'.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   644
"/            initAddr := self getFunction:symName from:handle.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   645
"/            initAddr isNil ifTrue:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   646
"/                "try with added underscore"
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   647
"/                symName := '__' , aClassName , '_Init'.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   648
"/                initAddr := self getFunction:symName from:handle.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   649
"/            ].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   650
"/        ]
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   651
"/    ].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   652
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   653
    initAddr notNil ifTrue:[
272
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   654
        Verbose ifTrue:[
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   655
            ('calling init at: ' , (initAddr printStringRadix:16)) infoPrintNL.
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   656
        ].
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   657
        info := self performModuleInitAt:initAddr for:aClassName identifyAs:handle.
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   658
        status := info at:1.
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   659
        "
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   660
         if any classes are missing ...
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   661
        "
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   662
        (status == #missingClass) ifTrue:[
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   663
            "
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   664
             ... and we are loading a module ...
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   665
            "
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   666
            Transcript showCR:'try for missing class in same object ...'.
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   667
            Verbose ifTrue:[
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   668
                'try for missing class:' infoPrint. (info at:2) infoPrintNL.
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   669
            ].
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   670
            otherClass := self loadClass:(info at:2) fromObjectFile:aFileName.
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   671
            otherClass notNil ifTrue:[
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   672
                "
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   673
                 try again ...
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   674
                "
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   675
                Transcript showCR:'missing class is here; try again ...'.
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   676
                info := self performModuleInitAt:initAddr for:aClassName identifyAs:handle.
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   677
                status := info at:1.
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   678
            ]
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   679
        ].
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   680
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   681
        Verbose ifTrue:[
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   682
            'done init status=' infoPrint. info infoPrintNL.
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   683
        ].
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   684
        (status == #unregisteredSuperclass) ifTrue:[
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   685
            Transcript showCR:'superclass is not registered'.
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   686
        ].
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   687
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   688
        (Symbol hasInterned:aClassName) ifTrue:[
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   689
            newClass := Smalltalk at:aClassName asSymbol ifAbsent:[nil].
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   690
            Verbose ifTrue:[
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   691
                'newClass is: ' infoPrint. newClass infoPrintNL
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   692
            ].
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   693
            newClass notNil ifTrue:[
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   694
                Verbose ifTrue:[
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   695
                    'initialize newClass ...' infoPrintNL
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   696
                ].
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   697
                newClass initialize.
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   698
                "force cache flush"
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   699
                Smalltalk at:aClassName asSymbol put:newClass.
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   700
                Smalltalk isInitialized ifTrue:[
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   701
                    Smalltalk changed.
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   702
                ]
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   703
            ].
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   704
        ] ifFalse:[
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   705
            'LOADER: class ' errorPrint. aClassName errorPrint.
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   706
            ' did not define itself' errorPrintNL
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   707
            "
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   708
             do not unload - could have installed other classes/methods ...
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   709
            "
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   710
        ].
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   711
        ^ newClass
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   712
    ].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   713
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   714
    Verbose ifTrue:[
272
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   715
        ('no symbol: ', symName,' in ',aFileName) infoPrintNL.
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   716
    ].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   717
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   718
    "
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   719
     unload
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   720
    "
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   721
    Verbose ifTrue:[
272
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   722
        'unloading due to init failure:' infoPrint. handle pathName infoPrintNL.
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   723
    ].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   724
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   725
    moreHandles notNil ifTrue:[
272
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   726
        moreHandles do:[:aHandle |
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   727
            Verbose ifTrue:[
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   728
                ('unloading: ', aHandle printString) infoPrintNL.
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   729
            ].
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   730
            self unloadDynamicObject:handle.
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   731
        ]
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   732
    ].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   733
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   734
    Verbose ifTrue:[
272
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   735
        ('unloading: ', handle printString) infoPrintNL.
134
d93682ca90a1 more queries for valid objectfilenames
Claus Gittinger <cg@exept.de>
parents: 130
diff changeset
   736
    ].
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   737
    self unloadDynamicObject:handle.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   738
    ^ nil
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   739
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   740
    "
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   741
     ObjectFileLoader loadClass:'Tetris'      fromObjectFile:'../clients/Tetris/Tetris.o'
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   742
     ObjectFileLoader loadClass:'TetrisBlock' fromObjectFile:'../clients/Tetris/TBlock.o'
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   743
     ObjectFileLoader loadClass:'Foo'         fromObjectFile:'classList.o'
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   744
    "
272
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   745
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   746
    "Modified: 18.5.1996 / 15:45:35 / cg"
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   747
!
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   748
174
3be731572be7 prints replaced by infoPrint
Claus Gittinger <cg@exept.de>
parents: 160
diff changeset
   749
loadMethodObjectFile:aFileName
3be731572be7 prints replaced by infoPrint
Claus Gittinger <cg@exept.de>
parents: 160
diff changeset
   750
    "load an object file (.o-file) for a single method into the image; 
3be731572be7 prints replaced by infoPrint
Claus Gittinger <cg@exept.de>
parents: 160
diff changeset
   751
     This does a slightly different initialization.
3be731572be7 prints replaced by infoPrint
Claus Gittinger <cg@exept.de>
parents: 160
diff changeset
   752
     Return an object handle; nil on error"
3be731572be7 prints replaced by infoPrint
Claus Gittinger <cg@exept.de>
parents: 160
diff changeset
   753
3be731572be7 prints replaced by infoPrint
Claus Gittinger <cg@exept.de>
parents: 160
diff changeset
   754
    |handle initAddr initName idx m|
3be731572be7 prints replaced by infoPrint
Claus Gittinger <cg@exept.de>
parents: 160
diff changeset
   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
3be731572be7 prints replaced by infoPrint
Claus Gittinger <cg@exept.de>
parents: 160
diff changeset
   759
    handle := self loadDynamicObject:aFileName.
3be731572be7 prints replaced by infoPrint
Claus Gittinger <cg@exept.de>
parents: 160
diff changeset
   760
    handle isNil ifTrue:[
225
122d8ff18aff nicer message
Claus Gittinger <cg@exept.de>
parents: 222
diff changeset
   761
        ^ nil
174
3be731572be7 prints replaced by infoPrint
Claus Gittinger <cg@exept.de>
parents: 160
diff changeset
   762
    ].
3be731572be7 prints replaced by infoPrint
Claus Gittinger <cg@exept.de>
parents: 160
diff changeset
   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
3be731572be7 prints replaced by infoPrint
Claus Gittinger <cg@exept.de>
parents: 160
diff changeset
   768
3be731572be7 prints replaced by infoPrint
Claus Gittinger <cg@exept.de>
parents: 160
diff changeset
   769
    initAddr := self getFunction:'__' , initName , '_Init' from:handle.
3be731572be7 prints replaced by infoPrint
Claus Gittinger <cg@exept.de>
parents: 160
diff changeset
   770
    initAddr isNil ifTrue:[
225
122d8ff18aff nicer message
Claus Gittinger <cg@exept.de>
parents: 222
diff changeset
   771
        initAddr := ObjectFileLoader getFunction:'_' , initName , '_Init' from:handle.
122d8ff18aff nicer message
Claus Gittinger <cg@exept.de>
parents: 222
diff changeset
   772
        initAddr isNil ifTrue:[
122d8ff18aff nicer message
Claus Gittinger <cg@exept.de>
parents: 222
diff changeset
   773
            (self getListOfUndefinedSymbolsFrom:handle) size > 0 ifTrue:[
122d8ff18aff nicer message
Claus Gittinger <cg@exept.de>
parents: 222
diff changeset
   774
                self listUndefinedSymbolsIn:handle.
122d8ff18aff nicer message
Claus Gittinger <cg@exept.de>
parents: 222
diff changeset
   775
                'LOADER: undefined symbols in primitive code' infoPrintNL.
122d8ff18aff nicer message
Claus Gittinger <cg@exept.de>
parents: 222
diff changeset
   776
            ] ifFalse:[
122d8ff18aff nicer message
Claus Gittinger <cg@exept.de>
parents: 222
diff changeset
   777
                ('LOADER: ' , initName , '_Init() lookup failed') errorPrintNL
122d8ff18aff nicer message
Claus Gittinger <cg@exept.de>
parents: 222
diff changeset
   778
            ].
122d8ff18aff nicer message
Claus Gittinger <cg@exept.de>
parents: 222
diff changeset
   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
122d8ff18aff nicer message
Claus Gittinger <cg@exept.de>
parents: 222
diff changeset
   783
            self unloadDynamicObject:handle.
122d8ff18aff nicer message
Claus Gittinger <cg@exept.de>
parents: 222
diff changeset
   784
            ^ nil
122d8ff18aff nicer message
Claus Gittinger <cg@exept.de>
parents: 222
diff changeset
   785
        ]
174
3be731572be7 prints replaced by infoPrint
Claus Gittinger <cg@exept.de>
parents: 160
diff changeset
   786
    ].
3be731572be7 prints replaced by infoPrint
Claus Gittinger <cg@exept.de>
parents: 160
diff changeset
   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
3be731572be7 prints replaced by infoPrint
Claus Gittinger <cg@exept.de>
parents: 160
diff changeset
   791
    m := self
225
122d8ff18aff nicer message
Claus Gittinger <cg@exept.de>
parents: 222
diff changeset
   792
        callInitFunctionAt:initAddr 
122d8ff18aff nicer message
Claus Gittinger <cg@exept.de>
parents: 222
diff changeset
   793
        specialInit:true
122d8ff18aff nicer message
Claus Gittinger <cg@exept.de>
parents: 222
diff changeset
   794
        forceOld:true 
122d8ff18aff nicer message
Claus Gittinger <cg@exept.de>
parents: 222
diff changeset
   795
        interruptable:false
122d8ff18aff nicer message
Claus Gittinger <cg@exept.de>
parents: 222
diff changeset
   796
        argument:2
122d8ff18aff nicer message
Claus Gittinger <cg@exept.de>
parents: 222
diff changeset
   797
        identifyAs:handle
122d8ff18aff nicer message
Claus Gittinger <cg@exept.de>
parents: 222
diff changeset
   798
        returnsObject:true.
174
3be731572be7 prints replaced by infoPrint
Claus Gittinger <cg@exept.de>
parents: 160
diff changeset
   799
3be731572be7 prints replaced by infoPrint
Claus Gittinger <cg@exept.de>
parents: 160
diff changeset
   800
    handle method:m.
3be731572be7 prints replaced by infoPrint
Claus Gittinger <cg@exept.de>
parents: 160
diff changeset
   801
    ^ handle
3be731572be7 prints replaced by infoPrint
Claus Gittinger <cg@exept.de>
parents: 160
diff changeset
   802
3be731572be7 prints replaced by infoPrint
Claus Gittinger <cg@exept.de>
parents: 160
diff changeset
   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
3be731572be7 prints replaced by infoPrint
Claus Gittinger <cg@exept.de>
parents: 160
diff changeset
   805
!
3be731572be7 prints replaced by infoPrint
Claus Gittinger <cg@exept.de>
parents: 160
diff changeset
   806
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   807
loadModulesFromListOfUndefined:list
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   808
    "try to figure out what has to be loaded to resolve symbols from list.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   809
     return a list of handles of loaded objects
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   810
    "
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   811
    |inits classNames|
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   812
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   813
    inits := list select:[:symbol | symbol notNil and:[symbol endsWith:'_Init']].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   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
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   841
    ].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   842
    ^ nil
174
3be731572be7 prints replaced by infoPrint
Claus Gittinger <cg@exept.de>
parents: 160
diff changeset
   843
3be731572be7 prints replaced by infoPrint
Claus Gittinger <cg@exept.de>
parents: 160
diff changeset
   844
    "Modified: 17.12.1995 / 16:00:27 / cg"
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   845
!
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   846
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   847
loadObjectFile:aFileName
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   848
    "load an object file (.o-file) into the image; 
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   849
     the class name is not needed (multiple definitions may be in the file).
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   850
     Return false on error, true if ok."
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   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
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   854
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   855
    handle := self loadDynamicObject:aFileName.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   856
    handle isNil ifTrue:[
272
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   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
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   859
    ].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   860
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   861
    didInit := false.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   862
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   863
    "/ with dld, load may have worked, even if undefined symbols
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   864
    "/ are to be resolved. If thats the case, load all libraries ...
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   865
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   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
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   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
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   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
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   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
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   882
    ].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   883
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   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
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   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
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   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
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   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
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   957
    ].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   958
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   959
    didInit ifFalse:[
228
be9939d96cfe removed a wrong debug message
Claus Gittinger <cg@exept.de>
parents: 227
diff changeset
   960
        status == #registrationFailed ifTrue:[
272
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   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
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   979
    ].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   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
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   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
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   990
!
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   991
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   992
unloadAllObsoleteObjectFiles
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   993
    "unload all dynamically loaded object files for which the classes/method
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   994
     has been already garbage collected."
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   995
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
   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
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  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
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1004
	]
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1005
    ].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1006
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1007
    "
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  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
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1014
unloadObjectFile:aFileName
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1015
    "unload an object file (.o-file) from the image.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1016
     DANGER ALERT: currently, you have to make sure that no references to
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1017
     objects of this module exist - in future versions, the system will keep
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1018
     track of these. For now, use at your own risk.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1019
     (especially critical are blocks-functions)."
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1020
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1021
    |handle|
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1022
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1023
    LoadedObjects notNil ifTrue:[
153
90df8e05815c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1024
	handle := LoadedObjects at:aFileName ifAbsent:nil
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1025
    ].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1026
    handle isNil ifTrue:[
153
90df8e05815c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1027
	'OBJFLOADER: oops file to be unloaded was not loaded dynamically (', aFileName , ')'.
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1028
	^ self
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1029
    ].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1030
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1031
    "/ call the modules deInit-function ...
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1032
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1033
    "/ unload ...
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1034
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1035
    self unloadDynamicObject:handle
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1036
! !
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1037
291
c0d5159014be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 286
diff changeset
  1038
!ObjectFileLoader  class methodsFor:'dynamic object access'!
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  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
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1085
getFunction:aString from:handle
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1086
    "return the address of a function from a dynamically loaded object file.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1087
     Handle must be the one returned previously from loadDynamicObject.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1088
     Return the address of the function, or nil on any error."
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1089
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1090
    |fName|
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1091
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1092
    OperatingSystem getSystemType = 'aix' ifTrue:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1093
	fName := '.' , aString 
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1094
    ] ifFalse:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1095
	fName := aString
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1096
    ].
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1097
    ^ self getSymbol:fName function:true from:handle
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1098
!
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1099
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1100
getListOfUndefinedSymbolsFrom:aHandle
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1101
    "return a collection of undefined symbols in a dynamically loaded object file.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1102
     Handle must be the one returned previously from loadDynamicObject.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1103
     Not all systems allow an object with undefined symbols to be
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1104
     loaded (actually, only dld does)."
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1105
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1106
    |list|
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1107
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1108
%{  /* STACK: 20000 */
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1109
#ifdef GNU_DL
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1110
    void (*func)();
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1111
    unsigned long addr;
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1112
    char *name;
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1113
    int nMax;
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1114
    char **undefNames;
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1115
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1116
    undefNames = dld_list_undefined_sym();
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1117
    if (dld_undefined_sym_count > 0) {
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1118
	char **nm;
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1119
	int index;
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1120
	int count = dld_undefined_sym_count;
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1121
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1122
	if (count > 100) count = 100;
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1123
	list = __ARRAY_NEW_INT(count);
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1124
	if (list) {
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1125
	    nm = undefNames;
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1126
	    for (index = 0; index < count; index++) {
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1127
		OBJ s;
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1128
238
4d80cc4b86dd underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 228
diff changeset
  1129
		s = __MKSTRING(*nm);
4d80cc4b86dd underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 228
diff changeset
  1130
		__ArrayInstPtr(list)->a_element[index] = s;
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1131
		__STORE(list, s);
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1132
		nm++;
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1133
	    }
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1134
	    free(undefNames);
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1135
	}
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1136
    }
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1137
#endif
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1138
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1139
#ifdef DL1_6
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1140
    /*
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1141
     * dont know how to do it
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1142
     */
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1143
#endif
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1144
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1145
#ifdef SYSV4_DL
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1146
    /*
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1147
     * dont know how to do it
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1148
     */
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1149
#endif
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1150
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1151
#ifdef SUN_DL
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1152
    /*
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1153
     * dont know how to do it
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1154
     */
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1155
#endif
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1156
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1157
#ifdef NEXT_DL
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1158
    /*
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1159
     * dont know how to do it
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1160
     */
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1161
#endif
180
a38d34ef8bde dynamic load works on NT !
Claus Gittinger <cg@exept.de>
parents: 178
diff changeset
  1162
a38d34ef8bde dynamic load works on NT !
Claus Gittinger <cg@exept.de>
parents: 178
diff changeset
  1163
#ifdef WIN_DL
a38d34ef8bde dynamic load works on NT !
Claus Gittinger <cg@exept.de>
parents: 178
diff changeset
  1164
    /*
a38d34ef8bde dynamic load works on NT !
Claus Gittinger <cg@exept.de>
parents: 178
diff changeset
  1165
     * dont know how to do it
a38d34ef8bde dynamic load works on NT !
Claus Gittinger <cg@exept.de>
parents: 178
diff changeset
  1166
     */
a38d34ef8bde dynamic load works on NT !
Claus Gittinger <cg@exept.de>
parents: 178
diff changeset
  1167
#endif
a38d34ef8bde dynamic load works on NT !
Claus Gittinger <cg@exept.de>
parents: 178
diff changeset
  1168
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1169
%}.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1170
    ^ list
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1171
!
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1172
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1173
getSymbol:aString function:isFunction from:aHandle
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1174
    "return the address of a symbol/function from a dynamically loaded object file.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1175
     Handle must be the one returned previously from loadDynamicObject.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1176
     Return the address of the symbol, or nil on any error."
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1177
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1178
    |sysHandle1 sysHandle2 lowAddr hiAddr|
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1179
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1180
    sysHandle1 := aHandle sysHandle1.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1181
    sysHandle2 := aHandle sysHandle2.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1182
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1183
%{  /* STACK: 20000 */
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1184
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1185
#ifdef GNU_DL
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1186
  {
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1187
    void (*func)();
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1188
    unsigned long addr;
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1189
    char *name;
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1190
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1191
    if (__isString(aString)) {
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1192
	name = (char *) __stringVal(aString);
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1193
	if (isFunction == false) {
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1194
	    addr = dld_get_symbol(name);
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1195
	} else {
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1196
	    func = (void (*) ()) dld_get_func(name);
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1197
	    if (func) {
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1198
		if (ObjectFileLoader_Verbose == true)
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1199
		    printf("addr of %s = %x\n", name, (INT)func);
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1200
		if (dld_function_executable_p(name)) {
238
4d80cc4b86dd underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 228
diff changeset
  1201
		    lowAddr = __MKSMALLINT( (INT)func & 0xFFFF );
4d80cc4b86dd underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 228
diff changeset
  1202
		    hiAddr = __MKSMALLINT( ((INT)func >> 16) & 0xFFFF );
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1203
		} else {
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1204
		    char **undefNames;
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1205
		    char **nm;
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1206
		    int i;
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1207
        
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1208
		    if (ObjectFileLoader_Verbose == true) {
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1209
			printf ("function %s not executable\n", name);
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1210
			dld_perror("not executable");
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1211
                    
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1212
			printf("undefined:\n");
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1213
			nm = undefNames = dld_list_undefined_sym();
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1214
			for (i=dld_undefined_sym_count; i; i--) {
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1215
			    printf("    %s\n", *nm++);
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1216
			}
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1217
			free(undefNames);
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1218
		    }
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1219
		}
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1220
	    } else {
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1221
		if (ObjectFileLoader_Verbose == true) {
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1222
		    printf ("function %s not found\n", name);
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1223
		    dld_perror("get_func");
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1224
		}
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1225
	    }
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1226
	}
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1227
    }
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1228
  }
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1229
#endif /* GNU_DL */
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1230
180
a38d34ef8bde dynamic load works on NT !
Claus Gittinger <cg@exept.de>
parents: 178
diff changeset
  1231
#ifdef WIN_DL
a38d34ef8bde dynamic load works on NT !
Claus Gittinger <cg@exept.de>
parents: 178
diff changeset
  1232
  {
a38d34ef8bde dynamic load works on NT !
Claus Gittinger <cg@exept.de>
parents: 178
diff changeset
  1233
    void *h;
a38d34ef8bde dynamic load works on NT !
Claus Gittinger <cg@exept.de>
parents: 178
diff changeset
  1234
    void *addr;
a38d34ef8bde dynamic load works on NT !
Claus Gittinger <cg@exept.de>
parents: 178
diff changeset
  1235
    int val;
a38d34ef8bde dynamic load works on NT !
Claus Gittinger <cg@exept.de>
parents: 178
diff changeset
  1236
    FARPROC entry;
a38d34ef8bde dynamic load works on NT !
Claus Gittinger <cg@exept.de>
parents: 178
diff changeset
  1237
    HMODULE handle;
a38d34ef8bde dynamic load works on NT !
Claus Gittinger <cg@exept.de>
parents: 178
diff changeset
  1238
a38d34ef8bde dynamic load works on NT !
Claus Gittinger <cg@exept.de>
parents: 178
diff changeset
  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
a38d34ef8bde dynamic load works on NT !
Claus Gittinger <cg@exept.de>
parents: 178
diff changeset
  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
4d80cc4b86dd underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 228
diff changeset
  1251
		lowAddr = __MKSMALLINT( (int)addr & 0xFFFF );
4d80cc4b86dd underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 228
diff changeset
  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
a38d34ef8bde dynamic load works on NT !
Claus Gittinger <cg@exept.de>
parents: 178
diff changeset
  1259
    }
a38d34ef8bde dynamic load works on NT !
Claus Gittinger <cg@exept.de>
parents: 178
diff changeset
  1260
  }
a38d34ef8bde dynamic load works on NT !
Claus Gittinger <cg@exept.de>
parents: 178
diff changeset
  1261
#endif
a38d34ef8bde dynamic load works on NT !
Claus Gittinger <cg@exept.de>
parents: 178
diff changeset
  1262
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1263
#ifdef DL1_6
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1264
  {
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1265
    void *h;
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1266
    void *addr;
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1267
    int val;
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1268
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1269
    if (__isString(aString)) {
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1270
	if (__isString(sysHandle1)) {
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1271
	    if (ObjectFileLoader_Verbose == true)
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1272
		printf("get sym <%s> handle = %x\n",
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1273
			__stringVal(aString), __stringVal(sysHandle1));
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1274
	    addr = dl_getsymbol(__stringVal(sysHandle1), __stringVal(aString));
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1275
	    if (addr) {
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1276
		if (ObjectFileLoader_Verbose == true)
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1277
		    printf("addr = %x\n", addr);
238
4d80cc4b86dd underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 228
diff changeset
  1278
		lowAddr = __MKSMALLINT( (int)addr & 0xFFFF );
4d80cc4b86dd underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 228
diff changeset
  1279
		hiAddr = __MKSMALLINT( ((int)addr >> 16) & 0xFFFF );
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1280
	    } else {
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1281
		if (ObjectFileLoader_Verbose == true)
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1282
		    printf("dl_getsymbol %s failed\n", __stringVal(aString));
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1283
	    }
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1284
	}
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1285
    }
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1286
  }
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1287
#endif
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1288
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1289
#ifdef SYSV4_DL
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1290
  {
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1291
    void *h;
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1292
    void *addr;
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1293
    int val;
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1294
    OBJ low = sysHandle1, hi = sysHandle2;
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1295
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1296
    if (__bothSmallInteger(low, hi)) {
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1297
	val = (_intVal(hi) << 16) + _intVal(low);
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1298
	h = (void *)(val);
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1299
	if (__isString(aString)) {
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1300
	    if (ObjectFileLoader_Verbose == true)
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1301
		printf("get sym <%s> handle = %x\n", __stringVal(aString), h);
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1302
	    addr = dlsym(h, (char *) __stringVal(aString));
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1303
	    if (addr) {
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1304
		if (ObjectFileLoader_Verbose == true) {
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1305
		    printf("dlsym %s ok; addr = %x\n", __stringVal(aString), addr);
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1306
		}
238
4d80cc4b86dd underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 228
diff changeset
  1307
		lowAddr = __MKSMALLINT( (int)addr & 0xFFFF );
4d80cc4b86dd underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 228
diff changeset
  1308
		hiAddr = __MKSMALLINT( ((int)addr >> 16) & 0xFFFF );
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1309
	    } else {
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1310
		if (ObjectFileLoader_Verbose == true) {
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1311
		    printf("dlsym %s error: %s\n", __stringVal(aString), dlerror());
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1312
		}
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1313
	    }
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1314
	}
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1315
    }
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1316
  }
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1317
#endif
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1318
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1319
#ifdef AIX_DL
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1320
  {
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1321
    OBJ fileName;
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1322
    void *h;
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1323
    void *addr;
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1324
    int val;
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1325
    struct nlist nl[2];
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1326
    OBJ low = sysHandle1, hi = sysHandle2;
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1327
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1328
    if (__bothSmallInteger(low, hi)
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1329
     && __isString(fileName)) {
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1330
	val = (_intVal(hi) << 16) + _intVal(low);
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1331
	h = (void *)(val);
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1332
	if (__isString(aString)) {
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1333
	    if (ObjectFileLoader_Verbose == true)
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1334
		printf("get sym <%s> handle = %x file = %s\n", 
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1335
			__stringVal(aString), h, __stringVal(fileName));
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1336
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1337
	    nl[0].n_name = __stringVal(aString);
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1338
	    nl[1].n_name = "";
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1339
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1340
	    if (nlist(__stringVal(fileName), &nl) == -1) {
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1341
		if (ObjectFileLoader_Verbose == true)
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1342
		    printf("nlist error\n");
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1343
	    } else {
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1344
		addr = (void *)((unsigned)nl[0].n_value + (unsigned)h);
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1345
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1346
		if (ObjectFileLoader_Verbose == true) {
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1347
		    printf("value=%x section=%d type=%x sclass=%d\n", 
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1348
			    nl[0].n_value, nl[0].n_scnum, nl[0].n_type, nl[0].n_sclass);
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1349
		    printf("addr = %x\n", addr);
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1350
		}
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1351
238
4d80cc4b86dd underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 228
diff changeset
  1352
		lowAddr = __MKSMALLINT( (int)addr & 0xFFFF );
4d80cc4b86dd underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 228
diff changeset
  1353
		hiAddr = __MKSMALLINT( ((int)addr >> 16) & 0xFFFF );
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1354
	    }
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1355
	}
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1356
    }
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1357
  }
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1358
#endif
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1359
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1360
#ifdef SUN_DL
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1361
  {
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1362
    void *h;
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1363
    void *addr;
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1364
    int val;
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1365
    OBJ low = sysHandle1, hi = sysHandle2;
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1366
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1367
    if (__bothSmallInteger(low, hi)) {
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1368
	val = (_intVal(hi) << 16) + _intVal(low);
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1369
	h = (void *)(val);
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1370
	if (__isString(aString)) {
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1371
	    if (ObjectFileLoader_Verbose == true)
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1372
		printf("get sym <%s> handle = %x\n", __stringVal(aString), h);
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1373
	    addr = dlsym(h, __stringVal(aString));
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1374
	    if (addr) {
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1375
		if (ObjectFileLoader_Verbose == true)
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1376
		    printf("addr = %x\n", addr);
238
4d80cc4b86dd underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 228
diff changeset
  1377
		lowAddr = __MKSMALLINT( (int)addr & 0xFFFF );
4d80cc4b86dd underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 228
diff changeset
  1378
		hiAddr = __MKSMALLINT( ((int)addr >> 16) & 0xFFFF );
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1379
	    } else {
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1380
		if (ObjectFileLoader_Verbose == true)
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1381
		    printf("dlsym %s error: %s\n", __stringVal(aString), dlerror());
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1382
	    }
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1383
	}
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1384
    }
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1385
  }
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1386
#endif
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1387
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1388
#ifdef NEXT_DL
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1389
  {
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1390
    unsigned long addr;
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1391
    long result;
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1392
    NXStream *errOut;
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1393
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1394
    if (__isString(aString)) {
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1395
	if (ObjectFileLoader_Verbose == true)
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1396
	    printf("get sym <%s>\n", __stringVal(aString));
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1397
	errOut = NXOpenFile(2, 2);
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1398
	result = rld_lookup(errOut,
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1399
			    (char *) __stringVal(aString),
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1400
			    &addr);
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1401
	NXClose(errOut);
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1402
	if (result) {
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1403
	    if (ObjectFileLoader_Verbose == true)
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1404
		printf("addr = %x\n", addr);
238
4d80cc4b86dd underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 228
diff changeset
  1405
	    lowAddr = __MKSMALLINT( (int)addr & 0xFFFF );
4d80cc4b86dd underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 228
diff changeset
  1406
	    hiAddr = __MKSMALLINT( ((int)addr >> 16) & 0xFFFF );
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1407
	}
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1408
    }
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1409
  }
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1410
#endif
180
a38d34ef8bde dynamic load works on NT !
Claus Gittinger <cg@exept.de>
parents: 178
diff changeset
  1411
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1412
%}.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1413
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1414
    lowAddr notNil ifTrue:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1415
	^ (hiAddr * 16r10000) + lowAddr
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1416
    ].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1417
    ^ nil
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1418
!
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1419
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1420
hasUndefinedSymbolsIn:handle
259
a469695d8d19 commentary
Claus Gittinger <cg@exept.de>
parents: 252
diff changeset
  1421
    "return true, if a module has undefined symbols in it.
a469695d8d19 commentary
Claus Gittinger <cg@exept.de>
parents: 252
diff changeset
  1422
     This is only possible if the system supports loading
a469695d8d19 commentary
Claus Gittinger <cg@exept.de>
parents: 252
diff changeset
  1423
     modules with undefined things in it - most do not"
a469695d8d19 commentary
Claus Gittinger <cg@exept.de>
parents: 252
diff changeset
  1424
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1425
    ^ (self getListOfUndefinedSymbolsFrom:handle) size > 0
259
a469695d8d19 commentary
Claus Gittinger <cg@exept.de>
parents: 252
diff changeset
  1426
a469695d8d19 commentary
Claus Gittinger <cg@exept.de>
parents: 252
diff changeset
  1427
    "Modified: 25.4.1996 / 09:47:27 / cg"
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1428
!
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  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
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1461
isCPlusPlusObject:handle
259
a469695d8d19 commentary
Claus Gittinger <cg@exept.de>
parents: 252
diff changeset
  1462
    "return true, if the loaded object is a c++ object module.
a469695d8d19 commentary
Claus Gittinger <cg@exept.de>
parents: 252
diff changeset
  1463
     This is not yet fully implemented/supported."
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1464
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1465
    (self getSymbol:'__gnu_compiled_cplusplus' function:true from:handle) notNil ifTrue:[^ true].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1466
    (self getSymbol:'__CTOR_LIST__' function:true from:handle) notNil ifTrue:[^ true].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1467
    (self getSymbol:'__CTOR_LIST__' function:false from:handle) notNil ifTrue:[^ true].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1468
    (self getSymbol:'__gnu_compiled_cplusplus' function:false from:handle) notNil ifTrue:[^ true].
6
0cd4e7480440 *** empty log message ***
claus
parents: 3
diff changeset
  1469
    ^ false
259
a469695d8d19 commentary
Claus Gittinger <cg@exept.de>
parents: 252
diff changeset
  1470
a469695d8d19 commentary
Claus Gittinger <cg@exept.de>
parents: 252
diff changeset
  1471
    "Modified: 25.4.1996 / 09:48:19 / cg"
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1472
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1473
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1474
isObjectiveCObject:handle
259
a469695d8d19 commentary
Claus Gittinger <cg@exept.de>
parents: 252
diff changeset
  1475
    "return true, if the loaded object is an objective-C object module.
a469695d8d19 commentary
Claus Gittinger <cg@exept.de>
parents: 252
diff changeset
  1476
     This is not yet implemented/supported"
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1477
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1478
    ^ false
259
a469695d8d19 commentary
Claus Gittinger <cg@exept.de>
parents: 252
diff changeset
  1479
a469695d8d19 commentary
Claus Gittinger <cg@exept.de>
parents: 252
diff changeset
  1480
    "Modified: 25.4.1996 / 09:47:59 / cg"
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1481
!
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1482
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1483
isSmalltalkObject:handle
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1484
    "return true, if the loaded object is a smalltalk object module"
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1485
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1486
    "not yet implemented - stc_compiled_smalltalk is a static symbol,
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1487
     not found in list - need nm-interface, or nlist-walker
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1488
    "
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1489
    ^ true.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1490
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1491
    (self getSymbol:'__stc_compiled_smalltalk' function:true from:handle) notNil ifTrue:[^ true].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1492
    (self getSymbol:'__stc_compiled_smalltalk' function:false from:handle) notNil ifTrue:[^ true].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1493
    ^ false
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1494
!
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1495
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1496
listUndefinedSymbolsIn:handle
259
a469695d8d19 commentary
Claus Gittinger <cg@exept.de>
parents: 252
diff changeset
  1497
    "list undefined objects in a module on the transcript"
a469695d8d19 commentary
Claus Gittinger <cg@exept.de>
parents: 252
diff changeset
  1498
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1499
    |undefinedNames|
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1500
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1501
    undefinedNames := self getListOfUndefinedSymbolsFrom:handle.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1502
    undefinedNames size > 0 ifTrue:[
272
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
  1503
        Transcript showCR:'undefined:'.
259
a469695d8d19 commentary
Claus Gittinger <cg@exept.de>
parents: 252
diff changeset
  1504
        undefinedNames do:[:aName |
272
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
  1505
            Transcript showCR:'    ' , aName
259
a469695d8d19 commentary
Claus Gittinger <cg@exept.de>
parents: 252
diff changeset
  1506
        ]
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1507
    ].
259
a469695d8d19 commentary
Claus Gittinger <cg@exept.de>
parents: 252
diff changeset
  1508
272
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
  1509
    "Modified: 18.5.1996 / 15:43:45 / cg"
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1510
!
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1511
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1512
loadDynamicObject:pathName
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1513
    "load an object-file (load/map into my address space).
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1514
     Return a non-nil handle if ok, nil otherwise.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1515
     No bindings are done - only a pure load is performed.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1516
     This function is not supported on all architectures.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1517
    "
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1518
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1519
    |handle buffer|
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1520
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1521
    Verbose ifTrue:[
272
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
  1522
        ('loadDynamic: ' , pathName , ' ...') infoPrintNL
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1523
    ].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1524
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1525
    "/ already loaded ?
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1526
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1527
    LoadedObjects notNil ifTrue:[
272
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
  1528
        handle := LoadedObjects at:pathName ifAbsent:nil.
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
  1529
        handle notNil ifTrue:[
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
  1530
            Verbose ifTrue:[
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
  1531
                ('... ' , pathName , ' already loaded.') infoPrintNL.
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
  1532
            ].
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
  1533
            ^ handle
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
  1534
        ].
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1535
    ].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1536
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1537
    "/
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1538
    "/ the 1st two entries are system dependent;
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1539
    "/ entry 3 is the pathName
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1540
    "/ entry 4 is a unique ID
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1541
    "/
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1542
    buffer := Array new:4.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1543
    buffer at:3 put:pathName.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1544
    buffer at:4 put:NextHandleID. NextHandleID := NextHandleID + 1.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1545
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1546
    buffer := self primLoadDynamicObject:pathName into:buffer.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1547
    buffer isNil ifTrue:[
272
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
  1548
        LastError == #notImplemented ifTrue:[
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
  1549
            Verbose ifTrue:[
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
  1550
                'no dynamic load facility or load failed.' infoPrintNL.
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
  1551
                Transcript showCR:'Try to load it myself ...'.
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
  1552
            ].
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
  1553
            "try it the hard way"
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
  1554
            buffer := self loadFile:pathName.
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
  1555
        ].
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
  1556
        buffer isNil ifTrue:[
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
  1557
            LastError == #linkError ifTrue:[
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
  1558
                LinkErrorMessage notNil ifTrue:[
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
  1559
                    Transcript showCR:'Load error:' , LinkErrorMessage
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
  1560
                ].    
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
  1561
            ].    
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
  1562
            ^ nil
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
  1563
        ]
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1564
    ].
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1565
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1566
    "
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1567
     remember loaded object for later unloading
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1568
    "
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1569
    handle := ObjectFileHandle new.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1570
    handle sysHandle1:(buffer at:1).
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1571
    handle sysHandle2:(buffer at:2).
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1572
    handle pathName:(buffer at:3).
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1573
    handle moduleID:(buffer at:4).
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1574
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1575
    LoadedObjects isNil ifTrue:[
272
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
  1576
        LoadedObjects := Dictionary new.
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1577
    ].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1578
    LoadedObjects at:pathName put:handle.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1579
    Smalltalk flushCachedClasses.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1580
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1581
    Verbose ifTrue:[
272
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
  1582
        ('loadDynamic ok; handle is: ' , handle printString) infoPrintNL.
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1583
    ].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1584
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1585
    ^ handle
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1586
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1587
    "sys5.4:
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1588
     |handle|
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1589
     handle := ObjectFileLoader loadDynamicObject:'../stc/mod1.so'.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1590
     ObjectFileLoader getFunction:'module1' from:handle
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1591
    "
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1592
    "next:
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1593
     |handle|
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1594
     handle := ObjectFileLoader loadDynamicObject:'../goodies/Path/AbstrPath.o'.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1595
     ObjectFileLoader getFunction:'__AbstractPath_Init' from:handle
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1596
    "
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1597
    "GLD:
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1598
     |handle|
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1599
     handle := ObjectFileLoader loadDynamicObject:'../clients/Tetris/Tetris.o'.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1600
     ObjectFileLoader getFunction:'__TetrisBlock_Init' from:handle
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1601
    "
272
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
  1602
04bf9e0c89da showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
  1603
    "Modified: 18.5.1996 / 15:43:56 / cg"
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1604
!
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1605
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1606
namesMatching:aPattern segment:segmentPattern in:aFileName
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1607
    "this is rubbish - it will vanish soon"
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1608
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1609
    |p l s addr segment name entry|
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1610
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1611
    OperatingSystem getSystemType = 'aix' ifTrue:[
225
122d8ff18aff nicer message
Claus Gittinger <cg@exept.de>
parents: 222
diff changeset
  1612
        ^ nil
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1613
    ].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1614
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1615
    l := OrderedCollection new.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1616
    p := PipeStream readingFrom:(self nm:aFileName).
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1617
    p isNil ifTrue:[
225
122d8ff18aff nicer message
Claus Gittinger <cg@exept.de>
parents: 222
diff changeset
  1618
        ('LOADER: cannot read names from ' , aFileName) infoPrintNL.
122d8ff18aff nicer message
Claus Gittinger <cg@exept.de>
parents: 222
diff changeset
  1619
        ^ nil
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1620
    ].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1621
    [p atEnd] whileFalse:[
225
122d8ff18aff nicer message
Claus Gittinger <cg@exept.de>
parents: 222
diff changeset
  1622
        entry := p nextLine.
122d8ff18aff nicer message
Claus Gittinger <cg@exept.de>
parents: 222
diff changeset
  1623
        Verbose ifTrue:[
122d8ff18aff nicer message
Claus Gittinger <cg@exept.de>
parents: 222
diff changeset
  1624
            entry infoPrintNL.
122d8ff18aff nicer message
Claus Gittinger <cg@exept.de>
parents: 222
diff changeset
  1625
        ].
122d8ff18aff nicer message
Claus Gittinger <cg@exept.de>
parents: 222
diff changeset
  1626
        entry notNil ifTrue:[
122d8ff18aff nicer message
Claus Gittinger <cg@exept.de>
parents: 222
diff changeset
  1627
            s := ReadStream on:entry.
122d8ff18aff nicer message
Claus Gittinger <cg@exept.de>
parents: 222
diff changeset
  1628
            addr := s nextAlphaNumericWord.
122d8ff18aff nicer message
Claus Gittinger <cg@exept.de>
parents: 222
diff changeset
  1629
            segment := s nextAlphaNumericWord.
122d8ff18aff nicer message
Claus Gittinger <cg@exept.de>
parents: 222
diff changeset
  1630
            name := s upToEnd withoutSeparators.
122d8ff18aff nicer message
Claus Gittinger <cg@exept.de>
parents: 222
diff changeset
  1631
            (addr notNil and:[segment notNil and:[name notNil]]) ifTrue:[
122d8ff18aff nicer message
Claus Gittinger <cg@exept.de>
parents: 222
diff changeset
  1632
                (aPattern match:name) ifTrue:[
122d8ff18aff nicer message
Claus Gittinger <cg@exept.de>
parents: 222
diff changeset
  1633
                    (segmentPattern isNil or:[segmentPattern match:segment]) ifTrue:[
122d8ff18aff nicer message
Claus Gittinger <cg@exept.de>
parents: 222
diff changeset
  1634
                        l add:name.
122d8ff18aff nicer message
Claus Gittinger <cg@exept.de>
parents: 222
diff changeset
  1635
                        Verbose ifTrue:[
122d8ff18aff nicer message
Claus Gittinger <cg@exept.de>
parents: 222
diff changeset
  1636
                            ('found name: ' , name) infoPrintNL.
122d8ff18aff nicer message
Claus Gittinger <cg@exept.de>
parents: 222
diff changeset
  1637
                        ]
122d8ff18aff nicer message
Claus Gittinger <cg@exept.de>
parents: 222
diff changeset
  1638
                    ] ifFalse:[
122d8ff18aff nicer message
Claus Gittinger <cg@exept.de>
parents: 222
diff changeset
  1639
                        Verbose ifTrue:[
122d8ff18aff nicer message
Claus Gittinger <cg@exept.de>
parents: 222
diff changeset
  1640
                            name infoPrint. ' segment mismatch ' infoPrint.
122d8ff18aff nicer message
Claus Gittinger <cg@exept.de>
parents: 222
diff changeset
  1641
                            segmentPattern infoPrint. ' ' infoPrint. segment infoPrintNL.
122d8ff18aff nicer message
Claus Gittinger <cg@exept.de>
parents: 222
diff changeset
  1642
                        ]
122d8ff18aff nicer message
Claus Gittinger <cg@exept.de>
parents: 222
diff changeset
  1643
                    ]
122d8ff18aff nicer message
Claus Gittinger <cg@exept.de>
parents: 222
diff changeset
  1644
                ]
122d8ff18aff nicer message
Claus Gittinger <cg@exept.de>
parents: 222
diff changeset
  1645
            ]
122d8ff18aff nicer message
Claus Gittinger <cg@exept.de>
parents: 222
diff changeset
  1646
        ]
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1647
    ].
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1648
    p close.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1649
    ^ l
225
122d8ff18aff nicer message
Claus Gittinger <cg@exept.de>
parents: 222
diff changeset
  1650
122d8ff18aff nicer message
Claus Gittinger <cg@exept.de>
parents: 222
diff changeset
  1651
    "Modified: 7.3.1996 / 19:20:01 / cg"
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1652
!
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1653
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1654
primLoadDynamicObject:pathName into:anInfoBuffer
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1655
    "load an object-file (map into my address space).
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1656
     Return an OS-handle (whatever that is) - where some space
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1657
     (a 3-element array) has to be passed in for this.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1658
     The first two entries are used in a machine dependent way,
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1659
     and callers may not depend on what is found there 
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1660
     (instead, only pass around handles transparently).
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1661
     This function is not supported on all architectures."
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1662
222
c06525bef9f1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 220
diff changeset
  1663
%{  /* CALLSUNLIMITEDSTACK */
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1664
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1665
    if (! __isArray(anInfoBuffer)
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1666
     || (_arraySize(anInfoBuffer) < 3)) {
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1667
	return nil;
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1668
    }
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1669
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1670
#ifdef GNU_DL
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1671
  {
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1672
    static firstCall = 1;
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1673
    extern char *__myName__;
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1674
    extern dld_ignore_redefinitions;
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1675
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1676
    if (firstCall) {
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1677
	firstCall = 0;
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1678
	(void) dld_init (__myName__);
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1679
	dld_ignore_redefinitions = 1;
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1680
    }
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1681
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1682
    if (__isString(pathName)) {
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1683
	if (dld_link(__stringVal(pathName))) {
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1684
	    if (ObjectFileLoader_Verbose == true) {
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1685
		printf ("link file %s failed\n", __stringVal(pathName));
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1686
		dld_perror("cant link");
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1687
	    }
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1688
	    ObjectFileLoader_LastError = @symbol(linkError);
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1689
	    RETURN ( nil );
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1690
	}
238
4d80cc4b86dd underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 228
diff changeset
  1691
	__ArrayInstPtr(anInfoBuffer)->a_element[0] = pathName;
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1692
	__STORE(anInfoBuffer, pathName);
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1693
	RETURN ( anInfoBuffer );
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1694
    }
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1695
    RETURN ( nil );
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1696
  }
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1697
#endif
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1698
180
a38d34ef8bde dynamic load works on NT !
Claus Gittinger <cg@exept.de>
parents: 178
diff changeset
  1699
#ifdef WIN_DL
a38d34ef8bde dynamic load works on NT !
Claus Gittinger <cg@exept.de>
parents: 178
diff changeset
  1700
  {
a38d34ef8bde dynamic load works on NT !
Claus Gittinger <cg@exept.de>
parents: 178
diff changeset
  1701
    HINSTANCE handle;
a38d34ef8bde dynamic load works on NT !
Claus Gittinger <cg@exept.de>
parents: 178
diff changeset
  1702
    int err;
a38d34ef8bde dynamic load works on NT !
Claus Gittinger <cg@exept.de>
parents: 178
diff changeset
  1703
a38d34ef8bde dynamic load works on NT !
Claus Gittinger <cg@exept.de>
parents: 178
diff changeset
  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
a38d34ef8bde dynamic load works on NT !
Claus Gittinger <cg@exept.de>
parents: 178
diff changeset
  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
a38d34ef8bde dynamic load works on NT !
Claus Gittinger <cg@exept.de>
parents: 178
diff changeset
  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
4d80cc4b86dd underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 228
diff changeset
  1714
	__ArrayInstPtr(anInfoBuffer)->a_element[0] = __MKSMALLINT( (int)handle & 0xFFFF );
4d80cc4b86dd underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 228
diff changeset
  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
a38d34ef8bde dynamic load works on NT !
Claus Gittinger <cg@exept.de>
parents: 178
diff changeset
  1717
    }
a38d34ef8bde dynamic load works on NT !
Claus Gittinger <cg@exept.de>
parents: 178
diff changeset
  1718
    RETURN ( nil );
a38d34ef8bde dynamic load works on NT !
Claus Gittinger <cg@exept.de>
parents: 178
diff changeset
  1719
  }
a38d34ef8bde dynamic load works on NT !
Claus Gittinger <cg@exept.de>
parents: 178
diff changeset
  1720
#endif
a38d34ef8bde dynamic load works on NT !
Claus Gittinger <cg@exept.de>
parents: 178
diff changeset
  1721
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1722
#ifdef DL1_6
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1723
  {
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1724
    extern char *__myName__;
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1725
    char *ldname;
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1726
    OBJ tmpName;
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1727
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1728
    if (__isString(pathName)) {
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1729
	if ( dl_loadmod_only(__myName__, __stringVal(pathName), &ldname) == 0 ) {
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1730
	    if (ObjectFileLoader_Verbose == true) {
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1731
		printf ("link file %s failed\n", __stringVal(pathName));
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1732
	    }
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1733
	    RETURN ( nil );
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1734
	}
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1735
	/*
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1736
	 * returns the name of the temporary ld-file
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1737
	 * use that as handle ...
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1738
	 */
238
4d80cc4b86dd underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 228
diff changeset
  1739
	tmpName = __MKSTRING(ldname);
4d80cc4b86dd underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 228
diff changeset
  1740
	__ArrayInstPtr(anInfoBuffer)->a_element[0] = tmpName;
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1741
	__STORE(anInfoBuffer, tmpName);
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1742
	RETURN ( anInfoBuffer );
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1743
    }
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1744
    RETURN ( nil );
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1745
  }
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1746
#endif
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1747
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1748
#ifdef AIX_DL
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1749
  {
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1750
    extern char *__myName__;
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1751
    char *ldname;
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1752
    int *handle;
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1753
    extern errno;
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1754
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1755
    if (__isString(pathName)) {
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1756
	if ( (handle = (int *) load(__stringVal(pathName), 0, 0)) == 0 ) {
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1757
	    if (ObjectFileLoader_Verbose == true) {
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1758
		char *messages[64];
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1759
		int i;
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1760
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1761
		printf ("load file %s failed errno=%d\n", 
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1762
				__stringVal(pathName), errno);
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1763
		switch (errno) {
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1764
		    case ENOEXEC:
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1765
			printf("   load messages:\n");
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1766
			loadquery(L_GETMESSAGES, messages, sizeof(messages));
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1767
			for (i=0; messages[i]; i++) {
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1768
			    printf("      %s\n", messages[i]);
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1769
			}
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1770
			break;
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1771
		}
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1772
	    }
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1773
	    RETURN ( nil );
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1774
	}
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1775
	if (ObjectFileLoader_Verbose == true) {
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1776
	    printf("load %s handle = %x\n", __stringVal(pathName), handle);
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1777
	}
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1778
238
4d80cc4b86dd underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 228
diff changeset
  1779
	__ArrayInstPtr(anInfoBuffer)->a_element[0] = __MKSMALLINT( (int)handle & 0xFFFF );
4d80cc4b86dd underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 228
diff changeset
  1780
	__ArrayInstPtr(anInfoBuffer)->a_element[1] = __MKSMALLINT( ((int)handle >> 16) & 0xFFFF );
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1781
	RETURN (anInfoBuffer);
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1782
    }
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1783
    RETURN ( nil );
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1784
  }
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1785
#endif
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1786
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1787
#ifdef SYSV4_DL
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1788
  {
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1789
    void *handle;
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1790
    char *nm;
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1791
    char *errMsg;
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1792
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1793
    if ((pathName == nil) || __isString(pathName)) {
248
27ae4364185e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 238
diff changeset
  1794
	handle = (void *)dlopen(pathName == nil ? (char *)0 : __stringVal(pathName), RTLD_NOW);
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1795
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1796
	if (! handle) {
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1797
	    errMsg = dlerror();
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1798
	    fprintf(stderr, "dlopen %s error:\n", __stringVal(pathName));
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1799
	    fprintf(stderr, "    <%s>\n", errMsg);
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1800
	    ObjectFileLoader_LastError = @symbol(linkError);
238
4d80cc4b86dd underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 228
diff changeset
  1801
	    ObjectFileLoader_LinkErrorMessage = __MKSTRING(errMsg);
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1802
	    RETURN (nil);
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1803
	}
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1804
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1805
	if (ObjectFileLoader_Verbose == true) {
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1806
	    printf("open %s handle = %x\n", __stringVal(pathName), handle);
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1807
	}
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1808
238
4d80cc4b86dd underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 228
diff changeset
  1809
	__ArrayInstPtr(anInfoBuffer)->a_element[0] = __MKSMALLINT( (int)handle & 0xFFFF );
4d80cc4b86dd underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 228
diff changeset
  1810
	__ArrayInstPtr(anInfoBuffer)->a_element[1] = __MKSMALLINT( ((int)handle >> 16) & 0xFFFF );
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1811
	RETURN (anInfoBuffer);
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1812
    }
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1813
  }
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1814
#endif
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1815
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1816
#ifdef SUN_DL
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1817
  {
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1818
    void *handle;
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1819
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1820
    if ((pathName == nil) || __isString(pathName)) {
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1821
	if (pathName == nil)
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1822
	    handle = dlopen((char *)0, 1);
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1823
	else
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1824
	    handle = dlopen(__stringVal(pathName), 1);
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1825
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1826
	if (! handle) {
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1827
	    fprintf(stderr, "dlopen %s error: <%s>\n", 
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1828
				__stringVal(pathName), dlerror());
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1829
	    ObjectFileLoader_LastError = @symbol(linkError);
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1830
	    RETURN (nil);
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1831
	}
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1832
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1833
	if (ObjectFileLoader_Verbose == true) {
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1834
	    printf("open %s handle = %x\n", __stringVal(pathName), handle);
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1835
	}
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1836
238
4d80cc4b86dd underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 228
diff changeset
  1837
	__ArrayInstPtr(anInfoBuffer)->a_element[0] = __MKSMALLINT( (int)handle & 0xFFFF );
4d80cc4b86dd underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 228
diff changeset
  1838
	__ArrayInstPtr(anInfoBuffer)->a_element[1] = __MKSMALLINT( ((int)handle >> 16) & 0xFFFF );
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1839
	RETURN (anInfoBuffer);
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1840
    }
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1841
  }
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1842
#endif
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1843
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1844
#ifdef NEXT_DL
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1845
  {
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1846
    long result;
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1847
    char *files[2];
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1848
    NXStream *errOut;
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1849
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1850
    if (__isString(pathName)) {
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1851
	files[0] = (char *) __stringVal(pathName);
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1852
	files[1] = (char *) 0;
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1853
	errOut = NXOpenFile(2, 2);
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1854
	result = rld_load(errOut,
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1855
			  (struct mach_header **)0,
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1856
			  files,
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1857
			  (char *)0);
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1858
	NXClose(errOut);
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1859
	if (! result) {
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1860
	    ObjectFileLoader_LastError = @symbol(linkError);
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1861
	    fprintf(stderr, "rld_load %s failed\n", __stringVal(pathName));
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1862
	    RETURN (nil);
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1863
	}
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1864
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1865
	if (ObjectFileLoader_Verbose == true)
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1866
	    printf("rld_load %s ok\n", __stringVal(pathName));
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1867
238
4d80cc4b86dd underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 228
diff changeset
  1868
	__ArrayInstPtr(anInfoBuffer)->a_element[0] = pathName;
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1869
	__STORE(anInfoBuffer, pathName);
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1870
	RETURN ( anInfoBuffer );
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1871
    }
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1872
  }
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1873
#endif
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1874
%}.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1875
    LastError := #notImplemented.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1876
    ^ nil
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1877
!
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1878
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1879
primUnloadDynamicObject:aHandle
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1880
    "unload an object-file (unmap from my address space).
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1881
     This is a low-level entry, which does not care if there are
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1882
     still any code references (from blocks or methods) to this
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1883
     module. Calling it for still living classes will definitely
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1884
     lead to some fatal conditions to occur later."
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1885
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1886
    |sysHandle1 sysHandle2|
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1887
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1888
    sysHandle1 := aHandle sysHandle1.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1889
    sysHandle2 := aHandle sysHandle2.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1890
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1891
%{
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1892
#ifdef GNU_DL
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1893
    if (__isString(sysHandle1)) {
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1894
	if (dld_unlink_by_file(__stringVal(sysHandle1), 1)) {
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1895
	    if (ObjectFileLoader_Verbose == true) {
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1896
		printf ("unlink file %s failed\n", __stringVal(sysHandle1));
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1897
		dld_perror("cant unlink");
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1898
	    }
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1899
	    RETURN (false);
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1900
	}
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1901
	RETURN (true);
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1902
    }
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1903
    RETURN (false);
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1904
#endif
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1905
180
a38d34ef8bde dynamic load works on NT !
Claus Gittinger <cg@exept.de>
parents: 178
diff changeset
  1906
#ifdef WIN_DL
a38d34ef8bde dynamic load works on NT !
Claus Gittinger <cg@exept.de>
parents: 178
diff changeset
  1907
    int val;
a38d34ef8bde dynamic load works on NT !
Claus Gittinger <cg@exept.de>
parents: 178
diff changeset
  1908
    HINSTANCE handle;
a38d34ef8bde dynamic load works on NT !
Claus Gittinger <cg@exept.de>
parents: 178
diff changeset
  1909
    int err;
a38d34ef8bde dynamic load works on NT !
Claus Gittinger <cg@exept.de>
parents: 178
diff changeset
  1910
a38d34ef8bde dynamic load works on NT !
Claus Gittinger <cg@exept.de>
parents: 178
diff changeset
  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
a38d34ef8bde dynamic load works on NT !
Claus Gittinger <cg@exept.de>
parents: 178
diff changeset
  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
a38d34ef8bde dynamic load works on NT !
Claus Gittinger <cg@exept.de>
parents: 178
diff changeset
  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
a38d34ef8bde dynamic load works on NT !
Claus Gittinger <cg@exept.de>
parents: 178
diff changeset
  1924
    }
a38d34ef8bde dynamic load works on NT !
Claus Gittinger <cg@exept.de>
parents: 178
diff changeset
  1925
    RETURN (false);
a38d34ef8bde dynamic load works on NT !
Claus Gittinger <cg@exept.de>
parents: 178
diff changeset
  1926
#endif
a38d34ef8bde dynamic load works on NT !
Claus Gittinger <cg@exept.de>
parents: 178
diff changeset
  1927
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1928
#ifdef SYSV4_DL
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1929
  {
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1930
    void *h;
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1931
    int val;
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1932
    OBJ low = sysHandle1, hi = sysHandle2;
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1933
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1934
    if (__bothSmallInteger(low, hi)) {
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1935
	val = (_intVal(hi) << 16) + _intVal(low);
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1936
	h = (void *)(val);
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1937
	if (ObjectFileLoader_Verbose == true)
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1938
	    printf("close handle = %x\n", h);
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1939
	if (dlclose(h) != 0) {
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1940
	    fprintf(stderr, "dlclose failed with:<%s>\n", dlerror());
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1941
	    RETURN (false);
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1942
	}
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1943
	RETURN (true);
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1944
    }
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1945
  }
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1946
#endif
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1947
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1948
#ifdef SUN_DL
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1949
  {
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1950
    void *h;
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1951
    int val;
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1952
    OBJ low = sysHandle1, hi = sysHandle2;
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1953
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1954
    if (__bothSmallInteger(low, hi)) {
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1955
	val = (_intVal(hi) << 16) + _intVal(low);
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1956
	h = (void *)(val);
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1957
	if (ObjectFileLoader_Verbose == true)
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1958
	    printf("close handle = %x\n", h);
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1959
	dlclose(h);
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1960
	RETURN (true);
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1961
    }
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1962
  }
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1963
#endif
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1964
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1965
#ifdef AIX_DL
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1966
  {
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1967
    int *h;
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1968
    int val;
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1969
    OBJ low = sysHandle1, hi = sysHandle2;
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1970
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1971
    if (__bothSmallInteger(low, hi)) {
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1972
	val = (_intVal(hi) << 16) + _intVal(low);
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1973
	h = (int *)(val);
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1974
	if (ObjectFileLoader_Verbose == true)
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1975
	    printf("unload handle = %x\n", h);
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1976
	if ( unload(h) != 0) {
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1977
	    fprintf(stderr, "unload failed\n");
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1978
	    RETURN (false);
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1979
	}
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1980
	RETURN (true);
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1981
    }
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1982
  }
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1983
#endif
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1984
%}.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1985
    ^ false
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1986
!
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1987
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1988
releaseSymbolTable
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1989
    "this is needed on NeXT to forget loaded names. If this wasnt done,
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1990
     the same class could not be loaded in again due to multiple defines.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1991
     On other architectures, this is not needed and therefore a noop."
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1992
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1993
%{
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1994
#ifdef NEXT_DL
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1995
    NXStream *errOut;
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1996
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1997
    errOut = NXOpenFile(2, 2);
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1998
    rld_unload_all(errOut, (long)0);
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  1999
    rld_load_basefile(errOut, "smalltalk");
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2000
    NXClose(errOut);
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2001
#endif
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2002
%}
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2003
!
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2004
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2005
unloadDynamicObject:handle
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2006
    "close an object-file (unmap from my address space)
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2007
     and remove the entry from the remembered object file set.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2008
     This is a low-level entry, which does not care if there are
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2009
     still any code references (from blocks or methods) to this
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2010
     module. Calling it for still living classes will definitely
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2011
     lead to some fatal conditions to occur later."
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  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
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2014
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  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
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2017
    ].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  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
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  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
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  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
0cd4e7480440 *** empty log message ***
claus
parents: 3
diff changeset
  2066
    ].
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2067
    Smalltalk flushCachedClasses.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2068
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2069
    "
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2070
     for individual methods, we keep the methodObject,
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2071
     but make it unexecutable. Its still visible in the browser.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2072
    "
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  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
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  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
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2081
! !
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2082
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2083
!ObjectFileLoader  class methodsFor:'image save/restart'!
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2084
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2085
invalidateAndRememberAllObjectFiles
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2086
    "invalidate code refs into all dynamically loaded object files.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2087
     Required before writing a snapshot image."
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2088
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2089
    LoadedObjects notNil ifTrue:[
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2090
        ActuallyLoadedObjects := LoadedObjects.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2091
        self rememberAllObjectFiles.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2092
        ActuallyLoadedObjects keys do:[:aFileName |
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2093
            |handle|
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2094
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2095
            handle := ActuallyLoadedObjects at:aFileName.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2096
            handle isNil ifTrue:[
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2097
                self error:'oops, no handle'.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2098
            ] ifFalse:[
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2099
                (handle isClassLibHandle or:[handle isMethodHandle]) ifTrue:[
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2100
                    self invalidateModule:handle
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2101
                ]
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2102
            ]
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2103
        ].
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2104
        LoadedObjects := nil.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2105
    ].
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2106
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2107
    "Created: 5.10.1995 / 15:48:56 / claus"
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2108
    "Modified: 5.10.1995 / 16:48:51 / claus"
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2109
    "Modified: 12.7.1996 / 17:13:45 / cg"
28
a9d33ea0692d loads objces on iris5
claus
parents: 20
diff changeset
  2110
!
6
0cd4e7480440 *** empty log message ***
claus
parents: 3
diff changeset
  2111
303
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2112
reloadAllRememberedObjectFiles
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2113
    "reload all object modules as were loaded when the image was saved.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2114
     Some care has to be taken, if files are missing or otherwise corrupted."
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2115
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2116
    |oldDummyMethod where m newHandle 
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2117
     savedOldClasses savedByteCodeMethods savedMethods
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2118
     functions newFunction|
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2119
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2120
    PreviouslyLoadedObjects notNil ifTrue:[
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2121
        PreviouslyLoadedObjects do:[:entry |
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2122
            |fileName handle cls sel|
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2123
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2124
            fileName := entry key.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2125
            handle := entry value.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2126
            handle moduleID:nil.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2127
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2128
            handle isClassLibHandle ifTrue:[
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2129
                ('OBJFLOADER: reloading classes in ' , fileName , ' ...') infoPrintNL.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2130
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2131
                "/
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2132
                "/ remember all byteCode methods (as added in the session)
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2133
                "/                
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2134
                savedByteCodeMethods := IdentityDictionary new.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2135
                savedOldClasses := IdentitySet new.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2136
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2137
                handle classes do:[:aClass |
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2138
                    savedMethods := IdentityDictionary new.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2139
                    savedOldClasses add:aClass.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2140
                    aClass methodDictionary keysAndValuesDo:[:sel :m |
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2141
                        m byteCode notNil ifTrue:[
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2142
                            "/ an interpreted method - must be preserved
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2143
                            savedMethods at:sel put:m
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2144
                        ]
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2145
                    ].
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2146
                    savedMethods notEmpty ifTrue:[
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2147
                        savedByteCodeMethods at:(aClass name) put:savedMethods
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2148
                    ].
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2149
                ].
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2150
                "/
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2151
                "/ load the class binary
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2152
                "/                
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2153
                self loadObjectFile:fileName.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2154
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2155
                "/
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2156
                "/ reinstall the byteCode methods
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2157
                "/                
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2158
                savedByteCodeMethods keysAndValuesDo:[:nm :savedMethods |
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2159
                    |cls|
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2160
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2161
                    cls := Smalltalk classNamed:nm.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2162
                    savedMethods keysAndValuesDo:[:sel :m |
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2163
                        cls primAddSelector:sel withMethod:m. 
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2164
"/ ('preserved ' , cls name , '>>' , sel) printNL.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2165
                    ]
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2166
                ].
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2167
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2168
                "/
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2169
                "/ validate old-classes vs. new classes.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2170
                "/ and if things look ok, get rid of old stuff
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2171
                "/ and make instances become instances of the new class
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2172
                "/
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2173
                savedOldClasses do:[:oldClass |
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2174
                    |newClass|
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2175
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2176
                    newClass := Smalltalk classNamed:(oldClass name).
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2177
                    (newClass isNil or:[newClass == oldClass]) ifTrue:[
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2178
                        ('OBJFLOADER: reload of ' , oldClass name , ' seemed to fail.') errorPrintCR.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2179
                    ] ifFalse:[
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2180
"/'oldSize: ' print. oldClass instSize print. ' (' print. oldClass instSize class name print. ') ' print.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2181
"/'newSize: ' print. newClass instSize print. ' (' print. oldClass instSize class name print. ') ' printCR.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2182
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2183
                        oldClass instSize ~~ newClass instSize ifTrue:[
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2184
                            ('OBJFLOADER: ' , oldClass name , ' has changed its size.') errorPrintCR.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2185
                        ] ifFalse:[
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2186
                            oldClass class instSize ~~ newClass class instSize ifTrue:[
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2187
                                ('OBJFLOADER: ' , oldClass name , ' class has changed its size.') errorPrintCR.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2188
                            ] ifFalse:[
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2189
                                ('OBJFLOADER: migrating ' , oldClass name) errorPrintCR.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2190
                                oldClass becomeSameAs:newClass
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2191
                            ]
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2192
                        ]
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2193
                    ]
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2194
                ]
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2195
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2196
            ] ifFalse:[
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2197
                handle isMethodHandle ifTrue:[
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2198
                    oldDummyMethod := handle method.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2199
                    (oldDummyMethod isKindOf:Method) ifFalse:[
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2200
                        ('OBJFLOADER: ignore obsolete (already collected) method in ' , fileName) infoPrintNL
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2201
                    ] ifTrue:[
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2202
                        ('OBJFLOADER: reloading method in ' , fileName , ' ...') infoPrintNL.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2203
                        where := oldDummyMethod who.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2204
                        newHandle := self loadMethodObjectFile:fileName.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2205
                        newHandle isNil ifTrue:[
306
3e2f45a18d3b care for unloadable libs
Claus Gittinger <cg@exept.de>
parents: 305
diff changeset
  2206
                            ('OBJFLOADER: failed to reload method in ' , fileName , ' ...') errorPrintNL.
3e2f45a18d3b care for unloadable libs
Claus Gittinger <cg@exept.de>
parents: 305
diff changeset
  2207
                            handle moduleID:nil.
303
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2208
                        ] ifFalse:[
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2209
                            m := newHandle method.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2210
                            m source:(oldDummyMethod source).
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2211
                            m package:(oldDummyMethod package).
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2212
                            where notNil ifTrue:[
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2213
                                cls := where at:1.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2214
                                sel := where at:2.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2215
                                m == (cls compiledMethodAt:sel) ifFalse:[
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2216
                                    'LOADER: oops - loaded method installed wrong' errorPrintNL.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2217
                                ] ifTrue:[
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2218
"/                                  cls changed:#methodDictionary with:(Array with:sel with:oldDummyMethod).
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2219
                                ]
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2220
                            ].
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2221
                        ]
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2222
                    ]
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2223
                ] ifFalse:[
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2224
                    handle isFunctionObjectHandle ifTrue:[
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2225
                        functions := handle functions.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2226
                        functions isEmpty ifTrue:[
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2227
                            ('OBJFLOADER: ignore obsolete (unreferenced) functions in ' , fileName) infoPrintNL
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2228
                        ] ifFalse:[
305
d5e07cd0fe2b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 303
diff changeset
  2229
                            newHandle := self loadDynamicObject:fileName.
306
3e2f45a18d3b care for unloadable libs
Claus Gittinger <cg@exept.de>
parents: 305
diff changeset
  2230
                            newHandle isNil ifTrue:[
3e2f45a18d3b care for unloadable libs
Claus Gittinger <cg@exept.de>
parents: 305
diff changeset
  2231
                                ('OBJFLOADER: failed to reload ' , fileName , ' ...') errorPrintNL.
3e2f45a18d3b care for unloadable libs
Claus Gittinger <cg@exept.de>
parents: 305
diff changeset
  2232
                                handle moduleID:nil.
3e2f45a18d3b care for unloadable libs
Claus Gittinger <cg@exept.de>
parents: 305
diff changeset
  2233
                            ] ifFalse:[
3e2f45a18d3b care for unloadable libs
Claus Gittinger <cg@exept.de>
parents: 305
diff changeset
  2234
                                ('OBJFLOADER: reloading ' , fileName , ' ...') infoPrintNL.
3e2f45a18d3b care for unloadable libs
Claus Gittinger <cg@exept.de>
parents: 305
diff changeset
  2235
                                functions do:[:oldFunction |
3e2f45a18d3b care for unloadable libs
Claus Gittinger <cg@exept.de>
parents: 305
diff changeset
  2236
                                    newFunction := newHandle getFunction:(oldFunction name).
3e2f45a18d3b care for unloadable libs
Claus Gittinger <cg@exept.de>
parents: 305
diff changeset
  2237
                                    newFunction isNil ifTrue:[
3e2f45a18d3b care for unloadable libs
Claus Gittinger <cg@exept.de>
parents: 305
diff changeset
  2238
                                        ('OBJFLOADER: function: ''' , oldFunction name , ''' no longer present.') errorPrintNL.
3e2f45a18d3b care for unloadable libs
Claus Gittinger <cg@exept.de>
parents: 305
diff changeset
  2239
                                        oldFunction code:nil.
3e2f45a18d3b care for unloadable libs
Claus Gittinger <cg@exept.de>
parents: 305
diff changeset
  2240
                                        oldFunction setName:oldFunction name moduleHandle:nil.
3e2f45a18d3b care for unloadable libs
Claus Gittinger <cg@exept.de>
parents: 305
diff changeset
  2241
                                    ] ifFalse:[
3e2f45a18d3b care for unloadable libs
Claus Gittinger <cg@exept.de>
parents: 305
diff changeset
  2242
                                        oldFunction code:(newFunction code).
3e2f45a18d3b care for unloadable libs
Claus Gittinger <cg@exept.de>
parents: 305
diff changeset
  2243
                                        oldFunction setName:oldFunction name moduleHandle:newHandle.
3e2f45a18d3b care for unloadable libs
Claus Gittinger <cg@exept.de>
parents: 305
diff changeset
  2244
                                        ('OBJFLOADER: rebound function: ''' , oldFunction name , '''.') infoPrintNL.
3e2f45a18d3b care for unloadable libs
Claus Gittinger <cg@exept.de>
parents: 305
diff changeset
  2245
                                    ]
3e2f45a18d3b care for unloadable libs
Claus Gittinger <cg@exept.de>
parents: 305
diff changeset
  2246
                                ].
3e2f45a18d3b care for unloadable libs
Claus Gittinger <cg@exept.de>
parents: 305
diff changeset
  2247
                                handle becomeSameAs:newHandle.      "/ the old handle is now void
3e2f45a18d3b care for unloadable libs
Claus Gittinger <cg@exept.de>
parents: 305
diff changeset
  2248
                            ]
303
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2249
                        ]
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2250
                    ] ifFalse:[
306
3e2f45a18d3b care for unloadable libs
Claus Gittinger <cg@exept.de>
parents: 305
diff changeset
  2251
                        ('OBJFLOADER: ignored invalid (obsolete) objectFile handle: ' , handle printString) infoPrintNL.
303
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2252
                    ]
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2253
                ]
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2254
            ]
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2255
        ].
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2256
        PreviouslyLoadedObjects := nil
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2257
    ]
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2258
306
3e2f45a18d3b care for unloadable libs
Claus Gittinger <cg@exept.de>
parents: 305
diff changeset
  2259
    "Modified: 12.7.1996 / 17:37:48 / cg"
303
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2260
!
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2261
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2262
rememberAllObjectFiles
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2263
    "remember all loaded objectModules in the
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2264
     PreviouslyLoadedObjects classVariable. 
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2265
     Called when an image is restarted to reload all modules which
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2266
     were loaded in the previous life"
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2267
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2268
    LoadedObjects notNil ifTrue:[
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2269
        PreviouslyLoadedObjects := OrderedCollection new.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2270
        LoadedObjects keysAndValuesDo:[:name :handle |
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2271
            handle isForCollectedObject ifTrue:[
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2272
                ('OBJFLOADER: ignore object for already collected objects in ' , name) infoPrintNL
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2273
            ] ifFalse:[
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2274
                PreviouslyLoadedObjects add:(name -> handle)
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2275
            ]
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2276
        ].
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2277
        PreviouslyLoadedObjects sort:[:a :b | a value moduleID < b value moduleID].
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2278
    ]
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2279
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2280
    "Created: 5.12.1995 / 20:51:07 / cg"
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2281
    "Modified: 25.4.1996 / 09:46:08 / cg"
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2282
!
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2283
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2284
revalidateAllObjectFiles
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2285
    "revalidate code refs into all dynamically loaded object files.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2286
     Required after writing a snapshot image."
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2287
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2288
    ActuallyLoadedObjects notNil ifTrue:[
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2289
        ActuallyLoadedObjects keys do:[:aFileName |
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2290
            |handle|
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2291
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2292
            handle := ActuallyLoadedObjects at:aFileName.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2293
            handle isNil ifTrue:[
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2294
                self error:'oops, no handle'.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2295
            ] ifFalse:[
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2296
                (handle isClassLibHandle or:[handle isMethodHandle]) ifTrue:[
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2297
                    self revalidateModule:handle
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2298
                ]
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2299
            ]
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2300
        ].
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2301
        LoadedObjects := ActuallyLoadedObjects.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2302
        ActuallyLoadedObjects := PreviouslyLoadedObjects := nil.
28
a9d33ea0692d loads objces on iris5
claus
parents: 20
diff changeset
  2303
    ].
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2304
303
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2305
    "Created: 5.10.1995 / 15:49:08 / claus"
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2306
    "Modified: 5.10.1995 / 16:49:18 / claus"
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2307
    "Modified: 12.7.1996 / 17:14:48 / cg"
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2308
!
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2309
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2310
unloadAllObjectFiles
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2311
    "unload all dynamically loaded object files from the image.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2312
     see DANGER ALERT in ObjectFileLoader>>unloadObjectFile:"
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2313
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2314
    LoadedObjects notNil ifTrue:[
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2315
	LoadedObjects keys copy do:[:aFileName |
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2316
	    self unloadObjectFile:aFileName
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2317
	]
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2318
    ].
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2319
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2320
    "
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2321
     ObjectFileLoader unloadAllObjectFiles
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2322
    "
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2323
!
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2324
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2325
unloadAndRememberAllObjectFiles
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2326
    "remember all modules and unload them"
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2327
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2328
    LoadedObjects notNil ifTrue:[
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2329
        self rememberAllObjectFiles.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2330
        self unloadAllObjectFiles
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2331
    ]
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2332
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  2333
    "Modified: 25.4.1996 / 09:46:27 / cg"
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2334
! !
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2335
291
c0d5159014be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 286
diff changeset
  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
a469695d8d19 commentary
Claus Gittinger <cg@exept.de>
parents: 252
diff changeset
  2339
    "given an oFile, arrange for it to be loadable.
a469695d8d19 commentary
Claus Gittinger <cg@exept.de>
parents: 252
diff changeset
  2340
     On ELF systems, this means that it has to be linked with the
a469695d8d19 commentary
Claus Gittinger <cg@exept.de>
parents: 252
diff changeset
  2341
     -shared option into a .so file; 
a469695d8d19 commentary
Claus Gittinger <cg@exept.de>
parents: 252
diff changeset
  2342
     DLD based loaders (linux a.out) can directly load a .o file;
a469695d8d19 commentary
Claus Gittinger <cg@exept.de>
parents: 252
diff changeset
  2343
     Other systems may require more ..."
a469695d8d19 commentary
Claus Gittinger <cg@exept.de>
parents: 252
diff changeset
  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
fef1879d2fcf linux-a.out fixes
ca
parents: 183
diff changeset
  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
a469695d8d19 commentary
Claus Gittinger <cg@exept.de>
parents: 252
diff changeset
  2349
        "
a469695d8d19 commentary
Claus Gittinger <cg@exept.de>
parents: 252
diff changeset
  2350
         link it to a shared object with 'ld -shared'
a469695d8d19 commentary
Claus Gittinger <cg@exept.de>
parents: 252
diff changeset
  2351
        "
a469695d8d19 commentary
Claus Gittinger <cg@exept.de>
parents: 252
diff changeset
  2352
        needSharedObject := true.
a469695d8d19 commentary
Claus Gittinger <cg@exept.de>
parents: 252
diff changeset
  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
a469695d8d19 commentary
Claus Gittinger <cg@exept.de>
parents: 252
diff changeset
  2357
        "
a469695d8d19 commentary
Claus Gittinger <cg@exept.de>
parents: 252
diff changeset
  2358
         link it to a shared object with 'ld -G'
a469695d8d19 commentary
Claus Gittinger <cg@exept.de>
parents: 252
diff changeset
  2359
        "
a469695d8d19 commentary
Claus Gittinger <cg@exept.de>
parents: 252
diff changeset
  2360
        needSharedObject := true.
a469695d8d19 commentary
Claus Gittinger <cg@exept.de>
parents: 252
diff changeset
  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
a469695d8d19 commentary
Claus Gittinger <cg@exept.de>
parents: 252
diff changeset
  2365
        ObjectFileLoader loadableBinaryObjectFormat == #elf ifTrue:[
a469695d8d19 commentary
Claus Gittinger <cg@exept.de>
parents: 252
diff changeset
  2366
            "
a469695d8d19 commentary
Claus Gittinger <cg@exept.de>
parents: 252
diff changeset
  2367
             link it to a shared object with 'ld -shared'
a469695d8d19 commentary
Claus Gittinger <cg@exept.de>
parents: 252
diff changeset
  2368
            "
a469695d8d19 commentary
Claus Gittinger <cg@exept.de>
parents: 252
diff changeset
  2369
            needSharedObject := true.
a469695d8d19 commentary
Claus Gittinger <cg@exept.de>
parents: 252
diff changeset
  2370
            ldArg := '-shared'.
a469695d8d19 commentary
Claus Gittinger <cg@exept.de>
parents: 252
diff changeset
  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
fef1879d2fcf linux-a.out fixes
ca
parents: 183
diff changeset
  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
a469695d8d19 commentary
Claus Gittinger <cg@exept.de>
parents: 252
diff changeset
  2376
        soFileName := './' , baseFileName , '.so'. 
a469695d8d19 commentary
Claus Gittinger <cg@exept.de>
parents: 252
diff changeset
  2377
        OperatingSystem executeCommand:'rm -f ' , soFileName.
a469695d8d19 commentary
Claus Gittinger <cg@exept.de>
parents: 252
diff changeset
  2378
        OperatingSystem executeCommand:'ld ' , ldArg , ' -o ' , soFileName , ' ' , oFileName.
a469695d8d19 commentary
Claus Gittinger <cg@exept.de>
parents: 252
diff changeset
  2379
        OperatingSystem removeFile:oFileName.
a469695d8d19 commentary
Claus Gittinger <cg@exept.de>
parents: 252
diff changeset
  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
a469695d8d19 commentary
Claus Gittinger <cg@exept.de>
parents: 252
diff changeset
  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
c0d5159014be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 286
diff changeset
  2392
!ObjectFileLoader  class methodsFor:'loading objects'!
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2393
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2394
loadFile:oFile
20
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2395
    "load in an object file - return a handle or nil.
45
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2396
     This is only needed if no dynamic link facility exists.
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2397
     It allocates some memory for text and data, calls for the linker
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2398
     to relocate the oFile to that address and loads the sections."
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2399
20
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2400
    |unixCommand errStream errors errText
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2401
     text data textSize dataSize dataAddr textAddr newTextSize newDataSize|
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2402
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2403
    "find out, how much memory we need"
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2404
20
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2405
    textSize := self textSizeOf:oFile.
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2406
    textSize isNil ifTrue:[
45
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2407
	'bad text-size in object file' errorPrintNL.
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2408
	^ nil
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2409
    ].
10
73e97b6175c4 *** empty log message ***
claus
parents: 6
diff changeset
  2410
    Verbose ifTrue:[
95
claus
parents: 94
diff changeset
  2411
	('text-size: ' , (textSize printStringRadix:16)) infoPrintNL
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2412
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2413
20
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2414
    dataSize := self dataSizeOf:oFile.
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2415
    dataSize isNil ifTrue:[
45
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2416
	'bad data-size in object file' errorPrintNL.
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2417
	^ nil
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2418
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2419
10
73e97b6175c4 *** empty log message ***
claus
parents: 6
diff changeset
  2420
    Verbose ifTrue:[
95
claus
parents: 94
diff changeset
  2421
	('data-size: ' , (dataSize printStringRadix:16)) infoPrintNL
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2422
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2423
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2424
    "allocate some memory for text and some for data;
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2425
     then call linker to link the file to those addresses"
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2426
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2427
    self needSeparateIDSpaces ifTrue:[
45
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2428
	text := ExternalBytes newForText:textSize.
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2429
	text isNil ifTrue:[
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2430
	    'cannot allocate memory for text' errorPrintNL.
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2431
	    ^ nil
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2432
	].
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2433
45
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2434
	Verbose ifTrue:[
95
claus
parents: 94
diff changeset
  2435
	    ('text: ' , (text address printStringRadix:16)) infoPrintNL
45
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2436
	].
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2437
45
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2438
	(dataSize ~~ 0) ifTrue:[
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2439
	    data := ExternalBytes newForData:dataSize.
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2440
	    (data isNil) ifTrue:[
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2441
		'cannot allocate memory for data' errorPrintNL.
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2442
		text notNil ifTrue:[text free].
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2443
		^ nil
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2444
	    ].
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2445
	    Verbose ifTrue:[
95
claus
parents: 94
diff changeset
  2446
		('data: ' , (data address printStringRadix:16)) infoPrintNL
45
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2447
	    ]
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2448
	].
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2449
	dataSize == 0 ifTrue:[
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2450
	    unixCommand := (self absLd:oFile text:text address) , ' >/tmp/out 2>/tmp/err'.
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2451
	] ifFalse:[
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2452
	    unixCommand := (self absLd:oFile text:text address data:data address) 
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2453
			   , ' >/tmp/out 2>/tmp/err'.
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2454
	]
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2455
    ] ifFalse:[
45
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2456
	text := ExternalBytes newForText:(textSize + dataSize).
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2457
	text isNil ifTrue:[
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2458
	    'cannot allocate memory for text+data' errorPrintNL.
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2459
	    ^ nil
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2460
	].
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2461
	Verbose ifTrue:[
95
claus
parents: 94
diff changeset
  2462
	    ('addr: ' , (text address printStringRadix:16)) infoPrintNL
45
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2463
	].
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2464
	unixCommand := (self absLd:oFile text:text address) , ' >/tmp/out 2>/tmp/err'.
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2465
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2466
10
73e97b6175c4 *** empty log message ***
claus
parents: 6
diff changeset
  2467
    Verbose ifTrue:[
95
claus
parents: 94
diff changeset
  2468
	('executing: ' , unixCommand) infoPrintNL
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2469
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2470
19
84a1ddf215a5 *** empty log message ***
claus
parents: 15
diff changeset
  2471
    'linking ...' printNewline.
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2472
    (OperatingSystem executeCommand:unixCommand) ifFalse: [
45
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2473
	errStream := FileStream oldFileNamed:'/tmp/err'.
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2474
	errStream notNil ifTrue:[
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2475
	    errors := errStream contents.
58
15b00d1236db asText eliminated
claus
parents: 53
diff changeset
  2476
	    errText := errors asStringCollection.
45
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2477
	    (errText size > 20) ifTrue:[
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2478
		errText grow:20.
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2479
		errText add:'... '.
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2480
		errors := errText
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2481
	    ].
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2482
	    OperatingSystem executeCommand:'rm /tmp/err /tmp/out'.
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2483
	    self notify:('link errors:\\' , errors asString) withCRs
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2484
	].
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2485
	'link unsuccessful.' errorPrintNL.
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2486
	text notNil ifTrue:[text free].
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2487
	data notNil ifTrue:[data free].
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2488
	^ nil
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2489
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2490
95
claus
parents: 94
diff changeset
  2491
    'link successful' infoPrintNL.
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2492
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2493
    OperatingSystem executeCommand:'rm /tmp/err /tmp/out'.
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2494
6
0cd4e7480440 *** empty log message ***
claus
parents: 3
diff changeset
  2495
    "find out, if space needs have changed after link (they do so on some machines)"
0cd4e7480440 *** empty log message ***
claus
parents: 3
diff changeset
  2496
20
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2497
    newTextSize := self textSizeOf:'a.out'.
6
0cd4e7480440 *** empty log message ***
claus
parents: 3
diff changeset
  2498
    newTextSize isNil ifTrue:[
45
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2499
	'bad new-text-size in a.out object file' errorPrintNL.
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2500
	text notNil ifTrue:[text free].
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2501
	data notNil ifTrue:[data free].
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2502
	^ nil
6
0cd4e7480440 *** empty log message ***
claus
parents: 3
diff changeset
  2503
    ].
10
73e97b6175c4 *** empty log message ***
claus
parents: 6
diff changeset
  2504
    Verbose ifTrue:[
95
claus
parents: 94
diff changeset
  2505
	('new-text-size: ' , (newTextSize printStringRadix:16)) infoPrintNL
6
0cd4e7480440 *** empty log message ***
claus
parents: 3
diff changeset
  2506
    ].
0cd4e7480440 *** empty log message ***
claus
parents: 3
diff changeset
  2507
20
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2508
    newDataSize := self dataSizeOf:'a.out'.
6
0cd4e7480440 *** empty log message ***
claus
parents: 3
diff changeset
  2509
    newDataSize isNil ifTrue:[
45
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2510
	'bad new-data-size in a.out object file' errorPrintNL.
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2511
	text notNil ifTrue:[text free].
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2512
	data notNil ifTrue:[data free].
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2513
	^ nil
6
0cd4e7480440 *** empty log message ***
claus
parents: 3
diff changeset
  2514
    ].
0cd4e7480440 *** empty log message ***
claus
parents: 3
diff changeset
  2515
10
73e97b6175c4 *** empty log message ***
claus
parents: 6
diff changeset
  2516
    Verbose ifTrue:[
95
claus
parents: 94
diff changeset
  2517
	('new-data-size: ' , (newDataSize printStringRadix:16)) infoPrintNL
6
0cd4e7480440 *** empty log message ***
claus
parents: 3
diff changeset
  2518
    ].
0cd4e7480440 *** empty log message ***
claus
parents: 3
diff changeset
  2519
0cd4e7480440 *** empty log message ***
claus
parents: 3
diff changeset
  2520
    "if size has changed, do it again"
0cd4e7480440 *** empty log message ***
claus
parents: 3
diff changeset
  2521
0cd4e7480440 *** empty log message ***
claus
parents: 3
diff changeset
  2522
    ((newTextSize ~~ textSize) or:[newDataSize ~~ dataSize]) ifTrue:[
0cd4e7480440 *** empty log message ***
claus
parents: 3
diff changeset
  2523
45
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2524
	'size changed after link - do it again' printNewline.
6
0cd4e7480440 *** empty log message ***
claus
parents: 3
diff changeset
  2525
45
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2526
	text notNil ifTrue:[text free. text := nil].
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2527
	data notNil ifTrue:[data free. data := nil].
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2528
	textSize := newTextSize.
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2529
	dataSize := newDataSize.
6
0cd4e7480440 *** empty log message ***
claus
parents: 3
diff changeset
  2530
45
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2531
	self needSeparateIDSpaces ifTrue:[
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2532
	    text := ExternalBytes newForText:textSize.
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2533
	    text isNil ifTrue:[
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2534
		'cannot allocate memory for new text' errorPrintNL.
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2535
		^ nil
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2536
	    ].
6
0cd4e7480440 *** empty log message ***
claus
parents: 3
diff changeset
  2537
45
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2538
	    Verbose ifTrue:[
95
claus
parents: 94
diff changeset
  2539
		('new text: ' , (text address printStringRadix:16)) infoPrintNL
45
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2540
	    ].
6
0cd4e7480440 *** empty log message ***
claus
parents: 3
diff changeset
  2541
45
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2542
	    (dataSize ~~ 0) ifTrue:[
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2543
		data := ExternalBytes newForData:dataSize.
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2544
		(data isNil) ifTrue:[
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2545
		    'cannot allocate memory for new data' errorPrintNL.
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2546
		    text notNil ifTrue:[text free].
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2547
		    ^ nil
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2548
		].
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2549
		Verbose ifTrue:[
95
claus
parents: 94
diff changeset
  2550
		    ('new data: ' , (data address printStringRadix:16)) infoPrintNL
45
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2551
		]
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2552
	    ].
6
0cd4e7480440 *** empty log message ***
claus
parents: 3
diff changeset
  2553
45
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2554
	    dataSize == 0 ifTrue:[
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2555
		unixCommand := (self absLd:oFile text:text address) , ' >/tmp/out 2>/tmp/err'.
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2556
	    ] ifFalse:[
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2557
		unixCommand := (self absLd:oFile text:text address data:data address) 
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2558
			       , ' >/tmp/out 2>/tmp/err'.
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2559
	    ]
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2560
	] ifFalse:[
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2561
	    text := ExternalBytes newForText:(textSize + dataSize).
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2562
	    text isNil ifTrue:[
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2563
		'cannot allocate memory for new text' errorPrintNL.
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2564
		^ nil
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2565
	    ].
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2566
	    Verbose ifTrue:[
95
claus
parents: 94
diff changeset
  2567
		('new text+data: ' , (text address printStringRadix:16)) infoPrintNL
45
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2568
	    ].
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2569
	    unixCommand := (self absLd:oFile text:text address) , ' >/tmp/out 2>/tmp/err'.
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2570
	].
6
0cd4e7480440 *** empty log message ***
claus
parents: 3
diff changeset
  2571
45
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2572
	Verbose ifTrue:[
95
claus
parents: 94
diff changeset
  2573
	    ('executing: ' , unixCommand) infoPrintNL
45
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2574
	].
6
0cd4e7480440 *** empty log message ***
claus
parents: 3
diff changeset
  2575
95
claus
parents: 94
diff changeset
  2576
	'linking ...' infoPrintNL.
45
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2577
	(OperatingSystem executeCommand:unixCommand) ifFalse: [
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2578
	    errStream := FileStream oldFileNamed:'/tmp/err'.
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2579
	    errStream notNil ifTrue:[
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2580
		errors := errStream contents.
58
15b00d1236db asText eliminated
claus
parents: 53
diff changeset
  2581
		errText := errors asStringCollection.
45
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2582
		(errText size > 20) ifTrue:[
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2583
		    errText grow:20.
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2584
		    errText add:'... '.
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2585
		    errors := errText
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2586
		].
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2587
		OperatingSystem executeCommand:'rm /tmp/err /tmp/out'.
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2588
		self notify:('link errors:\\' , errors asString) withCRs
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2589
	    ].
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2590
	    'link unsuccessful.' errorPrintNL.
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2591
	    text notNil ifTrue:[text free].
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2592
	    data notNil ifTrue:[data free].
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2593
	    ^ nil
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2594
	].
6
0cd4e7480440 *** empty log message ***
claus
parents: 3
diff changeset
  2595
95
claus
parents: 94
diff changeset
  2596
	'link successful' infoPrintNL.
6
0cd4e7480440 *** empty log message ***
claus
parents: 3
diff changeset
  2597
45
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2598
	OperatingSystem executeCommand:'rm /tmp/err /tmp/out'.
6
0cd4e7480440 *** empty log message ***
claus
parents: 3
diff changeset
  2599
45
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2600
	"check again for size change - should not happen"
6
0cd4e7480440 *** empty log message ***
claus
parents: 3
diff changeset
  2601
45
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2602
	newTextSize := self textSizeOf:'a.out'.
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2603
	newTextSize isNil ifTrue:[
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2604
	    'bad text-size in a.out object file' errorPrintNL.
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2605
	    text notNil ifTrue:[text free].
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2606
	    data notNil ifTrue:[data free].
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2607
	    ^ nil
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2608
	].
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2609
	Verbose ifTrue:[
95
claus
parents: 94
diff changeset
  2610
	    ('new-text-size: ' , (newTextSize printStringRadix:16)) infoPrintNL
45
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2611
	].
6
0cd4e7480440 *** empty log message ***
claus
parents: 3
diff changeset
  2612
45
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2613
	newDataSize := self dataSizeOf:'a.out'.
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2614
	newDataSize isNil ifTrue:[
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2615
	    'bad data-size in object file' errorPrintNL.
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2616
	    text notNil ifTrue:[text free].
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2617
	    data notNil ifTrue:[data free].
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2618
	    ^ nil
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2619
	].
6
0cd4e7480440 *** empty log message ***
claus
parents: 3
diff changeset
  2620
45
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2621
	Verbose ifTrue:[
95
claus
parents: 94
diff changeset
  2622
	    ('new-data-size: ' , (newDataSize printStringRadix:16)) infoPrintNL
45
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2623
	].
6
0cd4e7480440 *** empty log message ***
claus
parents: 3
diff changeset
  2624
45
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2625
	((newTextSize ~~ textSize) or:[newDataSize ~~ dataSize]) ifTrue:[
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2626
	    'size changed again - I give up' errorPrintNL.
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2627
	    text notNil ifTrue:[text free].
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2628
	    data notNil ifTrue:[data free].
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2629
	    ^ nil
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2630
	].
6
0cd4e7480440 *** empty log message ***
claus
parents: 3
diff changeset
  2631
    ].
0cd4e7480440 *** empty log message ***
claus
parents: 3
diff changeset
  2632
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2633
    "only thing left to do is to load in text at textAddr and
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2634
     data at dataAddr ... "
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2635
6
0cd4e7480440 *** empty log message ***
claus
parents: 3
diff changeset
  2636
    text notNil ifTrue:[
45
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2637
	textAddr := text address
6
0cd4e7480440 *** empty log message ***
claus
parents: 3
diff changeset
  2638
    ] ifFalse:[
45
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2639
	textAddr := nil
6
0cd4e7480440 *** empty log message ***
claus
parents: 3
diff changeset
  2640
    ].
0cd4e7480440 *** empty log message ***
claus
parents: 3
diff changeset
  2641
    data notNil ifTrue:[
45
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2642
	dataAddr := data address
6
0cd4e7480440 *** empty log message ***
claus
parents: 3
diff changeset
  2643
    ] ifFalse:[
45
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2644
	dataAddr := nil
6
0cd4e7480440 *** empty log message ***
claus
parents: 3
diff changeset
  2645
    ].
0cd4e7480440 *** empty log message ***
claus
parents: 3
diff changeset
  2646
19
84a1ddf215a5 *** empty log message ***
claus
parents: 15
diff changeset
  2647
    Verbose ifTrue:[
45
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2648
	textAddr notNil ifTrue:[
95
claus
parents: 94
diff changeset
  2649
	    ('loading ' , textSize printString , ' bytes at ' , (textAddr printStringRadix:16)) infoPrintNL.
45
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2650
	].
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2651
	dataAddr notNil ifTrue:[
95
claus
parents: 94
diff changeset
  2652
	    ('loading ' , dataSize printString , ' bytes at ' , (dataAddr printStringRadix:16)) infoPrintNL.
45
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2653
	].
19
84a1ddf215a5 *** empty log message ***
claus
parents: 15
diff changeset
  2654
    ].
6
0cd4e7480440 *** empty log message ***
claus
parents: 3
diff changeset
  2655
20
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2656
    (self loadObjectFile:'a.out'
45
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2657
		textAddr:textAddr textSize:textSize
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2658
		dataAddr:dataAddr dataSize:dataSize) isNil ifTrue: [
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2659
	'load error' errorPrintNL.
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2660
	text notNil ifTrue:[text free].
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2661
	data notNil ifTrue:[data free].
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2662
	^ nil
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2663
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2664
95
claus
parents: 94
diff changeset
  2665
    'dynamic load successful' infoPrintNL.
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2666
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2667
    OperatingSystem executeCommand:'mv a.out SymbolTable'.
10
73e97b6175c4 *** empty log message ***
claus
parents: 6
diff changeset
  2668
    MySymbolTable := 'SymbolTable'.
45
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2669
    ^ (Array with:text with:data)
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2670
!
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2671
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2672
loadFile:oFile with:librariesString
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2673
    "load in an object files code, linking in libraries.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2674
     This is only needed if no dynamic link facility exists."
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2675
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2676
    |tmpOfile errStream errors errText handle pid cmd|
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2677
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2678
    pid := OperatingSystem getProcessId printString.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2679
    tmpOfile := '/tmp/stc_ld' ,  pid.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2680
    cmd := 'ld -o ', tmpOfile, ' -r ' , oFile , ' ' , librariesString , '>/tmp/out 2>/tmp/err'.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2681
    Verbose ifTrue:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2682
	('executing: ld -o ', cmd) infoPrintNL
20
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2683
    ].
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2684
    (OperatingSystem executeCommand:cmd) ifFalse:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2685
	errStream := FileStream oldFileNamed:'/tmp/err'.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2686
	errStream isNil ifTrue:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2687
	    self notify:'errors during link.'
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2688
	] ifFalse:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2689
	    errors := errStream contents.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2690
	    errText := errors asStringCollection.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2691
	    (errText size > 20) ifTrue:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2692
		errText grow:20.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2693
		errText add:'... '.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2694
		errors := errText
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2695
	    ].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2696
	    OperatingSystem executeCommand:'rm /tmp/err /tmp/out'.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2697
	    self notify:('link errors:\\' , errors asString) withCRs
45
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2698
	].
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2699
	^ false
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2700
    ].
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2701
    handle := self loadFile:tmpOfile.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2702
    OperatingSystem executeCommand:('rm ' , tmpOfile).
15
992c3d87edbf *** empty log message ***
claus
parents: 10
diff changeset
  2703
    ^ handle
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2704
! !
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2705
291
c0d5159014be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 286
diff changeset
  2706
!ObjectFileLoader  class methodsFor:'primitive loading'!
20
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2707
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2708
dataSizeOf:aFileName
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2709
    "
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2710
     get the size of the data-segment (nBytes)
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2711
    "
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2712
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2713
%{  /* NOCONTEXT */
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2714
#ifdef HAS_DL
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2715
    /*
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2716
     * not needed, if dynamic link facilities exist
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2717
     */
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2718
#else /* no DL-support */
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2719
    char *fname;
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2720
    int fd;
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2721
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2722
    if (! __isString(aFileName)) {
45
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2723
	RETURN ( nil );
20
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2724
    }
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2725
98
claus
parents: 97
diff changeset
  2726
    fname = (char *) __stringVal(aFileName);
20
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2727
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2728
# if defined(A_DOT_OUT) && !defined(ELF)
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2729
#  if !defined(sco) && !defined(isc)
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2730
    {
45
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2731
	struct exec header;
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2732
	unsigned size;
20
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2733
45
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2734
	if ((fd = open(fname, 0)) < 0) {
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2735
	    fprintf(stderr, "cannot open <%s>\n", fname);
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2736
	    RETURN ( nil );
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2737
	}
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2738
	if (read(fd, &header, sizeof(header)) != sizeof(header)) {
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2739
	    fprintf(stderr, "cannot read header of <%s>\n", fname);
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2740
	    close(fd);
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2741
	    RETURN ( nil );
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2742
	}
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2743
	close(fd);
20
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2744
45
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2745
	if (N_MAGIC(header) != OMAGIC) {
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2746
	    fprintf(stderr, "header is (0%o) %x - should be (0%o)%x\n",
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2747
					N_MAGIC(header), N_MAGIC(header),
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2748
					OMAGIC, OMAGIC);
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2749
	    RETURN ( nil );
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2750
	}
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2751
	size = header.a_data;
20
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2752
#   if defined(sinix) && defined(BSD)
45
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2753
	size += header.a_bss;
20
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2754
#   endif
238
4d80cc4b86dd underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 228
diff changeset
  2755
	RETURN ( __MKSMALLINT(size) );
20
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2756
    }
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2757
#  endif
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2758
# endif
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2759
    /*
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2760
     * need support for other headers ... (i.e. coff, elf)
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  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
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2763
%}
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2764
.
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2765
    ^ self error:'objectFile format not supported'
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2766
!
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2767
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2768
loadObjectFile:aFileName textAddr:textAddr textSize:textSize
45
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2769
			 dataAddr:dataAddr dataSize:dataSize
20
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2770
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2771
    "the object in aFileName must have been linked for
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2772
     absolute address textAddr/dataAddr (using ld -A).
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2773
     Load the contents from the file. Memory must have previously
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2774
     been allocated using ExternalBytes."
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2775
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2776
%{  /* NOCONTEXT */
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2777
#ifdef HAS_DL
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2778
    /*
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2779
     * not needed, if dynamic link facilities exist
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2780
     */
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2781
#else /* no DL-support */
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2782
    if (! __isString(aFileName)) {
45
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2783
	RETURN ( nil );
20
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2784
    }
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2785
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2786
# if defined(A_DOT_OUT) && !defined(ELF)
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2787
#  if !defined(sco) && !defined(isc)
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2788
    {
98
claus
parents: 97
diff changeset
  2789
	char *fname = (char *) __stringVal(aFileName);
45
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2790
	unsigned taddr, daddr;
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2791
	unsigned tsize, dsize;
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2792
	unsigned toffset = 0;
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2793
	unsigned doffset = 0;
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2794
	int fd;
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2795
	struct exec header;
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2796
	char *cp;
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2797
	int bssCount;
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2798
	unsigned magic = OMAGIC;
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2799
	int nread;
20
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2800
60
0db697f03def *** empty log message ***
claus
parents: 58
diff changeset
  2801
	taddr = __isSmallInteger(textAddr) ? (unsigned) _intVal(textAddr) : 0;
0db697f03def *** empty log message ***
claus
parents: 58
diff changeset
  2802
	daddr = __isSmallInteger(dataAddr) ? (unsigned) _intVal(dataAddr) : 0;
0db697f03def *** empty log message ***
claus
parents: 58
diff changeset
  2803
	tsize = __isSmallInteger(textSize) ? _intVal(textSize) : 0;
0db697f03def *** empty log message ***
claus
parents: 58
diff changeset
  2804
	dsize = __isSmallInteger(dataSize) ? _intVal(dataSize) : 0;
20
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2805
45
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2806
	if ((fd = open(fname, 0)) < 0)  {
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2807
	    fprintf(stderr, "cannot open <%s>\n", fname);
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2808
	    RETURN ( nil );
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2809
	}
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2810
	if (read(fd, &header, sizeof(header)) != sizeof(header)) {
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2811
	    fprintf(stderr, "cannot read header of <%s>\n", fname);
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2812
	    close(fd);
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2813
	    RETURN ( nil );
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2814
	}
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2815
	if (N_MAGIC(header) != magic) {
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2816
	    fprintf(stderr, "header is (0%o) %x should be (0%o) %x\n",
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2817
					N_MAGIC(header), N_MAGIC(header),
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2818
					magic, magic);
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2819
	    close(fd);
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2820
	    RETURN ( nil );
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2821
	}
20
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2822
45
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2823
	/*
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2824
	 * some linkers produce a huge output file, with zeros up to the
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2825
	 * real code ... - thats what toffset, doffset are for.
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2826
	 */
20
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2827
#   if defined(sinix) && defined(BSD)
45
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2828
	toffset = N_TXTADDR(header);
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2829
	doffset = toffset + taddr + tsize /* - 0x800 */;
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2830
	daddr = taddr + tsize;
20
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2831
#   else
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2832
#    if defined(mips) && defined(ultrix)
45
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2833
	toffset = N_TXTOFF(header.ex_f, header.ex_o);
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2834
	doffset = toffset + tsize;
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2835
	daddr = taddr + tsize;
20
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2836
#    else
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2837
#     if defined(N_TXTOFF)
45
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2838
	toffset = N_TXTOFF(header);
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2839
	doffset = N_DATOFF(header);
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2840
	daddr = taddr + tsize;
20
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2841
#     else
45
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2842
	fprintf(stderr, "dont know text/data offsets in objectfile\n");
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2843
	RETURN ( nil );
20
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2844
#     endif
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2845
#    endif
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2846
#   endif
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2847
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2848
#   ifdef SUPERDEBUG
45
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2849
	printf("toffs:%x taddr:%x tsize:%d doffs:%x daddr:%x dsize:%d\n",
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2850
		toffset, taddr, tsize, doffset,daddr, dsize);
20
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2851
#   endif
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2852
45
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2853
	if (lseek(fd, (long)toffset, 0) < 0) {
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2854
	    fprintf(stderr, "cannot seek to text\n");
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2855
	    close(fd);
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2856
	    RETURN ( nil );
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2857
	}
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2858
	if ((nread = read(fd, taddr, tsize)) != tsize) {
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2859
	    perror("read");
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2860
	    fprintf(stderr, "cannot read text wanted:%d got:%d\n", tsize, nread);
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2861
	    close(fd);
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2862
	    RETURN ( nil );
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2863
	}
20
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2864
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2865
#   ifdef SUPERDEBUG
45
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2866
	printf("1st bytes of text: %02x %02x %02x %02x\n",
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2867
		*((char *)taddr) & 0xFF, *((char *)taddr+1) & 0xFF,
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2868
		*((char *)taddr+2) & 0xFF, *((char *)taddr+3) & 0xFF);
20
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2869
#   endif
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2870
45
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2871
	if (dsize) {
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2872
	    if (lseek(fd, (long)doffset, 0) < 0) {
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2873
		fprintf(stderr, "cannot seek to data\n");
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2874
		close(fd);
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2875
		RETURN ( nil );
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2876
	    }
20
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2877
45
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2878
	    if (read(fd, daddr, dsize) != dsize) {
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2879
		fprintf(stderr, "cannot read data\n");
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2880
		close(fd);
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2881
		RETURN ( nil );
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2882
	    }
20
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2883
#   ifdef SUPERDEBUG
45
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2884
	    {
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2885
		char *ptr;
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2886
		int i;
20
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2887
    
45
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2888
		ptr = (char *)daddr;
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2889
		fprintf(stderr, "bytes of data (at %x):\n", ptr);
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2890
		for (i=dsize; i>0; i--, ptr++)
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2891
		    printf("%02x ", *ptr & 0xFF);
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2892
	    }
20
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2893
#   endif
45
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2894
	}
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2895
	close(fd);
20
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2896
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2897
#   ifdef NOTDEF
45
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2898
	if (header.a_bss != 0) {
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2899
	    fprintf(stderr, "warning: bss not empty\n");
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2900
	    cp = ((char *)daddr) + header.a_data;
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2901
	    for (bssCount=header.a_bss; bssCount; bssCount--)
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2902
		*cp++ = 0;
e8331ba8ad5d *** empty log message ***
claus
parents: 37
diff changeset
  2903
	}
20
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2904
#   endif
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2905
    }
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2906
    RETURN ( self );
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2907
#  endif
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2908
# endif
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2909
    /*
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2910
     * need support for other headers ... (i.e. coff, elf)
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2911
     */
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2912
#endif
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2913
%}.
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  2914
    ^ self error:'objectFile format not supported'
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2915
!
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2916
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2917
textSizeOf:aFileName
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2918
    "
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2919
     get the size of the text-segment (nBytes)
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2920
    "
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2921
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2922
%{  /* NOCONTEXT */
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2923
#ifdef HAS_DL
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2924
    /*
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2925
     * not needed, if dynamic link facilities exist
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2926
     */
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2927
#else /* no DL-support */
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2928
    char *fname;
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2929
    int fd;
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2930
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2931
    if (! __isString(aFileName)) {
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2932
	RETURN (nil);
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2933
    }
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2934
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2935
    fname = (char *) __stringVal(aFileName);
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2936
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2937
# if defined(A_DOT_OUT) && !defined(ELF)
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2938
#  if !defined(sco) && !defined(isc)
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2939
    {
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2940
	struct exec header;
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2941
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2942
	if ((fd = open(fname, 0)) < 0) {
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2943
	    fprintf(stderr, "cannot open <%s>\n", fname);
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2944
	    RETURN ( nil );
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2945
	}
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2946
	if (read(fd, &header, sizeof(header)) != sizeof(header)) {
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2947
	    fprintf(stderr, "cannot read header of <%s>\n", fname);
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2948
	    close(fd);
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2949
	    RETURN ( nil );
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2950
	}
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2951
	close(fd);
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2952
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2953
	if (N_MAGIC(header) != OMAGIC) {
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2954
	    fprintf(stderr, "header is (0%o) %x - should be (0%o)%x\n",
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2955
					N_MAGIC(header), N_MAGIC(header),
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2956
					OMAGIC, OMAGIC);
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2957
	    RETURN ( nil );
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2958
	}
238
4d80cc4b86dd underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 228
diff changeset
  2959
	RETURN ( __MKSMALLINT(header.a_text) );
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2960
    }
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2961
#  endif
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2962
# endif
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2963
    /*
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2964
     * need support for other headers ... (i.e. coff, elf)
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2965
     */
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2966
#endif
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2967
%}.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2968
    ^ self error:'objectFile format not supported'
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2969
! !
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2970
291
c0d5159014be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 286
diff changeset
  2971
!ObjectFileLoader  class methodsFor:'queries'!
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2972
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2973
canLoadObjectFiles
259
a469695d8d19 commentary
Claus Gittinger <cg@exept.de>
parents: 252
diff changeset
  2974
    "return true, if dynamic loading is possible.
a469695d8d19 commentary
Claus Gittinger <cg@exept.de>
parents: 252
diff changeset
  2975
     Currently, only ELF based systems and linux a.out can do this."
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2976
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2977
    self primCanLoadObjectFiles ifTrue:[^true].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2978
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2979
    "/ can add a return true here, if I ever get manual loading to work
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2980
    "/ for some specific machine
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2981
    ^ false
259
a469695d8d19 commentary
Claus Gittinger <cg@exept.de>
parents: 252
diff changeset
  2982
a469695d8d19 commentary
Claus Gittinger <cg@exept.de>
parents: 252
diff changeset
  2983
    "Modified: 25.4.1996 / 09:51:39 / cg"
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2984
!
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2985
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2986
loadedObjectFiles
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2987
    "return a collection containing the names of all
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2988
     dynamically loaded objects."
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2989
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2990
    LoadedObjects isNil ifTrue:[^ #()].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2991
    ^ LoadedObjects keys copy
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2992
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2993
    "
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2994
     ObjectFileLoader loadedObjectFiles
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2995
    "
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2996
!
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2997
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2998
loadedObjectHandles
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  2999
    "return a collection of all handles"
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  3000
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  3001
    LoadedObjects isNil ifTrue:[^ #()].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  3002
    ^ LoadedObjects 
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  3003
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  3004
    "
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  3005
     ObjectFileLoader loadedObjectHandles
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  3006
    "
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  3007
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  3008
    "Created: 17.9.1995 / 14:28:55 / claus"
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  3009
    "Modified: 17.9.1995 / 16:13:48 / claus"
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  3010
!
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  3011
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  3012
loadedObjectHandlesDo:aBlock
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  3013
    "enumerate all handles"
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  3014
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  3015
    LoadedObjects notNil ifTrue:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  3016
	LoadedObjects copy do:aBlock.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  3017
    ].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  3018
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  3019
    "
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  3020
     ObjectFileLoader loadedObjectHandlesDo:[:h | h pathName printNL]
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  3021
    "
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  3022
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  3023
    "Created: 14.9.1995 / 22:03:13 / claus"
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  3024
    "Modified: 14.9.1995 / 22:32:48 / claus"
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  3025
!
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  3026
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  3027
pathNameFromID:id
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  3028
    "given an id, return the pathName, or nil for static modules"
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  3029
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  3030
    LoadedObjects notNil ifTrue:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  3031
	LoadedObjects keysAndValuesDo:[:name :handle |
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  3032
	    handle moduleID == id ifTrue:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  3033
		^ handle pathName
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  3034
	    ]
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  3035
	].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  3036
    ].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  3037
    ^ nil
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  3038
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  3039
    "
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  3040
     ObjectFileLoader pathNameFromID:1        
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  3041
    "
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  3042
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  3043
    "Modified: 28.8.1995 / 18:08:28 / claus"
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  3044
!
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  3045
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  3046
primCanLoadObjectFiles
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  3047
    "return true, if loading is possible using a standard mechanism"
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  3048
%{  /* NOCONTEXT */
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  3049
#ifdef HAS_DL
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  3050
# if !defined(OS_DEFINE) || defined(unknownOS)
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  3051
    fprintf(stderr, "*** OS_DEFINE not correct\n");
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  3052
# else
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  3053
#  if !defined(CPU_DEFINE) || defined(unknownCPU)
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  3054
    fprintf(stderr, "*** CPU_DEFINE not correct\n");
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  3055
#  else
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  3056
    RETURN (true);
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  3057
#  endif
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  3058
# endif
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  3059
#endif
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  3060
%}.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 138
diff changeset
  3061
    ^ false
20
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  3062
! !
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
  3063
303
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3064
!ObjectFileLoader  class methodsFor:'st object file handling'!
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3065
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3066
callInitFunctionAt:address specialInit:special forceOld:forceOld interruptable:interruptable argument:argument identifyAs:handle returnsObject:returnsObject
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3067
    "call a function at address - a very dangerous operation.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3068
     This is needed to call the classes init-function after loading in a
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3069
     class-object file or to call the CTORS when c++ modules are loaded.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3070
     ForceOld (if true) will have the memory manager
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3071
     allocate things in oldSpace instead of newSpace.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3072
     If special is true, this is a smalltalk moduleInit (i.e. pass the vm-entries table);
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3073
     otherwise, its called without arguments.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3074
     If its a smalltalk-moduleInit, it may be either for a classPackage (which should
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3075
     install all of its classes) or for a single incrementally compiled methdod
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3076
     (it should then NOT install it, but return the method object instead).
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3077
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  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
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3080
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3081
    |low hi lowAddr hiAddr moduleID retVal|
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3082
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3083
    hi := address // 16r10000.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3084
    low := address \\ 16r10000.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  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
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3087
    ].
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3088
%{  /* CALLSSTACK: 32000 */
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3089
    OBJ (*addr)();
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3090
    unsigned val;
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3091
    int savInt;
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  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
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3094
    int wasBlocked = 1;
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3095
    extern int __oldSpaceSize(), __oldSpaceUsed();
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3096
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  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
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3146
    }
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3147
%}.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3148
    self primitiveFailed
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3149
!
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3150
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  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
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3154
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3155
    |classes|
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3156
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3157
    classes := handle classes.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  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
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  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
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3171
!
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3172
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3173
invalidateModule:handle
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3174
    "invalidate all of the classes code objects ..."
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3175
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3176
    |id|
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3177
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3178
    Verbose ifTrue:[
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3179
	'invalidate module; name=' infoPrint. handle pathName infoPrint.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3180
	' id=' infoPrint. handle moduleID infoPrintNL.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3181
    ].
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3182
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3183
    id := handle moduleID.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3184
%{
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3185
    __INVALIDATE_BY_ID(__intVal(id));
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3186
%}
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3187
!
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3188
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3189
loadStatusFor:className
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3190
    "ask VM if class-hierarchy has been completely loaded, and return the status."
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3191
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3192
    |checker checkSymbol statusCode status badClassName|
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3193
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3194
    checker := self.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3195
    checkSymbol := #'superClassCheck:'.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3196
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3197
%{  /* NOREGISTER */
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3198
    char *badName;
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3199
    char *interrestingClassName;
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3200
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3201
    if (__isString(className) || __isSymbol(className)) {
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3202
	interrestingClassName = __stringVal(className);
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3203
    } else {
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3204
	interrestingClassName = (char *)0;
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3205
    }
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3206
    statusCode = __MKSMALLINT(__check_registration__(interrestingClassName,
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3207
						     &checker, &checkSymbol, &badName));
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3208
    if (badName) {
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3209
	badClassName = __MKSTRING(badName);
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3210
    }
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3211
%}.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3212
    statusCode == 0 ifTrue:[
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3213
	status := #ok
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3214
    ] ifFalse:[
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3215
	statusCode == -1 ifTrue:[
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3216
	    status := #missingClass
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3217
	] ifFalse:[
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3218
	    statusCode == -2 ifTrue:[
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3219
		status := #versionMismatch
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3220
	    ] ifFalse:[
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3221
		statusCode == -3 ifTrue:[
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3222
		    status := #unregisteredSuperclass
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3223
		] ifFalse:[
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3224
		    status := #loadFailed
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3225
		]
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3226
	    ]
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3227
	]
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3228
    ].
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3229
    ^ Array with:status with:badClassName.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3230
!
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3231
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3232
moduleInit:phase forceOld:forceOld interruptable:interruptable
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3233
    "initialization phases after registration.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3234
     DANGER: Pure magic; internal only -> dont use in your programs."
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3235
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3236
%{
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3237
    int savInt;
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3238
    int prevSpace, force;
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3239
    int arg = 0;
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3240
    int wasBlocked = 1;
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3241
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3242
    if (_isSmallInteger(phase)) {
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3243
	if (interruptable != true) {
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3244
	    wasBlocked = (__BLOCKINTERRUPTS() == true);
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3245
	}
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3246
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3247
	force = (forceOld == true);
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3248
	if (force) {
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3249
	    prevSpace = __allocForceSpace(OLDSPACE);
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3250
	}
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3251
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3252
	__init_registered_modules__(__intVal(phase) COMMA_CON);
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3253
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3254
	if (force) {
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3255
	    __allocForceSpace(prevSpace);
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3256
	}
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3257
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3258
	if (! wasBlocked) {
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3259
	    __UNBLOCKINTERRUPTS();
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3260
	}
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3261
	RETURN (self);
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3262
    }
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3263
%}.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3264
    self primitiveFailed
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3265
!
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3266
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3267
performModuleInitAt:initAddr for:className identifyAs:handle
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3268
    "Initialize a loaded smalltalk module."
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3269
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3270
    |status badClassName infoCollection info classNames classes|
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3271
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3272
    "
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3273
     need 4 passes to init: 0: let module register itself & create its pools/globals
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3274
                            0b check if modules superclasses are all loaded
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3275
                            1: let it get var-refs to other pools/globals
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3276
                            2: let it install install class, methods and literals
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3277
                            3: let it send #initialize to its class object
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3278
    "
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3279
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3280
    "/
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3281
    "/ let it register itself
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3282
    "/ and define its globals
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3283
    "/
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3284
    Verbose ifTrue:[
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3285
        'phase 0 ...' infoPrintNL
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3286
    ].
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3287
    self callInitFunctionAt:initAddr 
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3288
         specialInit:true 
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3289
         forceOld:true 
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3290
         interruptable:false
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3291
         argument:0
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3292
         identifyAs:handle
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3293
         returnsObject:false.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3294
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3295
    "/
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3296
    "/ check if superclasses are present
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3297
    "/
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3298
    info := self loadStatusFor:className.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3299
    status := info at:1.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3300
    badClassName := info at:2.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3301
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3302
    Verbose ifTrue:[
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3303
        '... status is ' infoPrint. info infoPrintNL
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3304
    ].
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3305
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3306
    (status ~~ #ok) ifTrue:[
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3307
        (status == #missingClass) ifTrue:[
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3308
            Transcript showCR:'load failed - missing class: ' , badClassName.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3309
            ^ info
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3310
        ].
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3311
        (status == #versionMismatch) ifTrue:[
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3312
            Transcript showCR:'load failed - version mismatch: ' , badClassName.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3313
            ^ info
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3314
        ].
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3315
        (status == #unregisteredSuperclass) ifTrue:[
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3316
            Transcript showCR:'load failed - unregistered: ' , badClassName.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3317
            ^ info
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3318
        ].
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3319
        Transcript showCR:'load failed'.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3320
        ^ Array with:#loadFailed with:nil
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3321
    ].
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3322
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3323
    "/
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3324
    "/ remaining initialization
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3325
    "/
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3326
    Verbose ifTrue:[
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3327
        'phase 1 ...' infoPrintNL
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3328
    ].
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3329
    self moduleInit:1 forceOld:true interruptable:false.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3330
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3331
    Verbose ifTrue:[
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3332
        'phase 2 ...' infoPrintNL
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3333
    ].
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3334
    self moduleInit:2 forceOld:true interruptable:false.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3335
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3336
    Verbose ifTrue:[
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3337
        'phase 3 ...' infoPrintNL
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3338
    ].
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3339
    ObjectMemory flushCaches.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3340
    self moduleInit:3 forceOld:false interruptable:true.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3341
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3342
    "/ ask objectMemory for the classes we have just loaded
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3343
    "/ and register them in the handle
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3344
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3345
    infoCollection := ObjectMemory binaryModuleInfo.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3346
    info := infoCollection at:handle moduleID ifAbsent:nil.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3347
    info isNil ifTrue:[
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3348
        "/ mhmh registration failed -
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3349
        ^ Array with:#registrationFailed with:nil
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3350
    ].
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3351
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3352
    classNames := info at:#classNames.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3353
    classNames size > 0 ifTrue:[
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3354
        classes := classNames collect:[:nm | Smalltalk classNamed:nm].
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3355
    ].
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3356
    classes size > 0 ifTrue:[
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3357
        classes := classes asArray.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3358
        classes := classes , (classes collect:[:aClass | aClass class]).
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3359
    ].
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3360
    handle classes:classes.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3361
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3362
    ^ Array with:#ok with:nil
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3363
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3364
    "Modified: 18.5.1996 / 15:44:05 / cg"
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3365
!
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3366
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3367
revalidateModule:handle
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3368
    "revalidate all of the classes code objects ..."
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3369
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3370
    |id|
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3371
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3372
    Verbose ifTrue:[
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3373
	'revalidate module; name=' infoPrint. handle pathName infoPrint.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3374
	' id=' infoPrint. handle moduleID infoPrintNL.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3375
    ].
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3376
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3377
    id := handle moduleID.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3378
%{
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3379
    __REVALIDATE_BY_ID(__intVal(id));
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3380
%}
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3381
!
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3382
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3383
superClassCheck:aClass
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3384
    "callBack from class registration code in VM: make certain, that aClass is
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3385
     loaded too ..."
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3386
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3387
    Verbose ifTrue:[
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3388
	'checkCall for:' infoPrint. aClass name infoPrint. ' -> ' infoPrint.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3389
    ].
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3390
    aClass isBehavior ifFalse:[
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3391
	Verbose ifTrue:[
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3392
	    'false' infoPrintNL. 
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3393
	].
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3394
	'LOADER: check failed - no behavior' infoPrintNL.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3395
	^ false
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3396
    ].
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3397
    Verbose ifTrue:[
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3398
	'true' infoPrintNL. 
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3399
    ].
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3400
    ('LOADER: check for ' , aClass name , ' being loaded') infoPrintNL.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3401
    aClass autoload.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3402
    (aClass isBehavior and:[aClass isLoaded]) ifTrue:[
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3403
	('LOADER: ok, loaded. continue registration of actual class') infoPrintNL.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3404
	aClass signature.       "/ req'd in VM for validation
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3405
	^ true
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3406
    ].
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3407
    ('LOADER: nope - not loaded. fail registration of actual class') infoPrintNL.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3408
    ^ false
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3409
!
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3410
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3411
unregisterModule:handle
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3412
    "unregister classes in the VM.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3413
     This invalidates all of the classes code objects ..."
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3414
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3415
    |id|
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3416
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3417
    Verbose ifTrue:[
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3418
	'unregister module; name=' infoPrint. handle pathName infoPrint.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3419
	' id=' infoPrint. handle moduleID infoPrintNL.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3420
    ].
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3421
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3422
    id := handle moduleID.
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3423
%{
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3424
    __UNREGISTER_BY_ID(__intVal(id));
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3425
%}
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3426
! !
989a7899b0e7 category changes
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  3427
291
c0d5159014be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 286
diff changeset
  3428
!ObjectFileLoader  class methodsFor:'documentation'!
148
ef0e604209ec version method at the end
Claus Gittinger <cg@exept.de>
parents: 147
diff changeset
  3429
ef0e604209ec version method at the end
Claus Gittinger <cg@exept.de>
parents: 147
diff changeset
  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
ef0e604209ec version method at the end
Claus Gittinger <cg@exept.de>
parents: 147
diff changeset
  3432
! !
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  3433
ObjectFileLoader initialize!