From: Thomas Tanner Date: Mon, 15 Feb 1999 16:46:55 +0000 (+0000) Subject: * cdemo/Makefile.am: renamed *foo1 to *foo, removed $(MATH_LIB) X-Git-Tag: release-1-2f~125 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c361d1cfebef12387b1988708f27c15a1106c741;p=thirdparty%2Flibtool.git * cdemo/Makefile.am: renamed *foo1 to *foo, removed $(MATH_LIB) * cdemo/foo1.c: renamed to foo.c * libltdl/ltdl.c: eliminated lt_dltype, in presym_open(): search for @PROGRAM@ if filename == 0, in lt_dlopen(): fixed bug for filename == 0 * libltdl/ltdl.h: use __P macro for lt_dlmalloc/free * libtool.m4: new macro AC_LIBTOOL_DLOPEN: checks for dlopen and dlopen(NULL) support * ltconfig.in: added new variables dlopen and dlopen_self, --enable-dlopen[-self] flags for AC_LIBTOOL_DLOPEN * ltmain.in: use dlopen[_self], dlpreopen files if there's no dlopen support, build lt_preloaded_symbols only if -dl[pre]open was used, include program symbols if -export-dynamic was specified and there's no dlopen(NULL) support * mdemo/configure.in: use AC_LIBTOOL_DLOPEN * mdemo/main.c: demonstrate lt_dlopen(0) --- diff --git a/ChangeLog b/ChangeLog index 8150bd57e..c3e24097d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,22 @@ +1999-02-15 Thomas Tanner + + * cdemo/Makefile.am: renamed *foo1 to *foo, removed $(MATH_LIB) + * cdemo/foo1.c: renamed to foo.c + * libltdl/ltdl.c: eliminated lt_dltype, in presym_open(): + search for @PROGRAM@ if filename == 0, in lt_dlopen(): + fixed bug for filename == 0 + * libltdl/ltdl.h: use __P macro for lt_dlmalloc/free + * libtool.m4: new macro AC_LIBTOOL_DLOPEN: checks for dlopen + and dlopen(NULL) support + * ltconfig.in: added new variables dlopen and dlopen_self, + --enable-dlopen[-self] flags for AC_LIBTOOL_DLOPEN + * ltmain.in: use dlopen[_self], dlpreopen files if there's no + dlopen support, build lt_preloaded_symbols only if + -dl[pre]open was used, include program symbols if -export-dynamic + was specified and there's no dlopen(NULL) support + * mdemo/configure.in: use AC_LIBTOOL_DLOPEN + * mdemo/main.c: demonstrate lt_dlopen(0) + 1999-02-15 Gary V. Vaughan * demo/dlmain.c (_WIN32): The lt_symlist structure is now const, diff --git a/cdemo/Makefile.am b/cdemo/Makefile.am index 942f8f7b1..8e9a844a8 100644 --- a/cdemo/Makefile.am +++ b/cdemo/Makefile.am @@ -2,17 +2,15 @@ # AUTOMAKE_OPTIONS = no-dependencies foreign -INCLUDES = -I$(srcdir)/../libltdl - EXTRA_DIST = acinclude.m4 -noinst_LTLIBRARIES = libfoo1.la +noinst_LTLIBRARIES = libfoo.la -libfoo1_la_SOURCES = foo1.c +libfoo_la_SOURCES = foo.c noinst_HEADERS = foo.h bin_PROGRAMS = cdemo cdemo_SOURCES = main.c -cdemo_LDADD = libfoo1.la $(MATHLIB) +cdemo_LDADD = libfoo.la diff --git a/cdemo/main.c b/cdemo/main.c index 291f35845..79602a249 100644 --- a/cdemo/main.c +++ b/cdemo/main.c @@ -36,8 +36,8 @@ main (argc,argv) if (value == HELLO_RET) printf("hello is ok!\n"); - if (foo1 () == FOO_RET) - printf("foo1 is ok!\n"); + if (foo () == FOO_RET) + printf("foo is ok!\n"); return 0; } diff --git a/libltdl/ltdl.c b/libltdl/ltdl.c index fcade87e7..5a851a589 100644 --- a/libltdl/ltdl.c +++ b/libltdl/ltdl.c @@ -110,7 +110,7 @@ typedef struct lt_dltype_t { int (*lib_open) __P((lt_dlhandle handle, const char *filename)); int (*lib_close) __P((lt_dlhandle handle)); lt_ptr_t (*find_sym) __P((lt_dlhandle handle, const char *symbol)); -} lt_dltype_t, *lt_dltype; +} lt_dltype_t; #define LTDL_TYPE_TOP 0 @@ -619,15 +619,8 @@ presym_open (handle, filename) last_error = no_symbols_error; return 1; } - if (!filename) { - if (!default_preloaded_symbols) { - last_error = file_not_found_error; - return 1; - } else { - handle->handle = (lt_ptr_t) default_preloaded_symbols; - return 0; - } - } + if (!filename) + filename = "@PROGRAM@"; while (lists) { const lt_dlsymlist *syms = lists->syms; @@ -681,14 +674,14 @@ static char *user_search_path = 0; static lt_dlhandle handles = 0; static int initialized = 0; -static lt_dltype types = LTDL_TYPE_TOP; +static lt_dltype_t *types = LTDL_TYPE_TOP; #undef LTDL_TYPE_TOP int lt_dlinit () { /* initialize libltdl */ - lt_dltype *type = &types; + lt_dltype_t **type = &types; int typecount = 0; if (initialized) { /* Initialize only at first call. */ @@ -739,7 +732,7 @@ int lt_dlexit () { /* shut down libltdl */ - lt_dltype type = types; + lt_dltype_t *type = types; int errors; if (!initialized) { @@ -772,7 +765,7 @@ tryall_dlopen (handle, filename) const char *filename; { lt_dlhandle cur; - lt_dltype type = types; + lt_dltype_t *type = types; const char *saved_error = last_error; /* check whether the module was already opened */ @@ -1055,13 +1048,11 @@ lt_dlopen (filename) } handle->usage = 0; newhandle = handle; - if (tryall_dlopen(handle, 0) != 0) { + if (tryall_dlopen(&handle, 0) != 0) { lt_dlfree(newhandle); return 0; } - if (newhandle != handle) - lt_dlfree(newhandle); - return handle; + goto register_handle; } basename = strrchr(filename, '/'); if (basename) { @@ -1221,6 +1212,7 @@ lt_dlopen (filename) return 0; } } +register_handle: if (newhandle != handle) { lt_dlfree(handle); handle = newhandle; diff --git a/libltdl/ltdl.h b/libltdl/ltdl.h index 574869472..2f58da355 100644 --- a/libltdl/ltdl.h +++ b/libltdl/ltdl.h @@ -41,11 +41,11 @@ Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. #undef __P #undef lt_ptr_t #if defined (__STDC__) || defined (_AIX) || (defined (__mips) && defined (_SYSTYPE_SVR4)) || defined(WIN32) || defined(__cplusplus) -# define __P(protos) protos -# define lt_ptr_t void* +# define __P(protos) protos +# define lt_ptr_t void* #else -# define __P(protos) () -# define lt_ptr_t char* +# define __P(protos) () +# define lt_ptr_t char* #endif #include @@ -78,8 +78,8 @@ extern const char *lt_dlgetsearchpath __P((void)); extern const lt_dlsymlist lt_preloaded_symbols[]; #define LTDL_SET_PRELOADED_SYMBOLS() lt_dlpreload_default(lt_preloaded_symbols) -extern lt_ptr_t (*lt_dlmalloc)(size_t size); -extern void (*lt_dlfree)(lt_ptr_t ptr); +extern lt_ptr_t (*lt_dlmalloc)__P((size_t size)); +extern void (*lt_dlfree)__P((lt_ptr_t ptr)); __END_DECLS diff --git a/libtool.m4 b/libtool.m4 index 85fd93889..394f783a9 100644 --- a/libtool.m4 +++ b/libtool.m4 @@ -44,6 +44,8 @@ AC_SUBST(LIBTOOL)dnl libtool_flags= test "$enable_shared" = no && libtool_flags="$libtool_flags --disable-shared" test "$enable_static" = no && libtool_flags="$libtool_flags --disable-static" +test "x$lt_cv_dlopen" = xyes && libtool_flags="$libtool_flags --enable-dlopen" +test "x$lt_cv_dlopen_self" = xyes && libtool_flags="$libtool_flags --enable-dlopen-self" test "$silent" = yes && libtool_flags="$libtool_flags --silent" test "$ac_cv_prog_gcc" = yes && libtool_flags="$libtool_flags --with-gcc" test "$ac_cv_prog_gnu_ld" = yes && libtool_flags="$libtool_flags --with-gnu-ld" @@ -116,6 +118,34 @@ LIBTOOL_DEPS="$ac_aux_dir/ltconfig $ac_aux_dir/ltmain.sh" exec 5>>./config.log ]) +# AC_LIBTOOL_DLOPEN - check for dlopen support +AC_DEFUN(AC_LIBTOOL_DLOPEN, +[AC_CACHE_VAL(lt_cv_dlopen, +[lt_cv_dlopen=no +AC_CHECK_LIB(dl, dlopen, lt_cv_dlopen=yes, + [AC_CHECK_FUNCS(dlopen, lt_cv_dlopen=yes, + [AC_CHECK_LIB(dld, dld_link, lt_cv_dlopen=yes, + [AC_CHECK_FUNCS(shl_load, lt_cv_dlopen=yes)] + )] + )] +)]) + +if test "$lt_cv_dlopen" = yes; then + AC_REQUIRE([AC_PROG_CC])dnl + AC_CACHE_VAL(lt_cv_dlopen_self, + [AC_CACHE_CHECK([whether a program can dlopen itself], lt_cv_dlopen_self, + [AC_TRY_RUN([ +#include +#include +fnord() { int i=42;} +main() { void *self, *ptr1, *ptr2; self=dlopen(0,RTLD_LAZY); + if(self) { ptr1=dlsym(self,"fnord"); ptr2=dlsym(self,"_fnord"); + if(ptr1 || ptr2) exit(0); } exit(1); } +], lt_cv_dlopen_self=no, lt_cv_dlopen_self=yes, lt_cv_dlopen_self=no)]) + ]) +fi +]) + # AC_ENABLE_SHARED - implement the --enable-shared flag # Usage: AC_ENABLE_SHARED[(DEFAULT)] # Where DEFAULT is either `yes' or `no'. If omitted, it defaults to diff --git a/ltconfig.in b/ltconfig.in index fc5c8b5d7..5761c4401 100755 --- a/ltconfig.in +++ b/ltconfig.in @@ -173,6 +173,8 @@ can_build_shared=yes enable_shared=yes # All known linkers require a `.a' archive for static linking. enable_static=yes +enable_dlopen=no +enable_dlopen_self=no ltmain= silent= srcdir= @@ -225,6 +227,8 @@ Generate a system-specific libtool script. --debug enable verbose shell tracing --disable-shared do not build shared libraries --disable-static do not build static libraries + --enable-dlopen enable dlopen support + --enable-dlopen-self enable support for dlopening programs --help display this help and exit --no-verify do not verify that HOST is a valid host type -o, --output=FILE specify the output file [default=$default_ofile] @@ -253,6 +257,10 @@ EOM --disable-static) enable_static=no ;; + --enable-dlopen) enable_dlopen=yes ;; + + --enable-dlopen-self) enable_dlopen_self=yes ;; + --quiet | --silent) silent=yes ;; --srcdir) prev=srcdir ;; @@ -2062,6 +2070,12 @@ need_lib_prefix=$need_lib_prefix # Do we need a version for libraries? need_version=$need_version +# Whether dlopen is supported. +dlopen=$enable_dlopen + +# Whether dlopen of programs is supported. +dlopen_self=$enable_dlopen_self + # Compiler flag to prevent dynamic linking. link_static_flag=$link_static_flag diff --git a/ltmain.in b/ltmain.in index 1bceadbf0..30f4d5d2c 100644 --- a/ltmain.in +++ b/ltmain.in @@ -939,7 +939,7 @@ compiler." # A library object. if test "$prev" = dlfiles; then dlfiles="$dlfiles $arg" - if test "$build_libtool_libs" = yes; then + if test "$build_libtool_libs" = yes && test "$dlopen" = yes; then prev= continue else @@ -1031,8 +1031,8 @@ compiler." # This library was specified with -dlopen. if test "$prev" = dlfiles; then dlfiles="$dlfiles $arg" - if test -z "$dlname" || test "$build_libtool_libs" = no; then - # If there is no dlname or we're linking statically, + if test -z "$dlname" || test "$dlopen" = no || test "$build_libtool_libs" = no; then + # If there is no dlname, no dlopen support or we're linking statically, # we need to preload. prev=dlprefiles else @@ -2088,10 +2088,13 @@ EOF finalize_command=`$echo "X$finalize_command" | $SP2NL | $Xsed -e "$lo2o" | $NL2SP` fi - if test "$export_dynamic" = yes || test -n "$dlfiles$dlprefiles" && test -n "$NM" && test -n "$global_symbol_pipe"; then - dlsyms="${outputname}S.c" - else - dlsyms= + dlsyms= + if test -n "$dlfiles$dlprefiles"; then + if test -n "$NM" && test -n "$global_symbol_pipe"; then + dlsyms="${outputname}S.c" + else + $echo "$modename: not configured to extract global symbols from dlpreopened files" 1>&2 + fi fi if test -n "$dlsyms"; then @@ -2130,7 +2133,7 @@ extern \"C\" { /* External symbol declarations for the compiler. */\ " - if test "$export_dynamic" = yes; then + if test "$export_dynamic" = yes && test "$dlopen_self" = no; then if test -n "$export_symbols"; then $run eval 'sed -e "s/^\(.*\)/\1 \1/" < "$export_symbols" > "$nlist"' else @@ -2189,11 +2192,10 @@ lt_preloaded_symbols[] = {\ " - # First entry is always the program itself - echo >> "$output_objdir/$dlsyms" "\ - {\"${output}\", (lt_ptr_t) 0}," - - if test "$export_dynamic" = yes; then + if test "$export_dynamic" = yes && test "$dlopen_self" = no; then + # First entry is the program itself + echo >> "$output_objdir/$dlsyms" "\ + {\"@PROGRAM@\", (lt_ptr_t) 0}," if test -n "$export_symbols"; then sed 's/^\(.*\)/ {"\1", (lt_ptr_t) \&\1},/' < "$export_symbols" >> "$output_objdir/$dlsyms" else @@ -2261,9 +2263,6 @@ static const void *lt_preloaded_setup() { # We keep going just in case the user didn't refer to # lt_preloaded_symbols. The linker will fail if global_symbol_pipe # really was required. - if test -n "$dlfiles$dlprefiles"; then - $echo "$modename: not configured to extract global symbols from dlpreopened files" 1>&2 - fi # Nullify the symbol file. compile_command=`$echo "X$compile_command" | $Xsed -e "s% @SYMFILE@%%"` diff --git a/mdemo/configure.in b/mdemo/configure.in index 62397027f..ebada43b6 100644 --- a/mdemo/configure.in +++ b/mdemo/configure.in @@ -5,6 +5,7 @@ AM_INIT_AUTOMAKE(mdemo,0.1) AC_PROG_CC AC_C_CONST AC_EXEEXT +AC_LIBTOOL_DLOPEN AM_PROG_LIBTOOL if ${CONFIG_SHELL} ./libtool --features | grep "enable static" >/dev/null; then diff --git a/mdemo/main.c b/mdemo/main.c index 53f86f5de..8355f0c90 100644 --- a/mdemo/main.c +++ b/mdemo/main.c @@ -78,6 +78,51 @@ test_dl (filename) return 0; } +int +myfunc () +{ + return HELLO_RET; +} + +int myvar; + +int +test_dlself () +{ + lt_dlhandle handle; + int (*pmyfunc)() = 0; + int *pmyvar = 0; + + handle = lt_dlopen(0); + if (!handle) { + fprintf (stderr, "can't dlopen the program!\n"); + fprintf (stderr, "error was: %s\n", lt_dlerror()); + return 1; + } + pmyfunc = (int(*)())lt_dlsym(handle, "myfunc"); + pmyvar = (int*)lt_dlsym(handle, "myvar"); + + if (pmyfunc) + { + int value = (*pmyfunc) (); + + printf ("myfunc returned: %i\n", value); + if (value == HELLO_RET) + printf("myfunc is ok!\n"); + } + else + fprintf (stderr, "did not find the `myfunc' function\n"); + + /* Try assigning to the variable. */ + if (pmyvar) + *pmyvar = 1; + else + fprintf (stderr, "did not find the `myvar' variable\n"); + + lt_dlclose(handle); + return 0; +} + int main (argc, argv) int argc; @@ -101,6 +146,9 @@ main (argc, argv) if (test_dl(argv[i])) return 1; + if (test_dlself()) + return 1; + lt_dlexit(); return 0; }