From 4ba01266de094e8050299fbabd01b8ced13d9b49 Mon Sep 17 00:00:00 2001 From: hag Date: Sun, 17 Nov 1996 18:49:56 +0000 Subject: [PATCH] Patches for BSDI dlsym stupidity --- configure | 61 ++++++++++++++++++++++++++++++++++++++++++---------- configure.in | 18 +++++++++++++++- dynload.c | 37 +++++++++++++++++-------------- sysdep.h.in | 4 ++++ 4 files changed, 92 insertions(+), 28 deletions(-) diff --git a/configure b/configure index 64bfb27..aa949a0 100755 --- a/configure +++ b/configure @@ -1879,13 +1879,52 @@ else fi echo "$ac_t""$s48_cv_uscore" 1>&6 + rm -f conftest.c a.out + if test $s48_cv_uscore = yes; then cat >> confdefs.h <<\EOF #define USCORE 1 EOF + + if test $ac_cv_func_dlopen = yes ; then + echo $ac_n "checking whether dlsym always adds an underscore for us""... $ac_c" 1>&6 + if eval "test \"`echo '$''{'s48_cv_dlsym_adds_uscore'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&6 +else + if test "$cross_compiling" = yes; then + { echo "configure: error: can not run test program while cross compiling" 1>&2; exit 1; } +else +cat > conftest.$ac_ext < +#include +fnord() { int i=42;} +main() { void *self, *ptr1, *ptr2; self=dlopen(NULL,RTLD_LAZY); + if(self) { ptr1=dlsym(self,"fnord"); ptr2=dlsym(self,"_fnord"); + if(ptr1 && !ptr2) exit(0); } exit(1); } + +EOF +{ (eval echo configure:1911: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } +if test -s conftest && (./conftest; exit) 2>/dev/null; then + s48_cv_dlsym_adds_uscore=yes + cat >> confdefs.h <<\EOF +#define DLSYM_ADDS_USCORE 1 +EOF + +else + s48_cv_dlsym_adds_uscore=no +fi +fi +rm -fr conftest* +fi + + + echo "$ac_t""$s48_cv_dlsym_adds_uscore" 1>&6 + fi fi - rm -f conftest.c a.out echo $ac_n "checking for n_name""... $ac_c" 1>&6 @@ -1894,7 +1933,7 @@ EOF else cat > conftest.$ac_ext < int main() { return 0; } @@ -1903,7 +1942,7 @@ struct nlist name_list; name_list.n_name = "foo"; ; return 0; } EOF -if { (eval echo configure:1907: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:1946: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* s48_cv_nlist=yes else @@ -1929,7 +1968,7 @@ EOF else cat > conftest.$ac_ext < int main() { return 0; } @@ -1937,7 +1976,7 @@ int t() { return stdin->_cnt; ; return 0; } EOF -if { (eval echo configure:1941: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:1980: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* s48_cv__cnt=yes else @@ -1964,7 +2003,7 @@ EOF else cat > conftest.$ac_ext < int main() { return 0; } @@ -1972,7 +2011,7 @@ int t() { return (int) tzname; ; return 0; } EOF -if { (eval echo configure:1976: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:2015: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* scsh_cv_tzname=yes else @@ -1998,7 +2037,7 @@ EOF else cat > conftest.$ac_ext < int main() { return 0; } @@ -2007,7 +2046,7 @@ struct tm time; return time.tm_gmtoff; ; return 0; } EOF -if { (eval echo configure:2011: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:2050: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* scsh_cv_gmtoff=yes else @@ -2033,7 +2072,7 @@ EOF else cat > conftest.$ac_ext < #include @@ -2042,7 +2081,7 @@ int t() { const extern char *sys_errlist[]; ; return 0; } EOF -if { (eval echo configure:2046: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:2085: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* scsh_cv_const_sys_errlist=yes else diff --git a/configure.in b/configure.in index dff9614..4ca91b4 100644 --- a/configure.in +++ b/configure.in @@ -85,10 +85,26 @@ AC_DEFUN(S48_USCORE, [ s48_cv_uscore=no fi]) AC_MSG_RESULT($s48_cv_uscore) + rm -f conftest.c a.out + if test $s48_cv_uscore = yes; then AC_DEFINE(USCORE) + + if test $ac_cv_func_dlopen = yes ; then + AC_MSG_CHECKING(whether dlsym always adds an underscore for us) + AC_CACHE_VAL(s48_cv_dlsym_adds_uscore,AC_TRY_RUN( [ +#include +#include +fnord() { int i=42;} +main() { void *self, *ptr1, *ptr2; self=dlopen(NULL,RTLD_LAZY); + if(self) { ptr1=dlsym(self,"fnord"); ptr2=dlsym(self,"_fnord"); + if(ptr1 && !ptr2) exit(0); } exit(1); } +], [s48_cv_dlsym_adds_uscore=yes + AC_DEFINE(DLSYM_ADDS_USCORE) ], s48_cv_dlsym_adds_uscore=no)) + + AC_MSG_RESULT($s48_cv_dlsym_adds_uscore) + fi fi - rm -f conftest.c a.out ]) dnl -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- diff --git a/dynload.c b/dynload.c index bc962c7..0dcb230 100644 --- a/dynload.c +++ b/dynload.c @@ -5,7 +5,7 @@ #include "sysdep.h" #include "scheme48.h" -/* +/* Hey folks, please help us out with conditions under which the ANCIENT_DYNLOAD and/or HAVE_DLOPEN code might work. About all we know is that ANCIENT_DYNLOAD worked once upon a time on the DEC @@ -43,10 +43,10 @@ static char *shared_object_name(char *name) { char *res=0; res = pathfind(getenv("LD_LIBRARY_PATH"), name, "r"); - if (res) + if (res) return res; res = pathfind(getenv("S48_EXTERN_PATH"), name, "r"); - if (res) + if (res) return res; return name; } /* end of shared_object_name */ @@ -64,7 +64,7 @@ static char *shared_object_name(char *name) /* SunoS5 & SVR4 define RTLD_NOW */ #ifdef RTLD_NOW #define S48_DLOPEN_MODE RTLD_NOW -#else +#else /* SunOS4 just says that mode should be 1 ie RTLD_LAZY */ #define S48_DLOPEN_MODE 1 #endif /*RTLD_NOW*/ @@ -112,7 +112,7 @@ dynamic_load(char*sharedobjname) dlopened_handle[rank] = newhandle; #ifdef DLDEBUG printf(" %s:%d %s sharedobjname='%s' pathname='%s' handle %#x rank=%d \n", - __FILE__, __LINE__, __FUNCTION__, + __FILE__, __LINE__, __FUNCTION__, sharedobjname, pathname, newhandle, rank); #endif /*DLDEBUG*/ return 0; @@ -125,6 +125,11 @@ lookup_dlsym(char *name, long *location) void *adr; static void *selfhandle; int rank; + +#if defined(USCORE) && defined(DLSYM_ADDS_USCORE) + name++; +#endif + /* perhaps i should scan the dlopened_handle from last to first, to find newest incarnation of symbol? in practice it should be faster to go from first (oldest) to last, @@ -135,20 +140,20 @@ lookup_dlsym(char *name, long *location) *location = (long) adr; #ifdef DLDEBUG printf(" %s:%d %s name='%s' in rank=%d at adr=%#x\n", - __FILE__, __LINE__, __FUNCTION__, + __FILE__, __LINE__, __FUNCTION__, name, rank, (long) adr); #endif /*DLDEBUG*/ return 1; }; /* find the name in the self process image - ie original scheme48 executable file */ - if (!selfhandle) + if (!selfhandle) selfhandle=dlopen((char*)0, S48_DLOPEN_MODE); if (adr=dlsym(selfhandle, name)) { *location = (long) adr; #ifdef DLDEBUG printf(" %s:%d %s name='%s' in self at adr=%#x\n", - __FILE__, __LINE__, __FUNCTION__, + __FILE__, __LINE__, __FUNCTION__, name, (long) adr); #endif /*DLDEBUG*/ return 1; @@ -156,7 +161,7 @@ lookup_dlsym(char *name, long *location) /* can't find name so return 0 */ #ifdef DLDEBUG printf(" %s:%d %s name='%s' not found\n", - __FILE__, __LINE__, __FUNCTION__, + __FILE__, __LINE__, __FUNCTION__, name); #endif /*DLDEBUG*/ return 0; @@ -194,7 +199,7 @@ struct exec { /* an exec-like structure for the MIPS */ #define TEXT_OFFSET(output_file_header) \ (long) N_TXTOFF(output_file_header) -#endif +#endif extern char *object_file; /* specified via a command line argument */ @@ -217,9 +222,9 @@ dynamic_load( char *user_args ) fprintf(stderr, "aborting dynamic load\n"); return(0); } - + new_reloc_file = (char *) malloc(L_tmpnam); - + tmpnam(new_reloc_file); if (-1 == really_dynamic_load(old_reloc_file, new_reloc_file, @@ -307,7 +312,7 @@ really_dynamic_load( char *reloc_info_file, char *output_file, char *user_args ) abort_load(command, NULL, NULL); return(-1); } - + /* move the storage pointer to the next page boundary */ end_of_memory = (long) sbrk(page_size - end_of_memory % page_size); @@ -318,7 +323,7 @@ really_dynamic_load( char *reloc_info_file, char *output_file, char *user_args ) } load_point = (long) sbrk(0); /* no malloc or printf after this */ - + if (load_point < 0 || 0 != load_point % page_size) { fprintf(stderr, "couldn't align sbrk on page boundary\n"); abort_load(command, NULL, NULL); @@ -399,7 +404,7 @@ really_dynamic_load( char *reloc_info_file, char *output_file, char *user_args ) abort_load(NULL, output_file_desc, output_file); return(-1); } - + /* go to beginning of text */ if (fseek(output_file_desc, TEXT_OFFSET(output_file_header), 0) < 0) { @@ -467,7 +472,7 @@ s48_dynamic_load( long nargs, scheme_value *argv ) if (nargs != 1) return(SCHFALSE); arg = argv[0]; - + if (!STRINGP(arg)) return(SCHFALSE); if (0 == dynamic_load(&STRING_REF(arg, 0))) diff --git a/sysdep.h.in b/sysdep.h.in index a5c440e..5b63682 100644 --- a/sysdep.h.in +++ b/sysdep.h.in @@ -120,6 +120,10 @@ struct sigaction { /* Define USCORE if your c externals are prepended with an underscore */ #undef USCORE +/* Define DLSYM_ADDS_USCORE if your system's dlsym() prepends an underscore + to symbol names. */ +#undef DLSYM_ADDS_USCORE + /* Define if you have POSIX tzname (Losing sunos4...). */ #undef HAVE_TZNAME