* Enhanced the dlopen() checks, especially for platforms that do not

need -ldl.
  * Ported the plugin loading code to the HP-UX shl_load() system.


git-svn-id: svn://svn.zoy.org/elk/trunk@129 55e467fa-43c5-0310-a8a2-de718669efc6
This commit is contained in:
sam 2003-09-09 13:30:23 +00:00
parent 9bcdb37dee
commit dcf74a9c38
2 changed files with 86 additions and 19 deletions

View File

@ -155,21 +155,54 @@ fi
# Which mechanism should be used to dynamically load object files? # Which mechanism should be used to dynamically load object files?
ac_cv_my_can_load_lib=no ac_cv_my_can_load_lib=no
# OS X style
AC_CHECK_HEADERS(mach-o/dyld.h, AC_CHECK_HEADERS(mach-o/dyld.h,
[AC_CHECK_FUNCS(NSLinkModule, [AC_CHECK_FUNCS(NSLinkModule,
[AC_DEFINE(HAVE_DL_DYLD, 1, [Define if you have the Darwin dyld API]) [AC_DEFINE(HAVE_DL_DYLD, 1, [Define if you have the Darwin dyld API])
AC_DEFINE(SYMS_BEGIN_WITH, ['_'], [Define if symbols start with '_']) AC_DEFINE(SYMS_BEGIN_WITH, ['_'], [Define if symbols start with '_'])
ac_cv_my_can_load_lib=yes])]) ac_cv_my_can_load_lib=yes])])
# HP-UX style
if test "${ac_cv_my_can_load_lib}" = "no"; then
AC_CHECK_HEADERS(dl.h)
ac_cv_my_have_shl_load=no
AC_CHECK_FUNC(shl_load,
[ac_cv_my_have_shl_load=yes,
AC_CHECK_LIB(dld, shl_load,
[ac_cv_my_have_shl_load=yes
ELK_LIBS="${ELK_LIBS} -ldld"])])
if test "${ac_cv_my_have_shl_load}" = "yes"; then
AC_DEFINE(HAVE_DL_SHL_LOAD, 1, [Define if you have the shl_load API])
ac_cv_my_can_load_lib=yes
fi
fi
# Whatever style
if test "${ac_cv_my_can_load_lib}" = "no"; then
AC_CHECK_LIB(dld, dld_link,
[ELK_LIBS="${ELK_LIBS} -ldld"
AC_DEFINE(HAVE_DL_DLD_LINK, 1, [Define if you have the GNU dld library])
ac_cv_my_can_load_lib=yes])
fi
AC_CHECK_HEADERS(a.out.h) AC_CHECK_HEADERS(a.out.h)
# Only test for dlopen() if the others didn't work # Only test for dlopen() if the others didn't work
if test "${ac_cv_my_can_load_lib}" = "no"; then if test "${ac_cv_my_can_load_lib}" = "no"; then
AC_CHECK_HEADERS(dlfcn.h, AC_CHECK_HEADERS(dlfcn.h sys/dl.h)
[AC_CHECK_LIB(dl, dlopen, ac_cv_my_have_dlopen=no
[AC_DEFINE(HAVE_DL_DLOPEN, 1, [Define if you have the dlopen API]) AC_CHECK_FUNC(dlopen,
ELK_LIBS="${ELK_LIBS} -ldl" ac_cv_my_have_dlopen=yes,
ac_cv_my_can_load_lib=yes])]) AC_CHECK_LIB(dl, dlopen,
ac_cv_my_have_dlopen=yes
ELK_LIBS="${ELK_LIBS} -ldl",
AC_CHECK_LIB(svld, dlopen,
ac_cv_my_have_dlopen=yes
ELK_LIBS="${ELK_LIBS} -lsvld")))
if test "${ac_cv_my_have_dlopen}" = "yes"; then
AC_DEFINE(HAVE_DL_DLOPEN, 1, [Define if you have the dlopen API])
ac_cv_my_can_load_lib=yes
fi
fi fi
if test "${ac_cv_my_can_load_lib}" = "yes"; then if test "${ac_cv_my_can_load_lib}" = "yes"; then

View File

