--- a/ObjFLoader.st Mon Jan 17 10:14:07 1994 +0100
+++ b/ObjFLoader.st Fri Feb 25 13:52:15 1994 +0100
@@ -28,16 +28,41 @@
(goal is to allow loading of binary classes)
-$Header: /cvs/stx/stx/libcomp/Attic/ObjFLoader.st,v 1.4 1994-01-08 17:05:10 claus Exp $
+$Header: /cvs/stx/stx/libcomp/Attic/ObjFLoader.st,v 1.5 1994-02-25 12:51:52 claus Exp $
'!
%{
+/*
+ * by default, use whatever the system provides
+ */
+#ifdef sunos
+# define SUN_DL
+#endif
+
#ifdef NeXT
+# define NEXT_DL
+#endif
+
+#ifdef SYSV4
+# define SYSV4_DL
+#endif
+
+/*
+ * but GNU_DL overwrites this
+ */
+#ifdef GNU_DL
+# undef SYSV4_DL
+# undef NEXT_DL
+# undef SUN_DL
+#endif
+
+#ifdef NEXT_DL
# ifndef _RLD_H_
# define _RLD_H_
# include <rld.h>
# endif
-#endif /* NeXT */
+#endif /* NEXT_DL */
+
static OBJ loadAddrLow, loadAddrHi;
%}
@@ -272,7 +297,7 @@
|baseName p t l handle address stubName|
stubName := 'stub000' , (StubNr printStringRadix:16).
- stubName := stubName copyFrom:(stubName size - 7) to:(stubName size).
+ stubName := stubName copyFrom:(stubName size - 7).
baseName := self createStubSource:stubName calling:functionName args:argTypes returning:returnType.
baseName isNil ifTrue:[^ nil].
@@ -454,11 +479,11 @@
^ true
].
(argType == #Float) ifTrue:[
- aStream nextPutAll:'_isFloat(' , argName , ')'.
+ aStream nextPutAll:'__isFloat(' , argName , ')'.
^ true
].
(argType == #String) ifTrue:[
- aStream nextPutAll:'_isString(' , argName , ')'.
+ aStream nextPutAll:'__isString(' , argName , ')'.
^ true
].
(argType == #Boolean) ifTrue:[
@@ -903,7 +928,7 @@
].
className := OperatingSystem baseNameOf:aFileName.
(className endsWith:'.o') ifTrue:[
- className := className copyFrom:1 to:(className size - 2)
+ className := className copyTo:(className size - 2)
].
OperatingSystem getOSType = 'sys5.4' ifTrue:[
symName := '_' , className , '_Init'
@@ -934,87 +959,104 @@
Return a non-nil handle if ok, nil otherwise.
This function is not supported on all architectures."
- |low hi|
+ |handle|
- "had to separate due to UNLIMITEDSTACK need"
- self primOpenDynamicObject:pathName.
-%{
- low = loadAddrLow;
- hi = loadAddrHi;
-%}
-.
- low notNil ifTrue:[
- ^ (hi * 16r10000) + low
- ].
-
- ^ nil
+ handle := self primOpenDynamicObject:pathName into:(Array new:2).
+ ^ handle
"sys5.4:
|handle|
handle := ObjectFileLoader openDynamicObject:'../stc/mod1.so'.
- ObjectFileLoader getSymbol:'module1' from:handle"
+ ObjectFileLoader getSymbol:'module1' from:handle
+ "
"next:
|handle|
handle := ObjectFileLoader openDynamicObject:'../goodies/Path/AbstrPath.o'.
- ObjectFileLoader getSymbol:'__AbstractPath_Init' from:handle"
+ ObjectFileLoader getSymbol:'__AbstractPath_Init' from:handle
+ "
+ "GLD:
+ |handle|
+ handle := ObjectFileLoader openDynamicObject:'../clients/Tetris/Tetris.o'.
+ ObjectFileLoader getSymbol:'__TetrisBlock_Init' from:handle
+ "
!
-primOpenDynamicObject:pathName
+primOpenDynamicObject:pathName into:aBuffer
"open an object-file (map into my address space).
- This function is not supported on all architectures."
+ This function is not supported on all architectures.
+ Dont depend on the returned value or class of it, it depends
+ on the underlying dynamic load package."
%{ /* UNLIMITEDSTACK */
-#ifdef SYSV4
+#ifdef GNU_DL
+# include "dld.h"
+ if (__isString(pathName)) {
+ if (dld_link(_stringVal(pathName))) {
+ dld_perror("cant link");
+ RETURN ( nil );
+ }
+ RETURN ( pathName );
+ }
+ RETURN ( nil );
+#endif
+
+#ifdef SYSV4_DL
+# include <dlfcn.h>
+ void *handle;
+
+ if ((pathName == nil) || __isString(pathName)) {
+ if (pathName == nil)
+ handle = dlopen((char *)0, RTLD_NOW);
+ else
+ handle = dlopen(_stringVal(pathName), RTLD_NOW);
+
+ if (! handle) {
+ printf("dlopen %s error: <%s>\n", _stringVal(pathName), dlerror());
+ RETURN (nil);
+ }
+
+ printf("open %s handle = %x\n", _stringVal(pathName), handle);
+ _AT_PUT_(aBuffer COMMA_SND, _MKSMALLINT(1),
+ _MKSMALLINT( (int)handle & 0xFFFF ));
+ _AT_PUT_(aBuffer COMMA_SND, _MKSMALLINT(2),
+ _MKSMALLINT( ((int)handle >> 16) & 0xFFFF ));
+ }
+#endif
+
+#ifdef SUN_DL
# include <dlfcn.h>
void *handle;
loadAddrLow = nil;
loadAddrHi = nil;
- if ((pathName == nil) || _isString(pathName)) {
- if (pathName == nil)
- handle = dlopen((char *)0, RTLD_NOW);
- else
- handle = dlopen(_stringVal(pathName), RTLD_NOW);
- if (handle) {
- printf("open %s handle = %x\n", _stringVal(pathName), handle);
- loadAddrLow = _MKSMALLINT( (int)handle & 0xFFFF );
- loadAddrHi = _MKSMALLINT( ((int)handle >> 16) & 0xFFFF );
- } else {
- printf("dlopen %s error: <%s>\n", _stringVal(pathName), dlerror());
- }
- RETURN ( self );
- }
-#endif
-#ifdef sunos
-# include <dlfcn.h>
- void *handle;
-
- loadAddrLow = nil;
- loadAddrHi = nil;
- if ((pathName == nil) || _isString(pathName)) {
+ if ((pathName == nil) || __isString(pathName)) {
if (pathName == nil)
handle = dlopen((char *)0, 1);
else
handle = dlopen(_stringVal(pathName), 1);
- if (handle) {
- printf("open %s handle = %x\n", _stringVal(pathName), handle);
- loadAddrLow = _MKSMALLINT( (int)handle & 0xFFFF );
- loadAddrHi = _MKSMALLINT( ((int)handle >> 16) & 0xFFFF );
- } else {
+
+ if (! handle) {
printf("dlopen %s error: <%s>\n", _stringVal(pathName), dlerror());
+ RETURN (nil);
}
- RETURN ( self );
+
+ printf("open %s handle = %x\n", _stringVal(pathName), handle);
+ _AT_PUT_(aBuffer COMMA_SND, _MKSMALLINT(1),
+ _MKSMALLINT( (int)handle & 0xFFFF ));
+ _AT_PUT_(aBuffer COMMA_SND, _MKSMALLINT(2),
+ _MKSMALLINT( ((int)handle >> 16) & 0xFFFF ));
}
#endif
-#ifdef NeXT
+
+#ifdef NEXT_DL
long result;
char *files[2];
NXStream *errOut;
loadAddrLow = nil;
loadAddrHi = nil;
- if (_isString(pathName)) {
+ if (__isString(pathName)) {
files[0] = (char *) _stringVal(pathName);
files[1] = (char *) 0;
errOut = NXOpenFile(2, 2);
@@ -1023,28 +1065,40 @@
files,
(char *)0);
NXClose(errOut);
- if (result) {
- printf("rld_load %s ok\n", _stringVal(pathName));
- /* a dummy handle */
- loadAddrLow = _MKSMALLINT(1);
- loadAddrHi = _MKSMALLINT(0);
+ if (! result) {
+ printf("rld_load %s failed\n", _stringVal(pathName));
+ RETURN (nil);
}
- RETURN ( self );
+
+ printf("rld_load %s ok\n", _stringVal(pathName));
+ _AT_PUT_(aBuffer COMMA_SND, _MKSMALLINT(1), _MKSMALLINT(1));
+ _AT_PUT_(aBuffer COMMA_SND, _MKSMALLINT(2), _MKSMALLINT(0));
}
- RETURN ( nil );
#endif
-%}
+%}.
+ ^ aBuffer
!
closeDynamicObject:handle
"close an object-file (unmap from my address space)."
|low hi|
+%{
+#ifdef GNU_DL
+# include "dld.h"
+ if (__isString(handle)) {
+ if (dld_unlink_by_file(_stringVal(handle), 1)) {
+ dld_perror("cant unlink");
+ }
+ RETURN ( self );
+ }
+#endif
+%}.
- hi := handle // 16r10000.
- low := handle \\ 16r10000.
+ hi := handle at:1.
+ low := handle at:2.
%{
-#ifdef SYSV4
+#ifdef SYSV4_DL
# include <dlfcn.h>
void *h;
int val;
@@ -1056,7 +1110,8 @@
dlclose(h);
}
#endif
-#ifdef sunos
+
+#ifdef SUN_DL
# include <dlfcn.h>
void *h;
int val;
@@ -1078,10 +1133,28 @@
|low hi lowAddr hiAddr|
- hi := handle // 16r10000.
- low := handle \\ 16r10000.
%{
-#ifdef SYSV4
+#ifdef GNU_DL
+# include "dld.h"
+ void (*func)();
+
+ if (__isString(aString)) {
+ func = (void (*) ()) dld_get_func(_stringVal(aString));
+ if (func) {
+ printf("addr = %x\n", (INT)func);
+ lowAddr = _MKSMALLINT( (INT)func & 0xFFFF );
+ hiAddr = _MKSMALLINT( ((INT)func >> 16) & 0xFFFF );
+ } else {
+ dld_perror("get_func");
+ }
+ }
+#endif
+%}.
+
+ hi := handle at:1.
+ low := handle at:2.
+%{
+#ifdef SYSV4_DL
# include <dlfcn.h>
void *h;
void *addr;
@@ -1090,7 +1163,7 @@
if (_isSmallInteger(low) && _isSmallInteger(hi)) {
val = (_intVal(hi) << 16) + _intVal(low);
h = (void *)(val);
- if (_isString(aString)) {
+ if (__isString(aString)) {
printf("get sym <%s> handle = %x\n", _stringVal(aString), h);
addr = dlsym(h, _stringVal(aString));
if (addr) {
@@ -1103,7 +1176,8 @@
}
}
#endif
-#ifdef sunos
+
+#ifdef SUN_DL
# include <dlfcn.h>
void *h;
void *addr;
@@ -1112,7 +1186,7 @@
if (_isSmallInteger(low) && _isSmallInteger(hi)) {
val = (_intVal(hi) << 16) + _intVal(low);
h = (void *)(val);
- if (_isString(aString)) {
+ if (__isString(aString)) {
printf("get sym <%s> handle = %x\n", _stringVal(aString), h);
addr = dlsym(h, _stringVal(aString));
if (addr) {
@@ -1125,12 +1199,13 @@
}
}
#endif
-#ifdef NeXT
+
+#ifdef NEXT_DL
unsigned long addr;
long result;
NXStream *errOut;
- if (_isString(aString)) {
+ if (__isString(aString)) {
printf("get sym <%s>\n", _stringVal(aString));
errOut = NXOpenFile(2, 2);
result = rld_lookup(errOut,
@@ -1154,11 +1229,11 @@
releaseSymbolTable
"this is needed on NeXT to forget loaded names. If this wasnt done,
- the same class could nat be loaded in again due to multiple defines.
+ the same class could not be loaded in again due to multiple defines.
On other architectures, this is not needed and therefore a noop."
%{
-#ifdef NeXT
+#ifdef NEXT_DL
NXStream *errOut;
errOut = NXOpenFile(2, 2);