ObjectFileLoader.st
changeset 759 fd7e1e42a6a0
parent 750 00bfa36237fb
child 760 c8dd27876bf0
--- a/ObjectFileLoader.st	Thu Aug 13 13:51:05 1998 +0200
+++ b/ObjectFileLoader.st	Thu Aug 13 13:56:40 1998 +0200
@@ -14,7 +14,8 @@
 	instanceVariableNames:''
 	classVariableNames:'MySymbolTable Verbose LastError LinkErrorMessage NextHandleID
 		LoadedObjects PreviouslyLoadedObjects ActuallyLoadedObjects
-		SearchedLibraries LibPath LoadLibraryPath ErrorPrinting'
+		SearchedLibraries LibPath LoadLibraryPath ErrorPrinting
+		LinkCommand LinkArgs'
 	poolDictionaries:''
 	category:'System-Compiler'
 !
@@ -277,6 +278,16 @@
 initialize
     |systemType|
 
+    OperatingSystem isMSDOSlike ifTrue:[
+	"/ default setup for msc
+	LinkCommand isNil ifTrue:[
+	    LinkCommand := 'link'
+	].
+	LinkArgs isNil ifTrue:[
+	    LinkArgs := '/NOPACK /NOLOGO /DEBUG /MACHINE:I386 /DLL /OUT:%1.dll /DEF:%1.def'
+	].
+    ].
+
     MySymbolTable isNil ifTrue:[
 	Verbose := false.
 	NextHandleID := 1.
@@ -457,6 +468,48 @@
     "Modified: 29.4.1997 / 21:55:07 / cg"
 !
 
+linkArgs
+    ^ LinkArgs ? ''   "/ that default is ok for Unix
+
+    "Created: / 12.8.1998 / 21:41:16 / cg"
+    "Modified: / 12.8.1998 / 21:42:50 / cg"
+!
+
+linkArgs:anArgString
+    LinkArgs := anArgString
+
+    "
+     MSC:
+	LinkCommand := 'link32'.
+	LinkArgs := ' /NOPACK /NOLOGO /DEBUG /MACHINE:I386 /DLL /OUT:%1.dll /DEF:%1.def'
+
+     Borland:
+	LinkCommand := 'ilink32'.
+	LinkArgs := ' -ap -Tpd -s -Gn -Gi -v -w-dup'
+'
+'/NOPACK /NOLOGO /DEBUG /MACHINE:I386 /DLL /OUT:%1.dll /DEF:%1.def'
+
+     Unix:
+	LinkCommand := 'ld'
+	LinkArgs := '-shared'
+    "
+
+    "Created: / 12.8.1998 / 21:43:16 / cg"
+    "Modified: / 12.8.1998 / 22:15:00 / cg"
+!
+
+linkCommand
+    ^ LinkCommand ? 'ld'   "/ that default is ok for Unix
+
+    "Created: / 12.8.1998 / 21:41:16 / cg"
+!
+
+linkCommand:aCommand
+    LinkCommand := aCommand
+
+    "Created: / 12.8.1998 / 21:40:44 / cg"
+!
+
 loadableBinaryObjectFormat
     "return a symbol describing the expected binary format
      for object files to be loadable.
@@ -1278,18 +1331,18 @@
     "
     className := Smalltalk classNameForFile:functionName.
     className notNil ifTrue:[
-        initAddr := self getFunction:(className , suffix) from:handle.
-        initAddr notNil ifTrue:[^ initAddr].
-
-        initAddr := self getFunction:('_' , className , suffix) from:handle.
-        initAddr isNil ifTrue:[
-            "/
-            "/ special for broken ultrix nlist 
-            "/ (will not find symbol with single underscore)
-            "/ workaround: add another underscore and retry
-            "/
-            initAddr := self getFunction:('__' , className , suffix) from:handle.
-        ].
+	initAddr := self getFunction:(className , suffix) from:handle.
+	initAddr notNil ifTrue:[^ initAddr].
+
+	initAddr := self getFunction:('_' , className , suffix) from:handle.
+	initAddr isNil ifTrue:[
+	    "/
+	    "/ special for broken ultrix nlist 
+	    "/ (will not find symbol with single underscore)
+	    "/ workaround: add another underscore and retry
+	    "/
+	    initAddr := self getFunction:('__' , className , suffix) from:handle.
+	].
     ].
     ^ initAddr
 
@@ -1819,50 +1872,50 @@
     |p l s addr segment name entry|
 
     OperatingSystem platformName = 'vms' ifTrue:[
-        "/ no nm command
-        ^ nil
+	"/ no nm command
+	^ nil
     ].
     OperatingSystem getOSType = 'aix' ifTrue:[
-        "/ no useful nm info
-        ^ nil
+	"/ no useful nm info
+	^ nil
     ].
     OperatingSystem getOSType = 'win32' ifTrue:[
-        "/ no nm command
-        ^ nil
+	"/ no nm command
+	^ nil
     ].
 
     l := OrderedCollection new.
     p := PipeStream readingFrom:(self nm:aFileName).
     p isNil ifTrue:[
-        ('ObjectFileLoader [info]: cannot read names from ' , aFileName) infoPrintCR.
-        ^ nil
+	('ObjectFileLoader [info]: cannot read names from ' , aFileName) infoPrintCR.
+	^ nil
     ].
     [p atEnd] whileFalse:[
-        entry := p nextLine.
-        Verbose ifTrue:[
-            entry infoPrintCR.
-        ].
-        entry notNil ifTrue:[
-            s := ReadStream on:entry.
-            addr := s nextAlphaNumericWord.
-            segment := s nextAlphaNumericWord.
-            name := s upToEnd withoutSeparators.
-            (addr notNil and:[segment notNil and:[name notNil]]) ifTrue:[
-                (aPattern match:name) ifTrue:[
-                    (segmentPattern isNil or:[segmentPattern match:segment]) ifTrue:[
-                        l add:name.
-                        Verbose ifTrue:[
-                            ('found name: ' , name) infoPrintCR.
-                        ]
-                    ] ifFalse:[
-                        Verbose ifTrue:[
-                            name infoPrint. ' segment mismatch ' infoPrint.
-                            segmentPattern infoPrint. ' ' infoPrint. segment infoPrintCR.
-                        ]
-                    ]
-                ]
-            ]
-        ]
+	entry := p nextLine.
+	Verbose ifTrue:[
+	    entry infoPrintCR.
+	].
+	entry notNil ifTrue:[
+	    s := ReadStream on:entry.
+	    addr := s nextAlphaNumericWord.
+	    segment := s nextAlphaNumericWord.
+	    name := s upToEnd withoutSeparators.
+	    (addr notNil and:[segment notNil and:[name notNil]]) ifTrue:[
+		(aPattern match:name) ifTrue:[
+		    (segmentPattern isNil or:[segmentPattern match:segment]) ifTrue:[
+			l add:name.
+			Verbose ifTrue:[
+			    ('found name: ' , name) infoPrintCR.
+			]
+		    ] ifFalse:[
+			Verbose ifTrue:[
+			    name infoPrint. ' segment mismatch ' infoPrint.
+			    segmentPattern infoPrint. ' ' infoPrint. segment infoPrintCR.
+			]
+		    ]
+		]
+	    ]
+	]
     ].
     p close.
     ^ l
@@ -2242,58 +2295,64 @@
     osType := OperatingSystem getOSType.
 
     osType = 'win32' ifTrue:[
-        self activityNotification:'create def file'.
-
-        "/ create an exports file.
-        expFileName := '.\' , baseFileName , '.def'.
-
-        expFile := expFileName asFilename writeStream.
-        expFile notNil ifTrue:[
-            expFile nextPutLine:'LIBRARY ' , baseFileName.
-            expFile nextPutLine:'CODE EXECUTE READ SHARED'.
-            expFile nextPutLine:'DATA READ WRITE'.
-            expFile nextPutLine:'SECTIONS'.
-            expFile nextPutLine:' INITCODE READ EXECUTE SHARED'.
-            expFile nextPutLine:' INITDATA READ WRITE'.
-            expFile nextPutLine:' RODATA READ SHARED'.
-            expFile nextPutLine:'EXPORTS'.
-            expFile nextPutLine:' _' , baseFileName , '_Init'.
-            expFile nextPutLine:'IMPORTS'.
-            expFile close.
-        ].
-
-        self activityNotification:'generating shared object'.
-
-        "
-         link it to a dll with 'LINK'
-         Req's the librun-export file somewhere.
-        "
-        librunExpFileName := 'librun.exp'.
-        librunExpFileName asFilename exists ifFalse:[
-            librunExpFileName := 'lib\librun.exp'.
-            librunExpFileName asFilename exists ifFalse:[
-                librunExpFileName := 'include\librun.exp'.
-                librunExpFileName asFilename exists ifFalse:[
-                    librunExpFileName := '..\librun\librun.exp'.
-                    librunExpFileName asFilename exists ifFalse:[
-                        LastError := 'missing exports file: ''librun.exp'' - cannot link'.
-                        ^ nil
-                    ].
-                ].
-            ].
-        ].
-
-        ld := 'LINK ' , baseFileName , '.obj'
-               , ' /NOPACK /NOLOGO /DEBUG /MACHINE:I386 /DLL'
-               , ' /OUT:' , baseFileName , '.dll '
-               , ' /DEF:' , baseFileName , '.def'.
-
-        (OperatingSystem executeCommand:ld) ifFalse:[
-            "/ self halt.
-            ^nil
-        ].
-        oFileName := (Filename currentDirectory construct:(baseFileName , self sharedLibraryExtension)) name.
-        ^ oFileName
+	self activityNotification:'create def file'.
+
+	"/ create an exports file.
+	expFileName := '.\' , baseFileName , '.def'.
+
+	expFile := expFileName asFilename writeStream.
+	expFile notNil ifTrue:[
+	    expFile nextPutLine:'LIBRARY ' , baseFileName.
+	    expFile nextPutLine:'CODE EXECUTE READ SHARED'.
+	    expFile nextPutLine:'DATA READ WRITE'.
+	    expFile nextPutLine:'SECTIONS'.
+	    expFile nextPutLine:' INITCODE READ EXECUTE SHARED'.
+	    expFile nextPutLine:' INITDATA READ WRITE'.
+	    expFile nextPutLine:' RODATA READ SHARED'.
+	    expFile nextPutLine:'EXPORTS'.
+	    expFile nextPutLine:' _' , baseFileName , '_Init'.
+	    expFile nextPutLine:'IMPORTS'.
+	    expFile close.
+	].
+
+	self activityNotification:'generating shared object'.
+
+	"
+	 link it to a dll with 'LINK'
+	 Req's the librun-export file somewhere.
+	"
+	librunExpFileName := 'librun.exp'.
+	librunExpFileName asFilename exists ifFalse:[
+	    librunExpFileName := 'lib\librun.exp'.
+	    librunExpFileName asFilename exists ifFalse:[
+		librunExpFileName := 'include\librun.exp'.
+		librunExpFileName asFilename exists ifFalse:[
+		    librunExpFileName := '..\librun\librun.exp'.
+		    librunExpFileName asFilename exists ifFalse:[
+self warn:('missing exports file: ''librun.exp'' - cannot link').
+"/                        LastError := 'missing exports file: ''librun.exp'' - cannot link'.
+"/                        ^ nil
+		    ].
+		].
+	    ].
+	].
+
+	ld := LinkCommand , ' ' , baseFileName , '.obj'.
+	LinkArgs isNil ifTrue:[
+	    ld := ld
+	       , ' /NOPACK /NOLOGO /DEBUG /MACHINE:I386 /DLL'
+	       , ' /OUT:' , baseFileName , '.dll '
+	       , ' /DEF:' , baseFileName , '.def'.
+	] ifFalse:[
+	    ld := ld , ' ' , (LinkArgs bindWith:baseFileName)
+	].
+
+	(OperatingSystem executeCommand:ld) ifFalse:[
+	    "/ self halt.
+	    ^nil
+	].
+	oFileName := (Filename currentDirectory construct:(baseFileName , self sharedLibraryExtension)) name.
+	^ oFileName
     ].
 
     "/ UNIX systems
@@ -2302,108 +2361,108 @@
     needSharedObject := false.
 
     osType = 'irix' ifTrue:[
-        "
-         link it to a shared object with 'ld -shared'
-        "
-        needSharedObject := true.
-        ldArg := '-shared'.
+	"
+	 link it to a shared object with 'ld -shared'
+	"
+	needSharedObject := true.
+	ldArg := '-shared'.
     ].
 
     osType = 'sys5_4' ifTrue:[
-        "
-         link it to a shared object with 'ld -G'
-        "
-        needSharedObject := true.
-        ldArg := '-G'.
+	"
+	 link it to a shared object with 'ld -G'
+	"
+	needSharedObject := true.
+	ldArg := '-G'.
     ].
 
     osType = 'osf' ifTrue:[
-        "
-         link it to a shared object with 'ld -shared'
-        "
-        needSharedObject := true.
-        ldArg := '-shared'.
+	"
+	 link it to a shared object with 'ld -shared'
+	"
+	needSharedObject := true.
+	ldArg := '-shared'.
     ].
 
     osType = 'linux' ifTrue:[
-        ObjectFileLoader loadableBinaryObjectFormat == #elf ifTrue:[
-            "
-             link it to a shared object with 'ld -shared'
-            "
-            needSharedObject := true.
-            ldArg := '-shared'.
-        ]
+	ObjectFileLoader loadableBinaryObjectFormat == #elf ifTrue:[
+	    "
+	     link it to a shared object with 'ld -shared'
+	    "
+	    needSharedObject := true.
+	    ldArg := '-shared'.
+	]
     ].
 
     osType = 'solaris' ifTrue:[
-        "
-         link it to a shared object with 'ld -G -B dynamic'
-        "
-        needSharedObject := true.
-        ldArg := '-G -B dynamic'.
+	"
+	 link it to a shared object with 'ld -G -B dynamic'
+	"
+	needSharedObject := true.
+	ldArg := '-G -B dynamic'.
     ].
 
     osType = 'hpux' ifTrue:[
-        "
-         link it to a shared object with 'ld -b -B immediate'
-        "
-        needSharedObject := true.
-        ldArg := '-b -B immediate'.
+	"
+	 link it to a shared object with 'ld -b -B immediate'
+	"
+	needSharedObject := true.
+	ldArg := '-b -B immediate'.
     ].
 
     osType = 'aix' ifTrue:[
-        self activityNotification:'create export file'.
-
-        "/ create an exports file.
-        expFileName := './' , baseFileName , '.exp'.
-
-        expFile := expFileName asFilename writeStream.
-        expFile notNil ifTrue:[
-            expFile nextPutAll:'#!! ./' , baseFileName , (self sharedLibraryExtension).
-            expFile cr.
-            expFile nextPutAll:'_' , baseFileName , '_Init'.
-            expFile close.
-        ].
-
-        self activityNotification:'generating shared object'.
-
-        "
-         link it to a shared object with 'cc -bI:...librun.exp -bE -bMSRE'
-        "
-        needSharedObject := true.
-        ld := 'cc'.
-        librunExpFileName := Smalltalk getSystemFileName:'lib/librun_aix.exp'.
-        librunExpFileName isNil ifTrue:[
-            LastError := 'missing exports file: ''lib/librun_aix.exp'' - cannot link'.
-            ^ nil
-        ].
-
-        ldArg := '-bI:' , librunExpFileName ,
-                ' -bE:' , baseFileName , '.exp' ,
-                ' -bM:SRE -e _' , baseFileName , '_Init'.
+	self activityNotification:'create export file'.
+
+	"/ create an exports file.
+	expFileName := './' , baseFileName , '.exp'.
+
+	expFile := expFileName asFilename writeStream.
+	expFile notNil ifTrue:[
+	    expFile nextPutAll:'#!! ./' , baseFileName , (self sharedLibraryExtension).
+	    expFile cr.
+	    expFile nextPutAll:'_' , baseFileName , '_Init'.
+	    expFile close.
+	].
+
+	self activityNotification:'generating shared object'.
+
+	"
+	 link it to a shared object with 'cc -bI:...librun.exp -bE -bMSRE'
+	"
+	needSharedObject := true.
+	ld := 'cc'.
+	librunExpFileName := Smalltalk getSystemFileName:'lib/librun_aix.exp'.
+	librunExpFileName isNil ifTrue:[
+	    LastError := 'missing exports file: ''lib/librun_aix.exp'' - cannot link'.
+	    ^ nil
+	].
+
+	ldArg := '-bI:' , librunExpFileName ,
+		' -bE:' , baseFileName , '.exp' ,
+		' -bM:SRE -e _' , baseFileName , '_Init'.
     ].
 
     oFileName := './' , baseFileName , (self objectFileExtension).
     needSharedObject ifTrue:[
-        self activityNotification:'generating shared object'.
-
-        soFileName := './' , baseFileName , (self sharedLibraryExtension). 
-        OperatingSystem removeFile:soFileName.
-        Verbose ifTrue:[
-            'linking with:' infoPrintCR.
-            '   ' infoPrint.
-            (ld , ' ' , ldArg , ' -o ' , soFileName , ' ' , oFileName) infoPrintCR.
-        ].         
-        OperatingSystem executeCommand:
-            ld , ' ' , ldArg , ' ', 
-            (SearchedLibraries asStringCollection asStringWith: $ ), 
-            ' -o ' , soFileName , ' ' , oFileName.
-
-        OperatingSystem removeFile:oFileName.
-        expFileName notNil ifTrue:[
-            OperatingSystem removeFile:expFileName
-        ].
-        ^ soFileName. 
+	self activityNotification:'generating shared object'.
+
+	soFileName := './' , baseFileName , (self sharedLibraryExtension). 
+	OperatingSystem removeFile:soFileName.
+	Verbose ifTrue:[
+	    'linking with:' infoPrintCR.
+	    '   ' infoPrint.
+	    (ld , ' ' , ldArg , ' -o ' , soFileName , ' ' , oFileName) infoPrintCR.
+	].         
+	OperatingSystem executeCommand:
+	    ld , ' ' , ldArg , ' ', 
+	    (SearchedLibraries asStringCollection asStringWith: $ ), 
+	    ' -o ' , soFileName , ' ' , oFileName.
+
+	OperatingSystem removeFile:oFileName.
+	expFileName notNil ifTrue:[
+	    OperatingSystem removeFile:expFileName
+	].
+	^ soFileName. 
     ].
 
     "