@ -32,14 +32,24 @@
#ifdef CAN_LOAD_LIB #ifdef CAN_LOAD_LIB
#include <errno.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#if defined(HAVE_DL_DYLD) #if defined(HAVE_MACH_O_DYLD_H)
# include <mach-o/dyld.h> # include <mach-o/dyld.h>
#elif defined(HAVE_DL_DLOPEN) #elif defined(HAVE_DL_DLOPEN)
# if defined(HAVE_DLFCN_H)
# include <dlfcn.h> # include <dlfcn.h>
# endif
# if defined(HAVE_SYS_DL_H)
# include <sys/dl.h>
# endif
#elif defined(HAVE_DL_SHL_LOAD)
# if defined(HAVE_DL_H)
# include <dl.h>
# endif
#endif #endif
#include "kernel.h" #include "kernel.h"
@ -58,29 +68,29 @@ void Dlopen_File (char *fn) {
if (Verb_Load) if (Verb_Load)
printf ("[dyld %s]\n", fn); printf ("[dyld %s]\n", fn);
ret = NSCreateObjectFileImageFromFile(fn, &image); ret = NSCreateObjectFileImageFromFile (fn, &image);
if (ret != NSObjectFileImageSuccess) if (ret != NSObjectFileImageSuccess)
Primitive_Error ("could not map `~%~s'", Primitive_Error ("could not map `~%~s'",
Make_String (fn, strlen (fn))); Make_String (fn, strlen (fn)));
/* Open the dynamic module */ /* Open the dynamic module */
handle = NSLinkModule(image, fn, NSLINKMODULE_OPTION_RETURN_ON_ERROR); handle = NSLinkModule (image, fn, NSLINKMODULE_OPTION_RETURN_ON_ERROR);
if (!handle) { if (!handle) {
NSLinkEditErrors errors; NSLinkEditErrors errors;
const char *file, *errstr; const char *file, *err;
int errnum; int errnum;
NSLinkEditError(&errors, &errnum, &file, &errstr); NSLinkEditError (&errors, &errnum, &file, &err);
Primitive_Error ("could not dyld `~%~s': ~%~s", Primitive_Error ("could not dyld `~%~s': ~%~s",
Make_String (file, strlen (file)), Make_String (file, strlen (file)),
Make_String (errstr, strlen (errstr))); Make_String (err, strlen (err)));
} }
/* Destroy our image, we won't need it */ /* Destroy our image, we won't need it */
NSDestroyObjectFileImage(image); NSDestroyObjectFileImage (image);
/* NSUnLinkModule(handle, FALSE); */ /* NSUnLinkModule (handle, FALSE); */
#elif defined(HAVE_DL_DLOPEN) #elif defined(HAVE_DL_DLOPEN)
void *handle; void *handle;
@ -88,12 +98,32 @@ void Dlopen_File (char *fn) {
if (Verb_Load) if (Verb_Load)
printf ("[dlopen %s]\n", fn); printf ("[dlopen %s]\n", fn);
handle = dlopen (fn, RTLD_NOW|RTLD_GLOBAL); #if defined(RTLD_GLOBAL)
handle = dlopen (fn, RTLD_NOW | RTLD_GLOBAL);
#elif defined(DL_GLOBAL)
handle = dlopen (fn, DL_NOW | DL_GLOBAL);
#else
handle = dlopen (fn, 0);
#endif
if (handle == NULL) { if (handle == NULL) {
char *errstr = dlerror (); char *err = dlerror ();
Primitive_Error ("dlopen failed: ~%~s", Primitive_Error ("dlopen failed: ~%~s",
Make_String (errstr, strlen (errstr))); Make_String (err, strlen (err)));
}
#elif defined(HAVE_DL_SHL_LOAD)
shl_t handle;
if (Verb_Load)
printf ("[shl_load %s]\n", fn);
handle = shl_load (fn, BIND_IMMEDIATE | BIND_NONFATAL, NULL);
if (handle == NULL) {
char *err = strerror (errno);
Primitive_Error ("shl_load failed: ~%~s",
Make_String (err, strlen (err)));
} }
#else #else
@ -106,15 +136,19 @@ void Dlopen_File (char *fn) {
The_Symbols = Open_File_And_Snarf_Symbols (fn); The_Symbols = Open_File_And_Snarf_Symbols (fn);
for (sp = The_Symbols->first; sp; sp = sp->next) { for (sp = The_Symbols->first; sp; sp = sp->next) {
#if defined(HAVE_DL_DYLD) #if defined(HAVE_DL_DYLD)
NSSymbol sym = NSLookupSymbolInModule(handle, sp->name); NSSymbol sym = NSLookupSymbolInModule (handle, sp->name);
if (sym) if (sym)
sp->value = (unsigned long int)(intptr_t)NSAddressOfSymbol(sym); sp->value = (unsigned long int)(intptr_t)NSAddressOfSymbol (sym);
#elif defined(HAVE_DL_DLOPEN) #elif defined(HAVE_DL_DLOPEN)
/* dlsym() may fail for symbols not exported by object file; /* dlsym() may fail for symbols not exported by object file;
* this can be safely ignored. */ * this can be safely ignored. */
sp->value = (unsigned long int)(intptr_t)dlsym (handle, sp->name); sp->value = (unsigned long int)(intptr_t)dlsym (handle, sp->name);
#elif defined(HAVE_DL_SHL_LOAD)
void *sym;
shl_findsym (&handle, "share", TYPE_UNDEFINED, &sym);
sp->value = (unsigned long int)(intptr_t)sym;
#endif #endif
} }