diff --git a/configure.ac b/configure.ac index 964ebfb..e6f7d7a 100644 --- a/configure.ac +++ b/configure.ac @@ -155,21 +155,54 @@ fi # Which mechanism should be used to dynamically load object files? ac_cv_my_can_load_lib=no +# OS X style AC_CHECK_HEADERS(mach-o/dyld.h, [AC_CHECK_FUNCS(NSLinkModule, [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_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) # Only test for dlopen() if the others didn't work if test "${ac_cv_my_can_load_lib}" = "no"; then - AC_CHECK_HEADERS(dlfcn.h, - [AC_CHECK_LIB(dl, dlopen, - [AC_DEFINE(HAVE_DL_DLOPEN, 1, [Define if you have the dlopen API]) - ELK_LIBS="${ELK_LIBS} -ldl" - ac_cv_my_can_load_lib=yes])]) + AC_CHECK_HEADERS(dlfcn.h sys/dl.h) + ac_cv_my_have_dlopen=no + AC_CHECK_FUNC(dlopen, + ac_cv_my_have_dlopen=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 if test "${ac_cv_my_can_load_lib}" = "yes"; then diff --git a/src/loadlib.c b/src/loadlib.c index d2ed371..e6e0c3c 100644 --- a/src/loadlib.c +++ b/src/loadlib.c @@ -32,14 +32,24 @@ #ifdef CAN_LOAD_LIB +#include #include #include #include -#if defined(HAVE_DL_DYLD) +#if defined(HAVE_MACH_O_DYLD_H) # include #elif defined(HAVE_DL_DLOPEN) -# include +# if defined(HAVE_DLFCN_H) +# include +# endif +# if defined(HAVE_SYS_DL_H) +# include +# endif +#elif defined(HAVE_DL_SHL_LOAD) +# if defined(HAVE_DL_H) +# include +# endif #endif #include "kernel.h" @@ -58,29 +68,29 @@ void Dlopen_File (char *fn) { if (Verb_Load) printf ("[dyld %s]\n", fn); - ret = NSCreateObjectFileImageFromFile(fn, &image); + ret = NSCreateObjectFileImageFromFile (fn, &image); if (ret != NSObjectFileImageSuccess) Primitive_Error ("could not map `~%~s'", Make_String (fn, strlen (fn))); /* Open the dynamic module */ - handle = NSLinkModule(image, fn, NSLINKMODULE_OPTION_RETURN_ON_ERROR); + handle = NSLinkModule (image, fn, NSLINKMODULE_OPTION_RETURN_ON_ERROR); if (!handle) { NSLinkEditErrors errors; - const char *file, *errstr; + const char *file, *err; int errnum; - NSLinkEditError(&errors, &errnum, &file, &errstr); + NSLinkEditError (&errors, &errnum, &file, &err); Primitive_Error ("could not dyld `~%~s': ~%~s", Make_String (file, strlen (file)), - Make_String (errstr, strlen (errstr))); + Make_String (err, strlen (err))); } /* Destroy our image, we won't need it */ - NSDestroyObjectFileImage(image); + NSDestroyObjectFileImage (image); - /* NSUnLinkModule(handle, FALSE); */ + /* NSUnLinkModule (handle, FALSE); */ #elif defined(HAVE_DL_DLOPEN) void *handle; @@ -88,12 +98,32 @@ void Dlopen_File (char *fn) { if (Verb_Load) 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) { - char *errstr = dlerror (); + char *err = dlerror (); 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 @@ -106,15 +136,19 @@ void Dlopen_File (char *fn) { The_Symbols = Open_File_And_Snarf_Symbols (fn); for (sp = The_Symbols->first; sp; sp = sp->next) { #if defined(HAVE_DL_DYLD) - NSSymbol sym = NSLookupSymbolInModule(handle, sp->name); + NSSymbol sym = NSLookupSymbolInModule (handle, sp->name); 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) /* dlsym() may fail for symbols not exported by object file; * this can be safely ignored. */ 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 }