Merged patches from Matt Watson <mwatson@apple.com> to make loadable
modules work on Rhapsody. Still have a few kinks to iron out.
--- a/pr/src/linking/prlink.c
+++ b/pr/src/linking/prlink.c
@@ -28,19 +28,17 @@
#endif
#ifdef XP_UNIX
#ifdef USE_DLFCN
#include <dlfcn.h>
#elif defined(USE_HPSHL)
#include <dl.h>
#elif defined(USE_RLD)
-#include <fcntl.h>
-#include <streams/streams.h>
-#include <mach-o/rld.h>
+#include <mach-o/dyld.h>
#endif
/* Define this on systems which don't have it (AIX) */
#ifndef RTLD_LAZY
#define RTLD_LAZY RTLD_NOW
#endif
#endif /* XP_UNIX */
@@ -62,18 +60,17 @@ struct PRLibrary {
#ifdef XP_MAC
CFragConnectionID dlh;
#endif
#ifdef XP_UNIX
#if defined(USE_HPSHL)
shl_t dlh;
#elif defined(USE_RLD)
- NXStream* dlh;
- int rld_fd;
+ NSModule dlh;
#else
void* dlh;
#endif
#endif
};
static PRLibrary *pr_loadmap;
static PRLibrary *pr_exe_loadmap;
@@ -637,20 +634,22 @@ PR_LoadLibrary(const char *name)
void *h = dlopen(name, RTLD_LAZY);
#elif defined(USE_HPSHL)
/*
* Shared libraries built using aCC cannot be dynamically loaded
* with BIND_DEFERRED, so we have to use the BIND_IMMEDIATE flag.
*/
shl_t h = shl_load(name, BIND_IMMEDIATE | DYNAMIC_PATH, 0L);
#elif defined(USE_RLD)
- int fd = open(name, O_RDONLY);
- NXStream *h = NXOpenFile(fd, NX_READONLY);
-
- lm->rld_fd = fd;
+ NSObjectFileImage ofi;
+ NSModule h = NULL;
+ if (NSCreateObjectFileImageFromFile(name, &ofi)
+ == NSObjectFileImageSuccess) {
+ h = NSLinkModule(ofi, name, TRUE);
+ }
#else
#error Configuration error
#endif
if (!h) {
PR_DELETE(lm);
goto unlock;
}
lm->name = strdup(name);
@@ -708,19 +707,17 @@ PR_UnloadLibrary(PRLibrary *lib)
}
#ifdef XP_UNIX
#ifdef HAVE_DLL
#ifdef USE_DLFCN
result = dlclose(lib->dlh);
#elif defined(USE_HPSHL)
result = shl_unload(lib->dlh);
#elif defined(USE_RLD)
- result = rld_unload(lib->dlh);
- NXClose(lib->dlh);
- close(lib->rld_fd);
+ result = NSUnLinkModule(lib->dlh, FALSE);
#else
#error Configuration error
#endif
#endif /* HAVE_DLL */
#endif /* XP_UNIX */
#ifdef XP_PC
if (lib->dlh) {
FreeLibrary((HINSTANCE)(lib->dlh));
@@ -822,18 +819,17 @@ pr_FindSymbolInLib(PRLibrary *lm, const
#ifdef XP_UNIX
#ifdef HAVE_DLL
#ifdef USE_DLFCN
f = dlsym(lm->dlh, name);
#elif defined(USE_HPSHL)
if (shl_findsym(&lm->dlh, name, TYPE_PROCEDURE, &f) == -1)
f = NULL;
#elif defined(USE_RLD)
- if (rld_lookup(lm->dlh, name, (unsigned long*)&f) == -1)
- f = NULL;
+ f = NSAddressOfSymbol(NSLookupAndBindSymbol(name));
#endif
#endif /* HAVE_DLL */
#endif /* XP_UNIX */
if (f == NULL) {
PR_SetError(PR_FIND_SYMBOL_ERROR, _MD_ERRNO());
DLLErrorInternal(_MD_ERRNO());
}
return f;
@@ -849,17 +845,17 @@ PR_FindSymbol(PRLibrary *lib, const char
#if defined(SUNOS4) || defined(WIN16)
char *name;
#else
const char *name;
#endif
/*
** Mangle the raw symbol name in any way that is platform specific.
*/
-#if defined(SUNOS4)
+#if defined(SUNOS4) || defined(RHAPSODY)
/* Need a leading _ */
name = PR_smprintf("_%s", raw_name);
#elif defined(AIX)
/*
** AIX with the normal linker put's a "." in front of the symbol
** name. When use "svcc" and "svld" then the "." disappears. Go
** figure.
*/
@@ -894,17 +890,17 @@ PR_FindSymbolAndLibrary(const char *raw_
#else
const char *name;
#endif
PRLibrary* lm;
/*
** Mangle the raw symbol name in any way that is platform specific.
*/
-#if defined(SUNOS4)
+#if defined(SUNOS4) || defined(RHAPSODY)
/* Need a leading _ */
name = PR_smprintf("_%s", raw_name);
#elif defined(AIX)
/*
** AIX with the normal linker put's a "." in front of the symbol
** name. When use "svcc" and "svld" then the "." disappears. Go
** figure.
*/