ObjFLoader.st
changeset 100 6df9644528bd
parent 98 ccc7f9389a8e
child 102 77e4d1119ff2
--- a/ObjFLoader.st	Thu Jul 27 06:06:12 1995 +0200
+++ b/ObjFLoader.st	Thu Aug 03 03:25:58 1995 +0200
@@ -21,7 +21,7 @@
 COPYRIGHT (c) 1993 by Claus Gittinger
 	     All Rights Reserved
 
-$Header: /cvs/stx/stx/libcomp/Attic/ObjFLoader.st,v 1.28 1995-07-23 02:23:48 claus Exp $
+$Header: /cvs/stx/stx/libcomp/Attic/ObjFLoader.st,v 1.29 1995-08-03 01:25:45 claus Exp $
 '!
 
 !ObjectFileLoader class methodsFor:'documentation'!
@@ -42,7 +42,7 @@
 
 version
 "
-$Header: /cvs/stx/stx/libcomp/Attic/ObjFLoader.st,v 1.28 1995-07-23 02:23:48 claus Exp $
+$Header: /cvs/stx/stx/libcomp/Attic/ObjFLoader.st,v 1.29 1995-08-03 01:25:45 claus Exp $
 "
 !
 
@@ -180,6 +180,8 @@
 
 #ifdef AIX_DL
 # include <nlist.h>
+# include <sys/ldr.h>
+# include <errno.h>
 #endif
 %}
 ! !
@@ -793,25 +795,27 @@
 	 look for init-function(s); call them all
 	"
 	Verbose ifTrue:[
-	    Transcript showCr:'not init found; looking for candidates ...'
+	    Transcript showCr:'no init found; looking for candidates ...'
 	].
 	initNames := self namesMatching:'*_Init' segment:'[tT]' in:aFileName.
-	initNames do:[:aName |
-	    initAddr := self getFunction:aName from:handle.
-	    initAddr isNil ifTrue:[
-		(aName startsWith:'_') ifTrue:[
-		    initAddr := self getFunction:(aName copyFrom:2) from:handle.
+	initNames notNil ifTrue:[
+	    initNames do:[:aName |
+		initAddr := self getFunction:aName from:handle.
+		initAddr isNil ifTrue:[
+		    (aName startsWith:'_') ifTrue:[
+			initAddr := self getFunction:(aName copyFrom:2) from:handle.
+		    ].
 		].
+		initAddr isNil ifTrue:[
+		    Transcript showCr:('no symbol: ',aName,' in ',aFileName).
+		    ^ false
+		].
+		Verbose ifTrue:[
+		    Transcript showCr:'calling init at:' , (initAddr printStringRadix:16)
+		].
+		self performModuleInitAt:initAddr.
+		didInit := true.
 	    ].
-	    initAddr isNil ifTrue:[
-		Transcript showCr:('no symbol: ',aName,' in ',aFileName).
-		^ false
-	    ].
-	    Verbose ifTrue:[
-		Transcript showCr:'calling init at:' , (initAddr printStringRadix:16)
-	    ].
-	    self performModuleInitAt:initAddr.
-	    didInit := true.
 	].
     ].
 
@@ -1018,7 +1022,7 @@
 	].
     ].
 
