From 17915a088c331d343e1e6f6f98f223689087b6bb Mon Sep 17 00:00:00 2001 From: Thomas Tanner Date: Thu, 11 Feb 1999 23:48:25 +0000 Subject: [PATCH] * autogen: libltdl needs autoheader * demo/Makefile.am: renamed hell.debug to hell.static (we're demonstrating static linking, not debugging) * tests/demo*: ditto * doc/libtool.texi (libltdl): documented new lt_dlopen(NULL) feature * libltdl/acconfig.h: required for config.h * libltdl/configure.in: use config.h * libltdl/ltdl.c: use config.h, support lt_dlopen(NULL) (returns a handle for the program itself) * ltconfig.in: minor reformatting * ltmain.in: in lt_preloaded_symbols always define the program's symbols first, for -export-dynamic list all program symbols together, -export-symbols was broken for programs, minor reformatting * mdemo/Makefile.am: renamed mdemo.debug to mdemo.static * tests/mdemo*: ditto, mdemo.test was completely broken --- ChangeLog | 20 ++++++++++++ autogen | 1 + demo/Makefile.am | 10 +++--- doc/libtool.texi | 7 ++++- libltdl/configure.in | 1 + libltdl/ltdl.c | 57 ++++++++++++++++++++++++++-------- ltconfig.in | 10 +++--- ltmain.in | 69 ++++++++++++++++++++++++++--------------- mdemo/Makefile.am | 12 +++---- tests/demo-exec.test | 4 +-- tests/demo-inst.test | 4 +-- tests/demo.test | 3 +- tests/mdemo-conf.test | 2 +- tests/mdemo-exec.test | 4 +-- tests/mdemo-inst.test | 4 +-- tests/mdemo-shared.test | 2 +- tests/mdemo-static.test | 2 +- tests/mdemo.test | 17 +++++----- 18 files changed, 154 insertions(+), 75 deletions(-) diff --git a/ChangeLog b/ChangeLog index 51496690..df56e0c1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,23 @@ +1999-02-11 Thomas Tanner + + * autogen: libltdl needs autoheader + * demo/Makefile.am: renamed hell.debug to hell.static + (we're demonstrating static linking, not debugging) + * tests/demo*: ditto + * doc/libtool.texi (libltdl): documented new lt_dlopen(NULL) + feature + * libltdl/acconfig.h: required for config.h + * libltdl/configure.in: use config.h + * libltdl/ltdl.c: use config.h, support lt_dlopen(NULL) + (returns a handle for the program itself) + * ltconfig.in: minor reformatting + * ltmain.in: in lt_preloaded_symbols always define + the program's symbols first, for -export-dynamic list all + program symbols together, -export-symbols was broken for + programs, minor reformatting + * mdemo/Makefile.am: renamed mdemo.debug to mdemo.static + * tests/mdemo*: ditto, mdemo.test was completely broken + 1999-02-10 Alexandre Oliva * ltconfig.in (irix5*, irix6*, osf3*, osf4*): do not use diff --git a/autogen b/autogen index a33b4c27..aebb562c 100644 --- a/autogen +++ b/autogen @@ -19,6 +19,7 @@ for sub in demo depdemo libltdl mdemo cdemo; do rm -f acinclude.m4 cp ../libtool.m4 acinclude.m4 aclocal + autoheader automake --gnits --add-missing autoconf cd .. diff --git a/demo/Makefile.am b/demo/Makefile.am index 4c8cf4d7..ac93cb6d 100644 --- a/demo/Makefile.am +++ b/demo/Makefile.am @@ -20,16 +20,16 @@ else BUILD_helldl = endif -bin_PROGRAMS = hell hell.debug $(BUILD_helldl) +bin_PROGRAMS = hell hell.static $(BUILD_helldl) # Build hell from main.c and libhello.la hell_SOURCES = main.c hell_LDADD = libhello.la -# Create an easier-to-debug version of hell. -hell_debug_SOURCES = main.c -hell_debug_LDADD = libhello.la -hell_debug_LDFLAGS = $(STATIC) +# Create a statically linked version of hell. +hell_static_SOURCES = main.c +hell_static_LDADD = libhello.la +hell_static_LDFLAGS = $(STATIC) if BINARY_HELLDL diff --git a/doc/libtool.texi b/doc/libtool.texi index 70daa9c6..2e3c630c 100644 --- a/doc/libtool.texi +++ b/doc/libtool.texi @@ -2612,7 +2612,8 @@ Return 0 on success, otherwise the number of errors. @deftypefun lt_dlhandle lt_dlopen (const char *@var{filename}) Open the module with the file name @var{filename} and return a handle for it. @code{lt_dlopen} is able to open libtool dynamic -modules, preloaded static modules and native dynamic libraries. +modules, preloaded static modules, the program itself and +native dynamic libraries. Unresolved symbols in the module are resolved using its dependency libraries and previously dlopened modules. If the executable using this @@ -2621,6 +2622,10 @@ symbols in the executable will also be used to resolve references in the module. Libltdl tries to resolve the symbols immediately and returns @code{NULL} if that fails. +If @var{filename} is NULL @code{lt_dlopen} will return a handle +for the program itself, which can be used to access its symbols +if it was linked with @code{-export-dynamic}. + If libltdl cannot find the library and the file name @var{filename} does not have a directory component it will additionally search in the following search paths for the module (in the order as follows): diff --git a/libltdl/configure.in b/libltdl/configure.in index 7b8fe65d..39aa2051 100644 --- a/libltdl/configure.in +++ b/libltdl/configure.in @@ -2,6 +2,7 @@ dnl Process this file with autoconf to create configure. dnl Initialize the libltdl package. AC_INIT(ltdl.c) AM_INIT_AUTOMAKE(libltdl,1.0,-) +AM_CONFIG_HEADER(config.h) AM_MAINTAINER_MODE diff --git a/libltdl/ltdl.c b/libltdl/ltdl.c index f53f50bf..3e395851 100644 --- a/libltdl/ltdl.c +++ b/libltdl/ltdl.c @@ -20,6 +20,10 @@ Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. #define _LTDL_COMPILE_ +#if HAVE_CONFIG_H +#include +#endif + #if HAVE_STRING_H #include #endif @@ -608,14 +612,19 @@ presym_open (handle, filename) { lt_dlsymlists_t *lists = preloaded_symbols; - if (!filename) { - last_error = file_not_found_error; - return 1; - } if (!lists) { 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; + } + } while (lists) { const lt_dlsymlist *syms = lists->syms; @@ -765,8 +774,14 @@ tryall_dlopen (handle, filename) /* check whether the module was already opened */ cur = handles; - while (cur && strcmp(cur->filename, filename)) + while (cur) { + if (!cur->filename && !filename) + break; + if (cur->filename && filename && + strcmp(cur->filename, filename)) + break; cur = cur->next; + } if (cur) { cur->usage++; *handle = cur; @@ -774,18 +789,22 @@ tryall_dlopen (handle, filename) } cur = *handle; - cur->filename = strdup(filename); - if (!cur->filename) { - last_error = memory_error; - return 1; - } + if (filename) { + cur->filename = strdup(filename); + if (!cur->filename) { + last_error = memory_error; + return 1; + } + } else + cur->filename = 0; while (type) { if (type->lib_open(cur, filename) == 0) break; type = type->next; } if (!type) { - free(cur->filename); + if (cur->filename) + free(cur->filename); return 1; } cur->type = type; @@ -1026,8 +1045,20 @@ lt_dlopen (filename) char *dir = 0, *name = 0; if (!filename) { - last_error = file_not_found_error; - return 0; + handle = (lt_dlhandle) malloc(sizeof(lt_dlhandle_t)); + if (!handle) { + last_error = memory_error; + return 0; + } + handle->usage = 0; + newhandle = handle; + if (tryall_dlopen(handle, 0) != 0) { + free(newhandle); + return 0; + } + if (newhandle != handle) + free(newhandle); + return handle; } basename = strrchr(filename, '/'); if (basename) { diff --git a/ltconfig.in b/ltconfig.in index ca693b78..fa1525b8 100755 --- a/ltconfig.in +++ b/ltconfig.in @@ -1128,13 +1128,13 @@ else allow_undefined_flag= if test "$with_gcc" = yes; then if strings `${CC} -print-prog-name=collect2` | \ - grep resolve_lib_name >/dev/null + grep resolve_lib_name >/dev/null then - # We have reworked collect2 - hardcode_direct=yes + # We have reworked collect2 + hardcode_direct=yes else - # We have old collect2 - hardcode_direct=unsupported + # We have old collect2 + hardcode_direct=unsupported fi archive_cmds='$CC -shared ${wl}-bnoentry -o $objdir/$soname $libobjs $deplibs $linkopts' else diff --git a/ltmain.in b/ltmain.in index 1761d5ce..f0ba67a4 100644 --- a/ltmain.in +++ b/ltmain.in @@ -431,14 +431,14 @@ compiler." # All platforms use -DPIC, to notify preprocessed assembler code. command="$base_compile $pic_flag -DPIC $srcfile" if test "$build_old_libs" = yes; then - lo_libobj="$libobj" + lo_libobj="$libobj" dir=`$echo "X$libobj" | $Xsed -e 's%/[^/]*$%%'` if test "X$dir" = "X$libobj"; then dir="$objdir" else dir="$dir/$objdir" fi - libobj="$dir/"`$echo "X$libobj" | $Xsed -e 's%^.*/%%'` + libobj="$dir/"`$echo "X$libobj" | $Xsed -e 's%^.*/%%'` if test -d "$dir"; then $show "$rm $libobj" @@ -501,7 +501,7 @@ compiler." # If we have no pic_flag, then copy the object into place and finish. if test -z "$pic_flag" && test "$build_old_libs" = yes; then # Rename the .lo from within objdir to obj - if test -f $obj; then + if test -f $obj; then $show $rm $obj $run $rm $obj fi @@ -580,8 +580,8 @@ compiler." # Create an invalid libtool object if no PIC, so that we do not # accidentally link it into a program. if test "$build_libtool_libs" != yes; then - $show "echo timestamp > $libobj" - $run eval "echo timestamp > \$libobj" || exit $? + $show "echo timestamp > $libobj" + $run eval "echo timestamp > \$libobj" || exit $? else # Move the .lo from within objdir $show "$mv $libobj $lo_libobj" @@ -748,6 +748,7 @@ compiler." exit 1 fi prev= + continue ;; release) release="-$arg" @@ -1390,8 +1391,8 @@ compiler." # How the heck are we supposed to write a wrapper for a shared library? if test -n "$link_against_libtool_libs"; then - $echo "$modename: error: cannot link shared libraries into libtool libraries" 1>&2 - exit 1 + $echo "$modename: error: cannot link shared libraries into libtool libraries" 1>&2 + exit 1 fi if test -n "$dlfiles$dlprefiles"; then @@ -1716,7 +1717,7 @@ EOF # but so what? potlib="$potent_lib" while test -h "$potlib" 2>/dev/null; do - potliblink=`ls -ld $potlib | sed 's/.* -> //'` + potliblink=`ls -ld $potlib | sed 's/.* -> //'` case "$potliblink" in /*) potlib="$potliblink";; *) potlib=`$echo "X$potlib" \ @@ -1822,13 +1823,13 @@ EOF # Ensure that we have .o objects for linkers which dislike .lo # (e.g. aix) incase we are running --disable-static - for obj in $libobjs; do - oldobj=`echo $obj | $Xsed -e "$lo2o"` - test -f $oldobj || ${LN_S} $obj $oldobj - done + for obj in $libobjs; do + oldobj=`echo $obj | $Xsed -e "$lo2o"` + test -f $oldobj || ${LN_S} $obj $oldobj + done # Use standard objects if they are pic - test -z "$pic_flag" && libobjs=`$echo "X$libobjs" | $SP2NL | $Xsed -e "$lo2o" | $NL2SP` + test -z "$pic_flag" && libobjs=`$echo "X$libobjs" | $SP2NL | $Xsed -e "$lo2o" | $NL2SP` if test -n "$whole_archive_flag_spec"; then if test -n "$convenience"; then @@ -2086,11 +2087,6 @@ EOF case "$dlsyms" in "") ;; *.c) - if test "$export_dynamic" = yes && test -z "$export_symbols"; then - # Add our own program objects to the preloaded list. - dlprefiles=`$echo "X$objs $dlprefiles" | $SP2NL | $Xsed -e "$lo2o" | $NL2SP` - fi - # Discover the nlist of each of the dlfiles. nlist="$objdir/${output}.nm" @@ -2123,8 +2119,17 @@ extern \"C\" { /* External symbol declarations for the compiler. */\ " - if test "$export_dynamic" = yes && test -n "$export_symbols"; then - sed -e 's/^\(.*\)/\1 \1/' < "$export_symbols" > "$nlist" + if test "$export_dynamic" = yes; then + if test -n "$export_symbols"; then + $run eval 'sed -e "s/^\(.*\)/\1 \1/" < "$export_symbols" > "$nlist"' + else + # Add our own program objects to the preloaded list. + progfiles=`$echo "X$objs" | $SP2NL | $Xsed -e "$lo2o" | $NL2SP` + for arg in $progfiles; do + $show "extracting global C symbols from \`$arg'" + $run eval "$NM $arg | $global_symbol_pipe >> '$nlist'" + done + fi fi for arg in $dlprefiles; do @@ -2169,10 +2174,24 @@ lt_preloaded_symbols[] = {\ " - if test "$export_dynamic" = yes && test -n "$export_symbols"; then - echo >> "$output_objdir/$dlsyms" "\ + # First entry is always the program itself + echo >> "$output_objdir/$dlsyms" "\ {\"${output}\", (lt_ptr_t) 0}," - sed 's/^\(.*\)/ {"\1", (lt_ptr_t) \&\1},/' < "$export_symbols" >> "$output_objdir/$dlsyms" + + if test "$export_dynamic" = yes; then + if test -n "$export_symbols"; then + sed 's/^\(.*\)/ {"\1", (lt_ptr_t) \&\1},/' < "$export_symbols" >> "$output_objdir/$dlsyms" + else + $rm "$nlist" + for arg in $progfiles; do + eval "$NM $arg | $global_symbol_pipe >> '$nlist'" + done + if test -f "$nlist"; then + sed 's/^\(.*\) \(.*\)$/ {"\1", (lt_ptr_t) \&\2},/' < "$nlist" >> "$output_objdir/$dlsyms" + else + echo '/* NONE */' >> "$output_objdir/$dlsyms" + fi + fi fi for arg in $dlprefiles; do @@ -2284,7 +2303,7 @@ static const void *lt_preloaded_setup() { fi if test -n "$runpath_var"; then - if test -n "$perm_rpath"; then + if test -n "$perm_rpath"; then # We should set the runpath_var. rpath= for dir in $perm_rpath; do @@ -2292,7 +2311,7 @@ static const void *lt_preloaded_setup() { done compile_command="$runpath_var=\"$rpath\$$runpath_var\" $compile_command" fi - if test -n "$finalize_perm_rpath"; then + if test -n "$finalize_perm_rpath"; then # We should set the runpath_var. rpath= for dir in $finalize_perm_rpath; do diff --git a/mdemo/Makefile.am b/mdemo/Makefile.am index 97ed28be..569000df 100644 --- a/mdemo/Makefile.am +++ b/mdemo/Makefile.am @@ -16,7 +16,7 @@ libfoo2_la_LDFLAGS = $(LIBADD_M) -module noinst_HEADERS = foo.h -bin_PROGRAMS = mdemo mdemo.debug +bin_PROGRAMS = mdemo mdemo.static ../libltdl/libltdl.la: ../libtool ../libltdl/libtool \ $(srcdir)/../libltdl/ltdl.c $(srcdir)/../libltdl/ltdl.h @@ -33,8 +33,8 @@ mdemo_LDFLAGS = -export-dynamic ## FIXME: remove this when libtool and libltdl mdemo_LDADD = ../libltdl/libltdl.la "-dlopen" foo1.la "-dlopen" libfoo2.la mdemo_DEPENDENCIES = ../libltdl/libltdl.la foo1.la libfoo2.la -# Create an easier-to-debug version of mdemo. -mdemo_debug_SOURCES = $(mdemo_SOURCES) -mdemo_debug_LDFLAGS = $(STATIC) $(mdemo_LDFLAGS) -mdemo_debug_LDADD = $(mdemo_LDADD) -mdemo_debug_DEPENDENCIES = $(mdemo_DEPENDENCIES) +# Create a statically linked version of mdemo. +mdemo_static_SOURCES = $(mdemo_SOURCES) +mdemo_static_LDFLAGS = $(STATIC) $(mdemo_LDFLAGS) +mdemo_static_LDADD = $(mdemo_LDADD) +mdemo_static_DEPENDENCIES = $(mdemo_DEPENDENCIES) diff --git a/tests/demo-exec.test b/tests/demo-exec.test index afe5912a..bdf61bc0 100755 --- a/tests/demo-exec.test +++ b/tests/demo-exec.test @@ -20,9 +20,9 @@ fi echo "Executing uninstalled programs in ../demo" status=0 -if ../demo/hell.debug| grep 'Welcome to GNU Hell'; then : +if ../demo/hell.static| grep 'Welcome to GNU Hell'; then : else - echo "$0: cannot execute ../demo/hell.debug" 1>&2 + echo "$0: cannot execute ../demo/hell.static" 1>&2 status=1 fi diff --git a/tests/demo-inst.test b/tests/demo-inst.test index 3e99e5e7..419cafdf 100755 --- a/tests/demo-inst.test +++ b/tests/demo-inst.test @@ -25,9 +25,9 @@ $make install || exit 1 echo "= Executing installed programs" status=0 -if $prefix/bin/hell.debug | grep 'Welcome to GNU Hell'; then : +if $prefix/bin/hell.static | grep 'Welcome to GNU Hell'; then : else - echo "$0: cannot execute $prefix/bin/hell.debug" 1>&2 + echo "$0: cannot execute $prefix/bin/hell.static" 1>&2 status=1 fi diff --git a/tests/demo.test b/tests/demo.test index 25b0ce8d..072cb680 100644 --- a/tests/demo.test +++ b/tests/demo.test @@ -55,7 +55,8 @@ fi if $prefix/bin/hell | grep 'GNU Hell'; then : else - echo "$0: warning: cannot execute $prefix/bin/hell" 1>&2 + echo "$0: cannot execute $prefix/bin/hell" 1>&2 + exit 1 fi echo "= Running make uninstall in ../demo" diff --git a/tests/mdemo-conf.test b/tests/mdemo-conf.test index 28c39ff5..d74b1356 100755 --- a/tests/mdemo-conf.test +++ b/tests/mdemo-conf.test @@ -1,5 +1,5 @@ #! /bin/sh -# mdemo-conf.test - try configuring the ../libltdl and ../mdemo subdirectories +# mdemo-conf.test - try configuring the ../mdemo subdirectory # Test script header. need_prefix=yes diff --git a/tests/mdemo-exec.test b/tests/mdemo-exec.test index d8651f03..a7d241e4 100755 --- a/tests/mdemo-exec.test +++ b/tests/mdemo-exec.test @@ -20,9 +20,9 @@ fi echo "Executing uninstalled programs in ../mdemo" status=0 -if ../mdemo/mdemo.debug ../mdemo/foo1.la ../mdemo/libfoo2.la; then : +if ../mdemo/mdemo.static ../mdemo/foo1.la ../mdemo/libfoo2.la; then : else - echo "$0: cannot execute ../mdemo/mdemo.debug" 1>&2 + echo "$0: cannot execute ../mdemo/mdemo.static" 1>&2 status=1 fi diff --git a/tests/mdemo-inst.test b/tests/mdemo-inst.test index c4fd7fab..fcd4025d 100755 --- a/tests/mdemo-inst.test +++ b/tests/mdemo-inst.test @@ -26,9 +26,9 @@ $make install || exit 1 echo "= Executing installed programs" status=0 -if $prefix/bin/mdemo.debug $prefix/lib/foo1.la $prefix/lib/libfoo2.la; then : +if $prefix/bin/mdemo.static $prefix/lib/foo1.la $prefix/lib/libfoo2.la; then : else - echo "$0: cannot execute $prefix/bin/mdemo.debug" 1>&2 + echo "$0: cannot execute $prefix/bin/mdemo.static" 1>&2 status=1 fi diff --git a/tests/mdemo-shared.test b/tests/mdemo-shared.test index f1b3feea..9f1d3a55 100755 --- a/tests/mdemo-shared.test +++ b/tests/mdemo-shared.test @@ -1,5 +1,5 @@ #! /bin/sh -# mdemo-conf.test - try configuring the ../libltdl and ../mdemo subdirectories +# mdemo-conf.test - try configuring the ../mdemo subdirectory # Test script header. need_prefix=yes diff --git a/tests/mdemo-static.test b/tests/mdemo-static.test index b063fc5c..b6ecb5ec 100755 --- a/tests/mdemo-static.test +++ b/tests/mdemo-static.test @@ -1,5 +1,5 @@ #! /bin/sh -# mdemo-conf.test - try configuring the ../libltdl and ../mdemo subdirectories +# mdemo-conf.test - try configuring the ../mdemo subdirectory # Test script header. need_prefix=yes diff --git a/tests/mdemo.test b/tests/mdemo.test index 225853b1..9af96cef 100644 --- a/tests/mdemo.test +++ b/tests/mdemo.test @@ -31,15 +31,15 @@ make || exit 1 # Try running the program. echo "= Executing uninstalled programs" -if ./hell.debug | grep 'GNU Hell'; then : +if ./mdemo.static foo1.la libfoo2.la; then : else - echo "$0: cannot execute ./hell.debug" 1>&2 + echo "$0: cannot execute ./mdemo.static" 1>&2 exit 1 fi -if ./hell | grep 'GNU Hell'; then : +if ./mdemo foo1.la libfoo2.la; then : else - echo "$0: cannot execute ./hell" 1>&2 + echo "$0: cannot execute ./mdemo" 1>&2 exit 1 fi @@ -47,15 +47,16 @@ echo "= Running make install in ../mdemo" make install || exit 1 echo "= Executing installed programs" -if $prefix/bin/hell.debug | grep 'GNU Hell'; then : +if $prefix/bin/mdemo.static $prefix/lib/foo1.la $prefix/lib/libfoo2.la; then : else - echo "$0: cannot execute $prefix/bin/hell.debug" 1>&2 + echo "$0: cannot execute $prefix/bin/mdemo.static" 1>&2 exit 1 fi -if $prefix/bin/hell | grep 'GNU Hell'; then : +if $prefix/bin/mdemo $prefix/lib/foo1.la $prefix/lib/libfoo2.la; then : else - echo "$0: warning: cannot execute $prefix/bin/hell" 1>&2 + echo "$0: cannot execute $prefix/bin/mdemo" 1>&2 + exit 1 fi echo "= Running make uninstall in ../mdemo"