Re: DESTDIR install on hppa-hpux
Hi Ralf, On Fri, 2009-06-12 at 21:57 +0200, Michael Haubenwallner wrote: > > > > Hmm. This does open a small security issue, no? > > > > That's precisely the reason we haven't gone this way > > before. > > Asking HP people (or more carefully reading the manpage) does help: The > linker does have the "+cdp" flag, which allows for changing the linktime > path of a library into something different being stored as fallback path > into the binary. It does even work on hpux10.20 (ld B.10.37 here) > although not mentioned in its manpage. Here's a patch that uses the +cdp linker flag to close the security issue with the fallback path encoded into the SOM binaries, by adding another libtool property 'fix_hardcoded_libdir_flag_spec', only used for hppa-hpux (32bit). It is configure-checked if compiler/linker do support this flag. This allows for hardcode_action=immediate and fast_install=yes, required for DESTDIR support. tests/deplibs-ident.at has to filter this flag, as it would lead to false positives. The same 12 tests as before are turned from SKIP/XFAIL to PASS on all the setups as before, with one exception: It is collect2 of gcc-3.0.1 on hppa-hpux10 here, which erroneously interprets -Wl,+cdp and fails to find libraries. So no tests do change their result in this setup. Thank you! /haubi/ diff --git a/libltdl/config/ltmain.m4sh b/libltdl/config/ltmain.m4sh index 6f44d35..f7d098d 100644 --- a/libltdl/config/ltmain.m4sh +++ b/libltdl/config/ltmain.m4sh @@ -3801,6 +3801,8 @@ func_mode_link () lib_search_path=`pwd` inst_prefix_dir= new_inherited_linker_flags= +fix_hardcoded_libdir_flag= +fix_hardcoded_libdir_flag_ld= avoid_version=no dlfiles= @@ -5436,6 +5438,15 @@ func_mode_link () elif test "$hardcode_shlibpath_var" = no; then add_shlibpath="$dir" add="-l$name" + elif test -n "$fix_hardcoded_libdir_flag_spec"; then + add_dir="-L${absdir}" + add="-l$name" + if test "${linkmode}" = prog && test "X${absdir}" != "X${libdir}"; then + linkdir=$absdir + eval "fix_hardcoded_libdir_flag=\"\${fix_hardcoded_libdir_flag} ${fix_hardcoded_libdir_flag_spec}\"" + # fix_hardcoded_libdir_flag_ld not needed, programs are linked with $CC + $lt_unset linkdir + fi else lib_linked=no fi @@ -5503,6 +5514,15 @@ func_mode_link () elif test "$hardcode_minus_L" = yes; then add_dir="-L$libdir" add="-l$name" + if test -n "$inst_prefix_dir" && + test -f "$inst_prefix_dir$libdir/$linklib" && + test -n "${fix_hardcoded_libdir_flag_spec}"; then + linkdir="$inst_prefix_dir$libdir" + add_dir="-L$linkdir" + eval "fix_hardcoded_libdir_flag=\"\${fix_hardcoded_libdir_flag} ${fix_hardcoded_libdir_flag_spec}\"" + eval "fix_hardcoded_libdir_flag_ld=\"\${fix_hardcoded_libdir_flag_ld} ${fix_hardcoded_libdir_flag_spec_ld}\"" + $lt_unset linkdir + fi elif test "$hardcode_shlibpath_var" = yes; then case :$finalize_shlibpath: in *":$libdir:"*) ;; diff --git a/libltdl/m4/libtool.m4 b/libltdl/m4/libtool.m4 index 5f24fab..9907f66 100644 --- a/libltdl/m4/libtool.m4 +++ b/libltdl/m4/libtool.m4 @@ -1905,6 +1905,7 @@ if test -n "$_LT_TAGVAR(hardcode_libdir_flag_spec, $1)" || # have to relink, otherwise we might link with an installed library # when we should be linking with a yet-to-be-installed one ## test "$_LT_TAGVAR(hardcode_shlibpath_var, $1)" != no && + test -z "$_LT_TAGVAR(fix_hardcoded_libdir_flag_spec, $1)" && test "$_LT_TAGVAR(hardcode_minus_L, $1)" != no; then # Linking always hardcodes the temporary library directory. _LT_TAGVAR(hardcode_action, $1)=relink @@ -4175,6 +4176,8 @@ m4_if([$1], [CXX], [ _LT_TAGVAR(hardcode_libdir_separator, $1)= _LT_TAGVAR(hardcode_minus_L, $1)=no _LT_TAGVAR(hardcode_shlibpath_var, $1)=unsupported + _LT_TAGVAR(fix_hardcoded_libdir_flag_spec, $1)= + _LT_TAGVAR(fix_hardcoded_libdir_flag_spec_ld, $1)= _LT_TAGVAR(inherit_rpath, $1)=no _LT_TAGVAR(link_all_deplibs, $1)=unknown _LT_TAGVAR(module_cmds, $1)= @@ -4758,13 +4761,12 @@ _LT_EOF hpux10*) if test "$GCC" = yes && test "$with_gnu_ld" = no; then - _LT_TAGVAR(archive_cmds, $1)='$CC -shared -fPIC ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -fPIC ${wl}+h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags $fix_hardcoded_libdir_flag' else - _LT_TAGVAR(archive_cmds, $1)='$LD -b +h $soname +b $install_libdir -o $lib $libobjs $deplibs $linker_flags' + _LT_TAGVAR(archive_cmds, $1)='$LD -b +h $soname -o $lib $libobjs $deplibs $linker_flags $fix_hardcoded_libdir_flag_ld' fi if test "$with_gnu_ld" = no; then - _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir' - _LT_TAGVAR(hardcode_libdir_flag_spec_ld, $1)='+b $libdir' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir $fix_hardcoded_libdir_flag' _LT_TAGVAR(h
[PATCH] Ensure LT_PATH_LD works when called before LT_INIT
* libltdl/m4/libtool.m4 (LT_PATH_LD): AC_REQUIRE _LT_PROG_ECHO_BACKSLASH. Original patch by Yaakov Selkowitz. As he explained: > > There's a bug in LT_PATH_LD (AC_PROG_LD) when called prior to LT_INIT > (AC_PROG_LIBTOOL): > > checking for ld used by gcc... > /usr/lib/gcc/i686-pc-cygwin/4.3.2/../../../../i686-pc-cygwin/bin/ld: no input > files > ./configure: line 3955: : command not found > > Yet this does not occur when the same macro is run by LT_INIT. > > Here's the offending hunk: > > # Canonicalize the pathname of ld > ac_prog=`$ECHO "$ac_prog"| $SED 's%%/%g'` > while $ECHO "$ac_prog" | $GREP "$re_direlt" > /dev/null 2>&1; do > ac_prog=`$ECHO $ac_prog| $SED "s%$re_direlt%/%"` > done > > The problem is that $ECHO hasn't been defined yet. This is done by > _LT_PROG_ECHO_BACKSLASH, which is called at the beginning of LT_INIT, but > isn't > an explicit requirement of LT_PATH_LD, which may be called on its own. > (AFAICS, all other macros which use $ECHO are libtool-internal and would only > be called after LT_INIT.) While it is not typical for LT_* functions to be called before LT_INIT, this can happen in this case because when libtool is in use, AC_PROG_LD is AU_DEFUN'ed to _LT_PATH_LD. And it is certainly ok for AC_PROG_LD to be called before LT_INIT or AC_PROG_LIBTOOL (as AC_PROG_LIBTOOL is AU_DEFUN'ed to LT_INIT). So, it /ought/ to work, but it doesn't. This patch seems like an obvious fix to me. Ok to push? --- libltdl/m4/libtool.m4 |1 + 1 files changed, 1 insertions(+), 0 deletions(-) diff --git a/libltdl/m4/libtool.m4 b/libltdl/m4/libtool.m4 index 5f24fab..6beb125 100644 --- a/libltdl/m4/libtool.m4 +++ b/libltdl/m4/libtool.m4 @@ -2772,6 +2772,7 @@ AC_REQUIRE([AC_CANONICAL_HOST])dnl AC_REQUIRE([AC_CANONICAL_BUILD])dnl m4_require([_LT_DECL_SED])dnl m4_require([_LT_DECL_EGREP])dnl +m4_require([_LT_PROG_ECHO_BACKSLASH])dnl AC_ARG_WITH([gnu-ld], [AS_HELP_STRING([--with-gnu-ld], -- 1.6.3.1
[PATCH] [cygwin|mingw] fix dlpreopen with --disable-static take 6
* libltdl/config/general.m4sh: Update copyright year. (func_tr_sh): New function. * libltdl/config/ltmain.m4sh (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 $sharedlib_from_linklib_cmd 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. (func_win32_libid): Accomodate pei-i386 import libs as well as pe-i386. (func_cygming_dll_for_implib): New function. (func_cygming_dll_for_implib_fallback): New function. (func_cygming_dll_for_implib_fallback_core): New function. (func_cygming_gnu_implib_p): New function. (func_cygming_ms_implib_p): New function. * libltdl/m4/libtool.m4 (_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. (_LT_CHECK_SHAREDLIB_FROM_LINKLIB): New macro sets sharedlib_from_linklib_cmd variable. (_LT_DECL_DLLTOOL): New macro ensures DLLTOOL is always set. --- Reposted without change from -take5, here: http://lists.gnu.org/archive/html/libtool-patches/2009-01/msg00232.html This patch has been in use in the cygwin distribution since 2009-02-20. libltdl/config/general.m4sh | 19 - libltdl/config/ltmain.m4sh | 226 +++ libltdl/m4/libtool.m4 | 62 +++- 3 files changed, 282 insertions(+), 25 deletions(-) diff --git a/libltdl/config/general.m4sh b/libltdl/config/general.m4sh index 4bc304c..e839070 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,22 @@ 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. All characters +# not in the set a-zA-Z0-9_ are replaced with '_'. Further, +# if $1 begins with a digit, a '_' is prepended as well. +func_tr_sh () +{ + case "$1" in + [0-9]* | *[!a-zA-Z0-9_]*) +func_tr_sh_result=`$ECHO "$1" | $SED 's/^\([0-9]\)/_\1/; s/[^a-zA-Z0-9_]/_/g'` +;; + * ) +func_tr_sh_result=$1 +;; + esac +} ]]) diff --git a/libltdl/config/ltmain.m4sh b/libltdl/config/ltmain.m4sh index 6f44d35..9353376 100644 --- a/libltdl/config/ltmain.m4sh +++ b/libltdl/config/ltmain.m4sh @@ -2007,10 +2007,49 @@ 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* | *cegcc* ) + # if an import library, we need to obtain dlname + if func_win32_import_lib_p "$dlprefile"; then + func_tr_sh "$dlprefile" + eval "curr_lafile=\$libfile_$func_tr_sh_result" + dlprefile_dlbasename="" + if test -n "$curr_lafile" && func_lalib_p "$curr_lafile"; then + # Use subshell, to avoid clobbering current variable values + dlprefile_dlname=`source "$curr_lafile" && echo "$dlname"` + if test -n "$dlprefile_dlname" ; then + func_basename "$dlprefile_dlname" + dlprefile_dlbasename="$func_basename_result" + else + # no lafile. user explicitly requested -dlpreopen . + eval '$sharedlib_from_linklib "$dlprefile"' + dlprefile_dlbasename=$sharedlib_from_linklib_result + fi + fi + $opt_dry_run || { + if test -n "$dlprefile_dlbasename" ; then + eval '$ECHO ": $dlprefile_dlbasename" >> "$nlist"' + else + func_warning "Could not compute DLL name from $name" + eval '$ECHO ": $name " >> "$nl
[PATCH] Document and test LT_DEBUGWRAPPER cwrapper macro
* tests/cwrapper.test: Add new test for -DLT_DEBUGWRAPPER. * doc/libtool.texi [Linking executables]: Mention wrapper executables, in addition to wrapper scripts. Add menu referencing subsection 'Wrapper executables for programs'. [Wrapper executables for programs]: New subsection. Documents cwrapper rationale, command line options, and LT_DEBUGWRAPPER macro. --- A repost of this patch: http://lists.gnu.org/archive/html/libtool-patches/2009-01/msg00168.html FWIW, I plan to expand on the [Wrapper executables for programs] documentation after (assuming) the cross-compile stuff goes in. Now there has been some reluctance about this patch in the past; presumably worry about documenting the --lt- options somehow cements them as an API that must be forever supported (and also perhaps because the wrapper *script* doesn't support these options, so why have arg differences between the two wrapper implementations?) 1) remove all of those bits from the documentation 2) only document the --lt-dump-script option 3) remove all those bits, AND remove their implementation a) might be troublesome as --lt-dump-script is quite useful, AND we still use it explicitly within libtool 4) only document the --lt-dump-script-option, AND remove the implementations of the other --lt- options. 5) Add a blurb to the documentation that "--lt- options to the cwrapper are unstable and subject to change". 6) Add all --lt-* "implementations" to the wrapper script 7) Add --lt-dump-script "implementation" to the wrapper script If changes to this patch must be made, then I lean towards #2 or #5. #4 might also be ok, since those functions haven't proven useful over the past year, plus it would shrink the size of ltmain.sh quite a bit. doc/libtool.texi | 96 +++- tests/cwrapper.at | 31 + 2 files changed, 125 insertions(+), 2 deletions(-) diff --git a/doc/libtool.texi b/doc/libtool.texi index a7872c6..738257a 100644 --- a/doc/libtool.texi +++ b/doc/libtool.texi @@ -790,8 +790,9 @@ Note that libtool added the necessary run-time path flag, as well as @cindex wrapper scripts for programs @cindex program wrapper scripts Notice that the executable, @code{hell}, was actually created in the -...@file{@value{objdir}} subdirectory. Then, a wrapper script was created -in the current directory. +...@file{@value{objdir}} subdirectory. Then, a wrapper script (or, on +certain platforms, a wrapper executable @pxref{Wrapper executables}) was +created in the current directory. Since libtool created a wrapper script, you should use libtool to install it and debug it too. However, since the program does not depend @@ -845,6 +846,97 @@ price of being dynamic is eight kilobytes, and the payoff is about four kilobytes. So, having a shared @file{libhello} won't be an advantage until we link it against at least a few more programs. +...@menu +* Wrapper executables:: Wrapper executables for certain platforms. +...@end menu + +...@node Wrapper executables +...@subsection Wrapper executables for programs +...@cindex wrapper executables for programs +...@cindex program wrapper executables + +Some platforms, notably those hosted on win32 such as cygwin +and mingw, use a wrapper executable rather than a wrapper script. It +performs the same function, but is necessary so that @code{make} +rules for target executables (whose names end in @code{$(EXEEXT)}) +are satisfied. Recall that the actual target executable is created +in @value{objdir} as @co...@value{objdir}/program_name.exe} on +these platforms. If a wrapper script were used, then the build +directory would contain @code{program_name}, @emph{not} @code{program_name.exe}. +Thus, @code{make} would never believe that the target executable had +been created, leading to continual and useless relinking. (We could +name the wrapper script @code{program_name.exe} on these platforms, but it +is not a good idea to lie to win32 in this way). + +Therefore, these platforms use a wrapper executable to set various +environment values so that the target executable may locate its +shared libraries. The wrapper executable then launches the target +executable using a (possibly $host-dependent) function, such as +exec() or _spawn(). + +Note that the wrapper executable, like the target executable, is a +$host program, not a $build program. Therefore, the path to the +target executable must be expressed in the native format of the +$host, not that of $build. Similarly, the environment variable +values --- and even the name of the specific environment variables +to adjust --- are $host-specific and should be in $host, not $build, +format. For this reason, libtool contains a number of path and +pathlist conversion functions for various $host/$build combinations, +where $host is one of those platforms where a wrapper executable is +needed. + +Obviously, the wrapper executable itself is quite complex (more so
[PATCH] [cygwin]: Add cross-compile support to cwrapper take 5
* libltdl/config/general.m4sh: Update copyright year. (func_tr_sh): New function. * libltdl/config/ltmain.m4sh (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 $sharedlib_from_linklib_cmd 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. (func_win32_libid): Accomodate pei-i386 import libs as well as pe-i386. (func_cygming_dll_for_implib): New function. (func_cygming_dll_for_implib_fallback): New function. (func_cygming_dll_for_implib_fallback_core): New function. (func_cygming_gnu_implib_p): New function. (func_cygming_ms_implib_p): New function. * libltdl/m4/libtool.m4 (_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. (_LT_CHECK_SHAREDLIB_FROM_LINKLIB): New macro sets sharedlib_from_linklib_cmd variable. (_LT_DECL_DLLTOOL): New macro ensures DLLTOOL is always set. -- This is a repost of the "take 4" patch originally posted here: http://lists.gnu.org/archive/html/libtool-patches/2009-01/msg00232.html This patch has been in use in the cygwin distribution since 2009-02-20. I've rewritten the original "patch notes" from -take1...-take4, so that a more coherent story can be told, for folks just joining this thread or who have forgotten all the surrounding context... Another good summary (if I do say so myself) of the problem, and history, that the attached patch addresses can be found here: [CFT] libtool on nix->cygwin cross, with wine http://www.cygwin.com/ml/cygwin/2009-02/msg00555.html (Ignore the rest of the thread; there was not a single on-topic reply.) Definition: "works", or "for the cwrapper to work properly" in this context means that you can, from the $build environment, execute the cwrapper program, and eventually the actual target executable will be successfully launched. In all known cases involving the cwrapper (e.g $host is win32-related -- except maybe cegcc but that's another issue), *compiling* in a cross environment with those $hosts always works just fine. It's launching the uninstalled target executables that is at issue throughout this post. Unix -> mingw cross builds need special support when creating the cwrapper source code in order for the cwrapper to work properly under the wine environment. This was originally described here: http://lists.gnu.org/archive/html/libtool-patches/2008-04/msg00164.html (that patch is already part of libtool, in a modified form). However, the full explanation is: 1) On win32 $host we need an executable wrapper, rather than the normal shell script wrapper, for dynamically linked executables. This is because the automake rules' target is foo$(EXEEXT). a) it is a bad idea to lie to win32 OS by naming a file that is NOT a PE/COFF executable "foo.exe" so we can't just rename foo (the shell script) as foo.exe. So, because we need to support native builds on cygwin, mingw, and friends, we have to care about this case, and not simply emit the shell wrapper as foo$(EXEEXT). 2) We have long had this cwrapper. It used to coexist in the same directory with the shell script wrapper. The cwrapper would exec the shell wrapper, which did all the work, and then launched the actual target. a) This doesn't work for cygwin-1.5 where CYGWIN variable contains the flag "transparent_exe". Since "transparent_exe" is now the default behavior for cygwin-1.7 (due to be released within 2 wks) this foo + foo.exe in same directory will very shortly be broken. b) So, a year or so ago, the cwrapper was modified to do all the work itself (setting PATH/LD_LIBRARY_PATH, etc), and to directly invoke the target. Similarly, libtool no longer creates the shell wrapper with the target's name (there is still a shell wrapper on these $hosts, but it goes in .libs/ and is named ltshwrapper_foo. This was the original goal, anyway, because it's just kinda silly to have two levels of wrappers to get to the target exe. c) One wrinkle: the cwrapper is a $host executable, not a $build one. So, for instance when $host=$min
Re: [PATCH] [cygwin]: Add cross-compile support to cwrapper take 5
Charles Wilson wrote: ... a long correct message but with the wrong changelog. sorry. Here's the correct changelog. - Refactor cwrapper cross-compile support; Add cygwin. * libltdl/m4/libtool.m4 (_LT_PATH_CONVERSION_FUNCTIONS): New function sets libtool variable $to_host_path_cmd, and employs cache. AC_SUBSTs $to_host_path_cmd, as well. (_LT_SETUP): Require it. * tests/testsuite.at: Ensure to_host_path_cmd is passed as a variable setting on the configure line for (new testsuite) tests. * Makefile.am: Ensure to_host_path_cmd is included in TEST_ENVIRONMENT so that it is passed to (old testsuite) tests. * libltdl/config/ltmain.m4sh (func_cygpath): New function. (func_init_to_host_pathlist_cmd): New function. (func_to_host_path): Refactored to... (now uses eval $to_host_path_cmd). (func_wine_to_win32_path): Here. New function. (func_msys_to_win32): Here. New function. (func_path_convert_check): Here. New function. (func_noop_path_convert): Here. New function. (func_msys_to_mingw_path_convert): Here. New function. (func_cygwin_to_mingw_path_convert): Here. New function. (func_nix_to_mingw_path_convert): Here. New function. (func_msys_to_cygwin_path_convert): New function. (func_nix_to_cygwin_path_convert): New function. (func_to_host_pathlist): Refactored to... (now uses eval $to_host_pathlist_cmd and func_init_to_host_pathlist_cmd). (func_pathlist_convert_check): Here. New function. (func_pathlist_front_back_pathsep): Here. New function. (func_wine_to_win32_pathlist): Here. New function. (func_noop_pathlist_convert): Here. New function. (func_msys_to_mingw_pathlist_convert): Here. New function. (func_cygwin_to_mingw_pathlist_convert): Here. New function. (func_nix_to_mingw_pathlist_convert): Here. New function. (func_msys_to_cygwin_pathlist_convert): New function. (func_nix_to_cygwin_pathlist_convert): New function.