-    handle := self primOpenDynamicObject:pathName into:(Array new:2).
+    handle := self primOpenDynamicObject:pathName into:(Array new:3).
     handle isNil ifTrue:[
 	LastError == #notImplemented ifTrue:[
 	    Verbose ifTrue:[
@@ -1119,13 +1123,27 @@
     extern char *__myName__;
     char *ldname;
     int *handle;
+    extern errno;
 
     if (__isString(pathName)) {
 	if (__isArray(aBuffer)
-	 && (_arraySize(aBuffer) == 2)) {;
-	    if ( (handle = load(__stringVal(pathName), 0, 0)) == 0 ) {
+	 && (_arraySize(aBuffer) >= 3)) {;
+	    if ( (handle = (int *) load(__stringVal(pathName), 0, 0)) == 0 ) {
 		if (ObjectFileLoader_Verbose == true) {
-		    printf ("load file %s failed\n", __stringVal(pathName));
+		    char *messages[64];
+		    int i;
+
+		    printf ("load file %s failed errno=%d\n", 
+				__stringVal(pathName), errno);
+		    switch (errno) {
+			case ENOEXEC:
+			    printf("   load messages:\n");
+			    loadquery(L_GETMESSAGES, messages, sizeof(messages));
+			    for (i=0; messages[i]; i++) {
+				printf("      %s\n", messages[i]);
+			    }
+			    break;
+		    }
 		}
 		RETURN ( nil );
 	    }
@@ -1136,6 +1154,8 @@
 				       _MKSMALLINT( (int)handle & 0xFFFF );
 	    _ArrayInstPtr(aBuffer)->a_element[1] = 
 				       _MKSMALLINT( ((int)handle >> 16) & 0xFFFF );
+	    _ArrayInstPtr(aBuffer)->a_element[2] = pathName;
+	    __STORE(aBuffer, pathName);
 	    RETURN (aBuffer);
 	}
     }
@@ -1148,7 +1168,7 @@
 
     if ((pathName == nil) || __isString(pathName)) {
 	if (__isArray(aBuffer)
-	 && (_arraySize(aBuffer) == 2)) {;
+	 && (_arraySize(aBuffer) >= 2)) {;
 	    handle = dlopen(pathName == nil ? 
 				(char *)0 : 
 				__stringVal(pathName), 
@@ -1178,7 +1198,7 @@
 
     if ((pathName == nil) || __isString(pathName)) {
 	if (__isArray(aBuffer)
-	 && (_arraySize(aBuffer) == 2)) {;
+	 && (_arraySize(aBuffer) >= 2)) {;
 	    if (pathName == nil)
 		handle = dlopen((char *)0, 1);
 	    else
@@ -1297,6 +1317,20 @@
     }
 #endif
 
+#ifdef SUN_DL
+    void *h;
+    int val;
+
+    if (__bothSmallInteger(low, hi)) {
+	val = (_intVal(hi) << 16) + _intVal(low);
+	h = (void *)(val);
+	if (ObjectFileLoader_Verbose == true)
+	    printf("close handle = %x\n", h);
+	dlclose(h);
+	RETURN (true);
+    }
+#endif
+
 #ifdef AIX_DL
     int *h;
     int val;
@@ -1313,20 +1347,6 @@
 	RETURN (true);
     }
 #endif
-
-#ifdef SUN_DL
-    void *h;
-    int val;
-
-    if (__bothSmallInteger(low, hi)) {
-	val = (_intVal(hi) << 16) + _intVal(low);
-	h = (void *)(val);
-	if (ObjectFileLoader_Verbose == true)
-	    printf("close handle = %x\n", h);
-	dlclose(h);
-	RETURN (true);
-    }
-#endif
 %}.
     ^ false
 !
@@ -1355,8 +1375,14 @@
 !
 
 namesMatching:aPattern segment:segmentPattern in:aFileName
+    "this is rubbish - it will vanish soon"
+
     |p l s addr segment name entry|
 
+    OperatingSystem getSystemType = 'aix' ifTrue:[
+	^ nil
+    ].
+
     l := OrderedCollection new.
     p := PipeStream readingFrom:(self nm:aFileName).
     p isNil ifTrue:[
@@ -1405,7 +1431,14 @@
      Handle must be the one returned previously from openDynamicObject.
      Return the address of the function, or nil on any error."
 
-    ^ self getSymbol:aString function:true from:handle
+    |fName|
+
+    OperatingSystem getSystemType = 'aix' ifTrue:[
+	fName := '.' , aString 
+    ] ifFalse:[
+	fName := aString
+    ].
+    ^ self getSymbol:fName function:true from:handle
 !
 
 getSymbol:aString function:isFunction from:handle
@@ -1492,7 +1525,8 @@
     int val;
     OBJ low, hi;
 
-    if (__isArray(handle)) {
+    if (__isArray(handle)
+     && (_arraySize(handle) >= 2)) {;
 	low = _ArrayInstPtr(handle)->a_element[0];
 	hi = _ArrayInstPtr(handle)->a_element[1];
     } else {
@@ -1526,7 +1560,8 @@
     int val;
     struct nlist nl[2];
 
-    if (__isArray(handle)) {
+    if (__isArray(handle)
+     && (_arraySize(handle) >= 3)) {
 	low = _ArrayInstPtr(handle)->a_element[0];
 	hi = _ArrayInstPtr(handle)->a_element[1];
 	fileName = _ArrayInstPtr(handle)->a_element[2];
@@ -1550,9 +1585,16 @@
 		if (ObjectFileLoader_Verbose == true)
 		    printf("nlist error\n");
 	    } else {
-		printf("value=%x section=%d type=%x sclass=%d\n", 
-			nl[0].n_value, nl[0].n_scnum, nl[0].n_type, nl[0].n_sclass);
-		printf("not yet implemented\n");
+		addr = (void *)((unsigned)nl[0].n_value + (unsigned)h);
+
+		if (ObjectFileLoader_Verbose == true) {
+		    printf("value=%x section=%d type=%x sclass=%d\n", 
+			    nl[0].n_value, nl[0].n_scnum, nl[0].n_type, nl[0].n_sclass);
+		    printf("addr = %x\n", addr);
+		}
+
+		lowAddr = _MKSMALLINT( (int)addr & 0xFFFF );
+		hiAddr = _MKSMALLINT( ((int)addr >> 16) & 0xFFFF );
 	    }
 	}
     }
@@ -1564,7 +1606,8 @@
     int val;
     OBJ low, hi;
 
-    if (__isArray(handle)) {
+    if (__isArray(handle)
+     && (_arraySize(handle) >= 2)) {;
 	low = _ArrayOnstPtr(handle)->a_element[0];
 	hi = _ArrayOnstPtr(handle)->a_element[0];
     } else {
@@ -1828,6 +1871,7 @@
     int arg = 0;
     int wasBlocked = 1;
     extern OBJ __BLOCKINTERRUPTS();
+    extern int __oldSpaceSize(), __oldSpaceUsed();
 
     if (__bothSmallInteger(low, hi)) {
 	if (_isSmallInteger(argument)) {
@@ -1845,6 +1889,9 @@
 
 	    force = (forceOld == true);
 	    if (force) {
+		if ((__oldSpaceSize() - __oldSpaceUsed()) < (64*1024)) {
+		    __moreOldSpace(__thisContext, 64*1024);
+		} 
 		prevSpace = __allocForceSpace(OLDSPACE);
 	    }