lt_dlopenext() sets error on succesful loading the library
Hi, There was an error report on the Debian bug tracking system that lt_dlopenext() sets an error on succesful loading the library if no extention was given. See: http://bugs.debian.org/510006 Here are the patches I've made for both the 1.5 and 2.2 branch. PS: Can somebody fix the example in autobook? Kurt diff --git a/libltdl/ltdl.c b/libltdl/ltdl.c index b747b70..e619c94 100644 --- a/libltdl/ltdl.c +++ b/libltdl/ltdl.c @@ -3491,6 +3491,9 @@ lt_dlopenext (filename) char * ext = 0; size_t len; int errors = 0; + const char * saved_error = 0; + + LT_DLMUTEX_GETERROR (saved_error); if (!filename) { @@ -3534,6 +3537,7 @@ lt_dlopenext (filename) } #ifdef LTDL_SHLIB_EXT + LT_DLMUTEX_SETERROR (saved_error); /* Try appending SHLIB_EXT. */ if (LT_STRLEN (shlib_ext) > LT_STRLEN (archive_ext)) { diff --git a/libltdl/ltdl.c b/libltdl/ltdl.c index 6e19599..80b5675 100644 --- a/libltdl/ltdl.c +++ b/libltdl/ltdl.c @@ -1614,6 +1614,9 @@ lt_dlopenadvise (const char *filename, lt_dladvise advise) { lt_dlhandle handle = 0; int errors = 0; + const char * saved_error = 0; + + LT__GETERROR (saved_error); /* Can't have symbols hidden and visible at the same time! */ if (advise && advise->is_symlocal && advise->is_symglobal) @@ -1650,6 +1653,7 @@ lt_dlopenadvise (const char *filename, lt_dladvise advise) #if defined(LT_MODULE_EXT) /* Try appending SHLIB_EXT. */ + LT__SETERRORSTR (saved_error); errors = try_dlopen (&handle, filename, shlib_ext, advise); /* As before, if the file was found but loading failed, return now
Re: [PATCH] [cygwin|mingw] fix dlpreopen with --disable-static
* libltdl/config/ltmain.m4sh (func_dlltool_identify): New function. (func_win32_dllname_for_implib): New function. (func_mode_link) [cygwin|mingw]: Use linklib (that is, import lib) as dlpreopen file, rather than DLL. (func_generate_dlsyms) [cygwin|mingw]: Use func_win32_dllname_for_implib to extract DLL name from import library. Also, properly extract dlsyms from the import library. * libltdl/m4/libtool.m4 (_LT_LINKER_SHLIBS) [cygwin|mingw][C++]: Set exclude_expsyms correctly for $host. Simplify regular expression in export_symbols_cmds. (_LT_LINKER_SHLIBS) [cygwin|mingw|pw32][C]: Set exclude_expsyms correctly for $host. Enable export_symbols_cmds to identify DATA exports by _nm_ prefix. --- This is a revised -- but obsoleted -- version of a patch first posted here: http://lists.gnu.org/archive/html/libtool-patches/2008-11/msg00019.html in response to a bug first posted here: http://lists.gnu.org/archive/html/bug-libtool/2008-05/msg00054.html This version of the patch corrects all issues raised in that thread and is updated to current master -- except for two issues: 1) This idiom eval '$ECHO ": $name " >> "$nlist"' eval "$NM $dlprefile 2>/dev/null | $global_symbol_pipe >> '$nlist'" is still used, rather than $ECHO ": $name " >> "$nlist" eval "$NM $dlprefile 2>/dev/null | $global_symbol_pipe >> '$nlist'" because, while "extra" evals are bad, the idiom predated this patch, and should be cleaned up -- if it needs to be -- in a separate patch. 2) At the end of the thread, Ralf had a suggestion for "saving" the name of the la file associated with each import library in the dlpreopen list. This avoids the need for func_win32_dllname_for_implib(), except when there IS no la file. I've implemented a version of that idea, but not here. The new implmentation completely obsoletes (but incorporates large parts of) this patch. So why post this one? For completeness, and to terminate the originating thread. I'll start a new thread with the new patch. = libltdl/config/ltmain.m4sh | 148 +--- libltdl/m4/libtool.m4 |8 ++- 2 files changed, 145 insertions(+), 11 deletions(-) diff --git a/libltdl/config/ltmain.m4sh b/libltdl/config/ltmain.m4sh index 20ca07b..c7d0dc0 100644 --- a/libltdl/config/ltmain.m4sh +++ b/libltdl/config/ltmain.m4sh @@ -2001,10 +2001,36 @@ extern \"C\" { func_verbose "extracting global C symbols from \`$dlprefile'" func_basename "$dlprefile" name="$func_basename_result" - $opt_dry_run || { - eval '$ECHO ": $name " >> "$nlist"' - eval "$NM $dlprefile 2>/dev/null | $global_symbol_pipe >> '$nlist'" - } + case $host in + *cygwin | *mingw* ) + # if an import library, we need to obtain dlname + if func_win32_import_lib_p "$dlprefile"; then + func_win32_dllname_for_implib "$dlprefile" + dllname=$func_win32_dllname_for_implib_result + $opt_dry_run || { + if test -n "$dllname" ; then + eval '$ECHO ": $dllname " >> "$nlist"' + else + func_warning "Could not compute DLL name from $name" + eval '$ECHO ": $name " >> "$nlist"' + fi + eval "$NM $dlprefile 2>/dev/null | $global_symbol_pipe | + $SED -e '/I __imp/d' -e 's/I __nm_/D /;s/_nm__//' >> '$nlist'" + } + else + $opt_dry_run || { + eval '$ECHO ": $name " >> "$nlist"' + eval "$NM $dlprefile 2>/dev/null | $global_symbol_pipe >> '$nlist'" + } + fi + ;; +* ) + $opt_dry_run || { + eval '$ECHO ": $name " >> "$nlist"' + eval "$NM $dlprefile 2>/dev/null | $global_symbol_pipe >> '$nlist'" + } + ;; + esac done $opt_dry_run || { @@ -2208,6 +2234,99 @@ func_win32_libid () $ECHO "$win32_libid_type" } +# func_dlltool_identify +# Determine if $DLLTOOL supports the --identify option +func_dlltool_identify () +{ + $opt_debug + if test -z "$func_dlltool_identify_result"; then +case `$DLLTOOL --help` in +*--identify*) func_dlltool_identify_result=: ;; +*) func_dlltool_identify_result=false ;; +esac + fi + $func_dlltool_identify_result +} + +# func_win32_dllname_for_implib implib +# Obtain the name of the DLL associated with the +# specified import library. Result is available +# in $func_win32_dllname_for_implib_result. +# +func_win32_dllname_for_implib () +{ + $opt_debug + func_win32_dllname_for_implib_result="" + + if func_dlltool_identify ; then +func_win32_dllname_for_implib_result=`$DLLTOOL --identify "$1" 2>/dev/null` +# if this fails, the fallback code is unlikely to succeed, so +# we don't bother... + else +# use fallback dlltool does not have the --identify option
[PATCH] [cygwin|mingw] fix dlpreopen with --disable-static take 2
* libltdl/config/general.m4sh: Adjust copyright date. (func_tr_sh): New function. * libltdl/config/ltmain.m4sh: Adjust copyright date. (func_dlltool_identify): New function. (func_win32_dllname_for_implib): New function. (func_generate_dlsyms) [cygwin|mingw]: Obtain DLL name corresponding to import library by using value stored in unique variable libfile_$(transliterated implib name). If that fails, use func_win32_dllname_for_implib to extract DLL name from import library directly. Also, properly extract dlsyms from the import library. (func_mode_link) [cygwin|mingw]: Prefer to dlpreopen DLLs over static libs when both are available. When dlpreopening DLLs, Use linklib (that is, import lib) as dlpreopen file, rather than DLL. Store name of associated la file in unique variable libfile_$(transliterated implib name) for later use. * libltdl/m4/libtool.m4: Adjust copyright date. (_LT_COPYING): Adjust copyright date. (_LT_CMD_GLOBAL_SYMBOLS): adjust sed expressions for lt_cv_sys_global_symbol_to_c_name_address and lt_cv_sys_global_symbol_to_c_name_address_lib_prefix as trailing space after module name is optional. (_LT_LINKER_SHLIBS) [cygwin|mingw][C++]: Set exclude_expsyms correctly for $host. Simplify regular expression in export_symbols_cmds. (_LT_LINKER_SHLIBS) [cygwin|mingw|pw32][C]: Set exclude_expsyms correctly for $host. Enable export_symbols_cmds to identify DATA exports by _nm_ prefix. --- This is a revised version of patch(es) posted here http://lists.gnu.org/archive/html/libtool-patches/2008-11/msg00019.html and here: http://lists.gnu.org/archive/html/libtool-patches/2009-01/msg1.html In response to a bug reported here: http://lists.gnu.org/archive/html/bug-libtool/2008-05/msg00054.html Please see those threads for a discussion of the need for this patch and the approach taken here. One change reflected in the patch below, but not discussed in the preceeding threads, is that for systems-supporting-PE-DLLs (e.g. cygwin, mingw, cegcc), the linker will automatically link against the import library instead of the static library if both are present in the search path. However, earlier versions of this patch -- and indeed, un-patched libtool -- would, in the both-are-present case, extract symbols from the static library always, even tho the final dlpreopen link was against the import library. This situation led to an erroneous symbol list: lt__PROGRAM__LTX_preloaded_symbols[] = { { "@PROGRAM@", (void *) 0 }, {"libhello.a", (void *) 0}, HERE {"nothing", (void *) ¬hing}, {"hello", (void *) &hello}, {"foo", (void *) &foo}, {0, (void *) 0} }; when the correct symbol list should be: lt__PROGRAM__LTX_preloaded_symbols[] = { { "@PROGRAM@", (void *) 0 }, {"cyghello-2.dll", (void *) 0}, HERE {"nothing", (void *) ¬hing}, {"hello", (void *) &hello}, {"foo", (void *) &foo}, {0, (void *) 0} }; The patch below therefore modifies func_generate_dlsyms to prefer the DLL/import library over the static library when both are present -- but only for PE-DLL platforms. Other platforms still prefer to dlpreopen static libraries when both are present. bootstrapped on cygwin, tested the demo-{conf|shared|static} + demo-make + demo-exec test cases with success. Full test suite in progress. = libltdl/config/general.m4sh | 15 +++- libltdl/config/ltmain.m4sh | 198 ++- libltdl/m4/libtool.m4 | 16 ++-- 3 files changed, 201 insertions(+), 28 deletions(-) diff --git a/libltdl/config/general.m4sh b/libltdl/config/general.m4sh index 4bc304c..c4de91a 100644 --- a/libltdl/config/general.m4sh +++ b/libltdl/config/general.m4sh @@ -1,6 +1,6 @@ m4_if([general.m4sh -- general shell script boiler plate -*- Autoconf -*- - Copyright (C) 2004, 2005, 2007, 2008 Free Software Foundation, Inc. + Copyright (C) 2004, 2005, 2007, 2008, 2009 Free Software Foundation, Inc. Written by Gary V. Vaughan, 2004 This file is part of GNU Cvs-utils. @@ -412,5 +412,18 @@ func_show_eval_locale () fi fi } + +# func_tr_sh +# turn $1 into a string suitable for a shell variable name +# result is stored in $func_tr_sh_result +func_tr_sh () +{ + func_tr_sh_result=`echo "$1" | $SED -e 's/[^A-Za-z0-9_]/_/g'` + # ensure result begins with non-digit + case "$func_tr_sh_result" in +[A-Za-z_][A-Za-z0-9_] ) ;; +* ) func_tr_sh_result=_$func_tr_sh_result ;; + esac +} ]]) diff --git a/libltdl/config/ltmain.m4sh b/libltdl/config/ltmain.m4sh index 20ca07b..503457c 100644 --- a/libltdl/config/ltmain.m4sh +++ b/libltdl/config/ltmain.m4sh @@ -5,7 +5,7 @@ m4_divert_push([SCRIPT])# @configure_input@ # Written by Gordon Matzigkeit , 1996 # Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005, -# 2006, 2007, 2008 Free Software Foundation, Inc. +# 2006, 2007, 2008, 2009 Free Software Foundation, Inc. # This is free software; see the source for copying conditions. There is NO # warranty; not even for MERCHANTABILITY o
Re: [PATCH] [cygwin|mingw] fix dlpreopen with --disable-static take 2
Charles Wilson wrote: > bootstrapped on cygwin, tested the > demo-{conf|shared|static} + demo-make + demo-exec > test cases with success. Full test suite in progress. And...4.5 hours later, test suite results on cygwin (1.7.0-37, but that shouldn't matter. The good news is, cygwin-1.7 now handles missing DLL errors without a GUI popup dialog. Un-attended testsuite execution on Vista has been restored!) old: === All 113 tests passed (11 tests were not run) === SKIP: tests/cdemo-undef.test SKIP: tests/tagdemo-undef.test SKIP: tests/fcdemo-* == 9 tests new: 76 tests behaved as expected. 5 tests were skipped. 23: Java convenience archives skipped (convenience.at:230) 27: shlibpath_overrides_runpath skipped (shlibpath.at:54) 41: GCJ inferred tag skipped (infer-tag.at:84) 52: ltdl API skipped (ltdl-api.at:31) 81: darwin fat compileskipped (darwin.at:42) OK to push? Comments? Revisions? -- Chuck
[PATCH] [cygwin|mingw] Fix compile warnings when -std=c89.
* libltdl/config/ltmain.m4sh: Update copyright date. (func_emit_wrapper_part1): move contents to... (func_emit_wrapper_part2): move contents to... (func_emit_wrapper): here. (func_emit_cwrapperexe_src) [file scope]: re-organized includes and portability macros. Avoid oldnames on MINGW32 and MSVC for setmode/stat/chmod/getcwd/putenv. Declare _putenv on MINGW32 when -ansi. Use namespaced macro LT_DEBUGWRAPPER. Remove variables script_text_part1 and script_text_part2. (func_emit_cwrapperexe_src) [lt_dump_script]: New function. (func_emit_cwrapperexe_src) [main]: Call it. --- This patch attempts to correct the issues raised in this thread: "msys/mingw warnings about string length and putenv absence with gcc -Wall -ansi" http://lists.gnu.org/archive/html/bug-libtool/2008-12/msg00038.html There was an earlier, similar patch related to errors that occurred when -std=c99. One of those errors, related to a limitation on const char* arrays to less than 4096 bytes, led to splitting the existing function 'func_emit_wrapper' into two different pieces, each less than 4096 characters. However, the string limitation in c89 is 509 characters, which would lead to too many such subfunctions. Futher, it would be very difficult to chose breakpoints to ensure this char length limit, when some chunks would include long variable values such as LD_LIBRARY_PATH or PATH. To achieve this more stringent limitation, the best we can (easily) do is to emit each line of the script as a single const char*. Thus, we require -- but do not check -- that each line in the wrapper script has less than 509 characters. However, we do not want 127 'func_emit_wrapper_partN' functions. So, in this patch I reverted the "split" and moved all of the script contents back into func_emit_wrapper. However, when building the cwrapper source code, each line of the script is turned into a separate C string: fputs ("one line\n", stdout); I probably should have done it this way to start with, but was trying to avoid 127 different function calls. Oh well. Also took the opportunity here to move the DEBUGWRAPPER macro into the LT_* namespace, and to reorganize the #includes and the portability #defines into separate sections. Spot checked some regression tests on cygwin (all passed). Running full regression suite on mingw. OK to push, pending testsuite results? = libltdl/config/ltmain.m4sh | 132 1 files changed, 59 insertions(+), 73 deletions(-) diff --git a/libltdl/config/ltmain.m4sh b/libltdl/config/ltmain.m4sh index 20ca07b..ebedf69 100644 --- a/libltdl/config/ltmain.m4sh +++ b/libltdl/config/ltmain.m4sh @@ -5,7 +5,7 @@ m4_divert_push([SCRIPT])# @configure_input@ # Written by Gordon Matzigkeit , 1996 # Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005, -# 2006, 2007, 2008 Free Software Foundation, Inc. +# 2006, 2007, 2008, 2009 Free Software Foundation, Inc. # This is free software; see the source for copying conditions. There is NO # warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. @@ -2309,15 +2309,23 @@ func_extract_archives () } - -# func_emit_wrapper_part1 [arg=no] +# func_emit_wrapper [arg=no] +# +# Emit a libtool wrapper script on stdout. +# Don't directly open a file because we may want to +# incorporate the script contents within a cygwin/mingw +# wrapper executable. Must ONLY be called from within +# func_mode_link because it depends on a number of variables +# set therein. # -# Emit the first part of a libtool wrapper script on stdout. -# For more information, see the description associated with -# func_emit_wrapper(), below. -func_emit_wrapper_part1 () +# ARG is the value that the WRAPPER_SCRIPT_BELONGS_IN_OBJDIR +# variable will take. If 'yes', then the emitted script +# will assume that the directory in which it is stored is +# the $objdir directory. This is a cygwin/mingw-specific +# behavior. +func_emit_wrapper () { - func_emit_wrapper_part1_arg1=${1-no} + func_emit_wrapper_arg1=${1-no} $ECHO "\ #! $SHELL @@ -2398,24 +2406,10 @@ _LTECHO_EOF' file=\`\$ECHO \"\$file\" | $SED 's%^.*/%%'\` file=\`ls -ld \"\$thisdir/\$file\" | $SED -n 's/.*-> //p'\` done -" -} -# end: func_emit_wrapper_part1 - -# func_emit_wrapper_part2 [arg=no] -# -# Emit the second part of a libtool wrapper script on stdout. -# For more information, see the description associated with -# func_emit_wrapper(), below. -func_emit_wrapper_part2 () -{ -func_emit_wrapper_part2_arg1=${1-no} - - $ECHO "\ # Usually 'no', except on cygwin/mingw when embedded into # the cwrapper. - WRAPPER_SCRIPT_BELONGS_IN_OBJDIR=$func_emit_wrapper_part2_arg1 + WRAPPER_SCRIPT_BELONGS_IN_OBJDIR=$func_emit_wrapper_arg1 if test \"\$WRAPPER_SCRIPT_BELONGS_IN_OBJDIR\" = \"yes\"; then # special case for '.' if test \"\$thisdir\" = \".\"; then @@ -2532,30 +2526,6 @@ func_emit_wrapper_part2 () fi\ " } -# end: func_