@@ -2475,6 +2534,9 @@
 	].
     ].
 
+    Verbose ifTrue:[
+	('initializeLoader...') infoPrintCR
+    ].
     self initializeLoader.
 
     "/
@@ -2486,7 +2548,15 @@
     buffer at:3 put:pathName.
     buffer at:4 put:NextHandleID. NextHandleID := NextHandleID + 1.
 
+    Verbose ifTrue:[
+	('primLoadDynamicObject...') infoPrintCR
+    ].
+
     buffer := self primLoadDynamicObject:pathName into:buffer.
+    Verbose ifTrue:[
+	('done') infoPrintCR
+    ].
+
     buffer isNil ifTrue:[
 	LastError == #notImplemented ifTrue:[
 	    'ObjectFileLoader [warning]: no dynamic load facility present.' infoPrintCR.
@@ -2591,7 +2661,7 @@
      (instead, only pass around handles transparently).
      This function is not supported on all architectures."
 
-%{  /* CALLSUNLIMITEDSTACK */
+%{  /* CALLSUNLIMITEDSTACK(noWIN32) */
 
     if (! __isArray(anInfoBuffer)
      || (__arraySize(anInfoBuffer) < 3)) {
@@ -2626,7 +2696,16 @@
     int err;
 
     if (__isString(pathName)) {
-	if ((handle = LoadLibrary(__stringVal(pathName))) == NULL) {
+	if (@global(Verbose) == true)
+	    fprintf(stderr, "loading dll: %s...\n", __stringVal(pathName));
+	    fflush(stderr);
+	}
+	handle = LoadLibrary(__stringVal(pathName));
+	if (@global(Verbose) == true)
+	    fprintf(stderr, "handle: %x\n", handle);
+	    fflush(stderr);
+	}
+	if (handle == NULL) {
 	    err = GetLastError();
 	    if (@global(ErrorPrinting) == true) {
 		fprintf (stderr, "ObjectFileLoader: LoadLibrary %s failed; error: %x\n", 
@@ -3256,14 +3335,17 @@
 		prevSpace = __allocForceSpace(OLDSPACE);
 	    }
 
+#ifdef alpha
+	    if (@global(Verbose) == true)
+		printf("calling initfunc %lx ...\n", addr);
+#else
+	    if (@global(Verbose) == true)
+		printf("calling initfunc %x ...\n", addr);
+#endif
 	    if (special == true) {
 		if (__isSmallInteger(moduleID)) {
 		    __SET_MODULE_ID(__intVal(moduleID));
 		}
-#ifdef alpha
-		if (@global(Verbose) == true)
-		    printf("calling initfunc %lx ...\n", addr);
-#endif
 		retVal = (*addr)(arg, __pRT__);
 		__SET_MODULE_ID(0);
 		if (returnsObject != true) {
@@ -3578,6 +3660,6 @@
 !ObjectFileLoader class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libcomp/ObjectFileLoader.st,v 1.171 1998-08-03 14:51:48 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libcomp/ObjectFileLoader.st,v 1.172 1998-08-13 11:56:40 cg Exp $'
 ! !
 ObjectFileLoader initialize!