[ gcc-patches: OK to pull the libtool.m4 bits over to the GCC tree once they are applied upstream? ]
GCC places special requirements on Libtool macros: it may be in the situation where compile tests work but link tests don't. This means the macros should either avoid link tests where possible, or otherwise allow for a cache variable override. See this thread for more info: <http://thread.gmane.org/gmane.comp.gcc.devel/102579> Also, the shlibpath_overrides_runpath test (which is executed on Linux only, in order to catch the binutils change to set DT_RUNPATH enabled by some distributions) is currently run once per language. This means both unnecessary work, and that the last language wins. The latter is an unfortunate choice esp. for GCC: the C compiler is typically less of a problem than, say, $CXX, or even $GCJ (we fixed the latter case back in February by not calling _LT_SYS_DYNAMIC_LINKER for GCX; see link below). Using only one cache variable helps to choose the first test result consistently. It should be sufficiently flexible to require that all linkers invoked by the various compilers used behave similarly in this regard (and anyway that would not be a regression over current behavior). Wrt. the archive_cmds_need_lc tests, I think using one data per compiler is necessary. Note that Autoconf has AC_NO_EXECUTABLES which is similar to GCC_NO_EXECUTABLES, so we can just use the former in Libtool's testsuite. As it happens, this should also fix <http://thread.gmane.org/gmane.comp.sysutils.autotools.announce/105/focus=8959> for good. (The extra _LT_SYS_DYNAMIC_LINKER($1) calls should still be removed one day, but only after a careful audit.) The shlibpath_overrides_runpath test uses silent AC_CACHE_VAL rather than AC_CACHE_CHECK because that would cause munged output: | checking dynamic linker characteristics... checking whether LD_LIBRARY_PATH overrides the run path... (cached) no | GNU/Linux ld.so OK to apply? FWIW, the new test isn't a particularly strong one, but I don't know how to easily write a better one. FWIW2, the old thread cited above also mentions a patch to remove the _LT_SYS_DYNAMIC_LINKER call for all languages other than C. I'm not sure this is safe yet, though. And even if it were, using cache variables are independently a move in the right direction anyway. Since the libtool.m4 change mostly consists of changed indentation, here is the diff -w FYI: | --- a/libltdl/m4/libtool.m4 | +++ b/libltdl/m4/libtool.m4 | @@ -2389,16 +2389,21 @@ linux* | k*bsd*-gnu) | finish_cmds='PATH="\$PATH:/sbin" ldconfig -n $libdir' | shlibpath_var=LD_LIBRARY_PATH | shlibpath_overrides_runpath=no | + | # Some binutils ld are patched to set DT_RUNPATH | + AC_CACHE_VAL([lt_cv_shlibpath_overrides_runpath], | + [lt_cv_shlibpath_overrides_runpath=no | save_LDFLAGS=$LDFLAGS | save_libdir=$libdir | eval "libdir=/foo; wl=\"$_LT_TAGVAR(lt_prog_compiler_wl, $1)\"; \ | LDFLAGS=\"\$LDFLAGS $_LT_TAGVAR(hardcode_libdir_flag_spec, $1)\"" | AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])], | [AS_IF([ ($OBJDUMP -p conftest$ac_exeext) 2>/dev/null | grep "RUNPATH.*$libdir" >/dev/null], | - [shlibpath_overrides_runpath=yes])]) | + [lt_cv_shlibpath_overrides_runpath=yes])]) | LDFLAGS=$save_LDFLAGS | libdir=$save_libdir | + ]) | + shlibpath_overrides_runpath=$lt_cv_shlibpath_overrides_runpath | | # This implies no fast_install, which is unacceptable. | # Some rework will be needed to allow for fast_install | @@ -5055,8 +5060,9 @@ x|xyes) | # Test whether the compiler implicitly links with -lc since on some | # systems, -lgcc has to come before -lc. If gcc already passes -lc | # to ld, don't add -lc before -lgcc. | - AC_MSG_CHECKING([whether -lc should be explicitly linked in]) | - $RM conftest* | + AC_CACHE_CHECK([whether -lc should be explicitly linked in], | + [lt_cv_]_LT_TAGVAR(archive_cmds_need_lc, $1), | + [$RM conftest* | echo "$lt_simple_compile_test_code" > conftest.$ac_ext | | if AC_TRY_EVAL(ac_compile) 2>conftest.err; then | @@ -5075,16 +5081,17 @@ x|xyes) | _LT_TAGVAR(allow_undefined_flag, $1)= | if AC_TRY_EVAL(_LT_TAGVAR(archive_cmds, $1) 2\>\&1 \| $GREP \" -lc \" \>/dev/null 2\>\&1) | then | - _LT_TAGVAR(archive_cmds_need_lc, $1)=no | + lt_cv_[]_LT_TAGVAR(archive_cmds_need_lc, $1)=no | else | - _LT_TAGVAR(archive_cmds_need_lc, $1)=yes | + lt_cv_[]_LT_TAGVAR(archive_cmds_need_lc, $1)=yes | fi | _LT_TAGVAR(allow_undefined_flag, $1)=$lt_save_allow_undefined_flag | else | cat conftest.err 1>&5 | fi | $RM conftest* | - AC_MSG_RESULT([$_LT_TAGVAR(archive_cmds_need_lc, $1)]) | + ]) | + _LT_TAGVAR(archive_cmds_need_lc, $1)=$lt_cv_[]_LT_TAGVAR(archive_cmds_need_lc, $1) | ;; | esac | fi Thanks, Ralf 2008-12-13 Ralf Wildenhues <[email protected]> Add cache variables to link tests. * libltdl/m4/libtool.m4 (_LT_SYS_DYNAMIC_LINKER) (_LT_LINKER_SHLIBS): Add cache variables to tests that require the linker to work. For shlibpath_overrides_runpath, this also changes the semantics to let the result from the C compiler take precedence. * tests/no-executables.at (AC_NO_EXECUTABLES): New file. * Makefile.am: Update. * NEWS: Update. Report of shlibpath_overrides_runpath issue by Mike Frysinger, report of GCC issue by Andreas Schwab. diff --git a/Makefile.am b/Makefile.am index 98feed4..86224e1 100644 --- a/Makefile.am +++ b/Makefile.am @@ -483,6 +483,7 @@ TESTSUITE_AT = tests/testsuite.at \ tests/template.at \ tests/ctor.at \ tests/early-libtool.at \ + tests/no-executables.at \ tests/deplibs-ident.at \ tests/configure-iface.at \ tests/stresstest.at \ diff --git a/NEWS b/NEWS index 8927d23..9550e5b 100644 --- a/NEWS +++ b/NEWS @@ -24,6 +24,8 @@ New in 2.2.8 2008-??-??: git version 2.2.7a, Libtool team: - libtool command line flag --verbose now also enables explicit verbose output, in addition to its previous behavior of (re)enabling only the default informational output. See New Features, --no-silent. + - Link tests are guarded by cache variables so they can be avoided for + bootstrapping purposes (e.g., when link tests are not possible). * Miscellaneous changes: diff --git a/libltdl/m4/libtool.m4 b/libltdl/m4/libtool.m4 index 3fa0688..b7b566d 100644 --- a/libltdl/m4/libtool.m4 +++ b/libltdl/m4/libtool.m4 @@ -2389,16 +2389,21 @@ linux* | k*bsd*-gnu) finish_cmds='PATH="\$PATH:/sbin" ldconfig -n $libdir' shlibpath_var=LD_LIBRARY_PATH shlibpath_overrides_runpath=no + # Some binutils ld are patched to set DT_RUNPATH - save_LDFLAGS=$LDFLAGS - save_libdir=$libdir - eval "libdir=/foo; wl=\"$_LT_TAGVAR(lt_prog_compiler_wl, $1)\"; \ - LDFLAGS=\"\$LDFLAGS $_LT_TAGVAR(hardcode_libdir_flag_spec, $1)\"" - AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])], - [AS_IF([ ($OBJDUMP -p conftest$ac_exeext) 2>/dev/null | grep "RUNPATH.*$libdir" >/dev/null], - [shlibpath_overrides_runpath=yes])]) - LDFLAGS=$save_LDFLAGS - libdir=$save_libdir + AC_CACHE_VAL([lt_cv_shlibpath_overrides_runpath], + [lt_cv_shlibpath_overrides_runpath=no + save_LDFLAGS=$LDFLAGS + save_libdir=$libdir + eval "libdir=/foo; wl=\"$_LT_TAGVAR(lt_prog_compiler_wl, $1)\"; \ + LDFLAGS=\"\$LDFLAGS $_LT_TAGVAR(hardcode_libdir_flag_spec, $1)\"" + AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])], + [AS_IF([ ($OBJDUMP -p conftest$ac_exeext) 2>/dev/null | grep "RUNPATH.*$libdir" >/dev/null], + [lt_cv_shlibpath_overrides_runpath=yes])]) + LDFLAGS=$save_LDFLAGS + libdir=$save_libdir + ]) + shlibpath_overrides_runpath=$lt_cv_shlibpath_overrides_runpath # This implies no fast_install, which is unacceptable. # Some rework will be needed to allow for fast_install @@ -5055,36 +5060,38 @@ x|xyes) # Test whether the compiler implicitly links with -lc since on some # systems, -lgcc has to come before -lc. If gcc already passes -lc # to ld, don't add -lc before -lgcc. - AC_MSG_CHECKING([whether -lc should be explicitly linked in]) - $RM conftest* - echo "$lt_simple_compile_test_code" > conftest.$ac_ext - - if AC_TRY_EVAL(ac_compile) 2>conftest.err; then - soname=conftest - lib=conftest - libobjs=conftest.$ac_objext - deplibs= - wl=$_LT_TAGVAR(lt_prog_compiler_wl, $1) - pic_flag=$_LT_TAGVAR(lt_prog_compiler_pic, $1) - compiler_flags=-v - linker_flags=-v - verstring= - output_objdir=. - libname=conftest - lt_save_allow_undefined_flag=$_LT_TAGVAR(allow_undefined_flag, $1) - _LT_TAGVAR(allow_undefined_flag, $1)= - if AC_TRY_EVAL(_LT_TAGVAR(archive_cmds, $1) 2\>\&1 \| $GREP \" -lc \" \>/dev/null 2\>\&1) - then - _LT_TAGVAR(archive_cmds_need_lc, $1)=no - else - _LT_TAGVAR(archive_cmds_need_lc, $1)=yes - fi - _LT_TAGVAR(allow_undefined_flag, $1)=$lt_save_allow_undefined_flag - else - cat conftest.err 1>&5 - fi - $RM conftest* - AC_MSG_RESULT([$_LT_TAGVAR(archive_cmds_need_lc, $1)]) + AC_CACHE_CHECK([whether -lc should be explicitly linked in], + [lt_cv_]_LT_TAGVAR(archive_cmds_need_lc, $1), + [$RM conftest* + echo "$lt_simple_compile_test_code" > conftest.$ac_ext + + if AC_TRY_EVAL(ac_compile) 2>conftest.err; then + soname=conftest + lib=conftest + libobjs=conftest.$ac_objext + deplibs= + wl=$_LT_TAGVAR(lt_prog_compiler_wl, $1) + pic_flag=$_LT_TAGVAR(lt_prog_compiler_pic, $1) + compiler_flags=-v + linker_flags=-v + verstring= + output_objdir=. + libname=conftest + lt_save_allow_undefined_flag=$_LT_TAGVAR(allow_undefined_flag, $1) + _LT_TAGVAR(allow_undefined_flag, $1)= + if AC_TRY_EVAL(_LT_TAGVAR(archive_cmds, $1) 2\>\&1 \| $GREP \" -lc \" \>/dev/null 2\>\&1) + then + lt_cv_[]_LT_TAGVAR(archive_cmds_need_lc, $1)=no + else + lt_cv_[]_LT_TAGVAR(archive_cmds_need_lc, $1)=yes + fi + _LT_TAGVAR(allow_undefined_flag, $1)=$lt_save_allow_undefined_flag + else + cat conftest.err 1>&5 + fi + $RM conftest* + ]) + _LT_TAGVAR(archive_cmds_need_lc, $1)=$lt_cv_[]_LT_TAGVAR(archive_cmds_need_lc, $1) ;; esac fi diff --git a/tests/no-executables.at b/tests/no-executables.at new file mode 100644 index 0000000..e9e229a --- /dev/null +++ b/tests/no-executables.at @@ -0,0 +1,78 @@ +# no-executables.at -- Libtool usage in GCC -*- Autotest -*- + +# Copyright (C) 2008 Free Software Foundation, Inc. +# Written by Ralf Wildenhues, 2008 +# +# This file is part of GNU Libtool. +# +# GNU Libtool is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 2 of +# the License, or (at your option) any later version. +# +# GNU Libtool is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Libtool; see the file COPYING. If not, a copy +# can be downloaded from http://www.gnu.org/licenses/gpl.html, +# or obtained by writing to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +#### + +AT_BANNER([Libtool usage in GCC]) +AT_SETUP([AC_NO_EXECUTABLES]) + +mkdir m4 + +AT_DATA([configure.ac], +[[AC_INIT([no-exec], [1]) +AC_CONFIG_MACRO_DIR([m4]) + +# We punt a bit here, to get the results of AC_PROG_CC +# (and allow it to do link tests) but still error out on +# link tests within Libtool macros. +LDFLAGS=-lnosuchlibrary +AC_NO_EXECUTABLES +AC_PROG_CC +AC_PROG_CXX +AC_PROG_F77 +AC_PROG_FC +AM_PROG_GCJ + +# Consequently, we have to set cache variables for each link +# test we may need. For the purposes of this test, it shouldn't +# matter much whether these values are actually wrong, the point +# is that the linker should never be invoked. + +lt_cv_shlibpath_overrides_runpath=no +lt_cv_archive_cmds_need_lc=no +lt_cv_cc_needs_belf=no +lt_cv_ld_exported_symbols_list=no +lt_cv_prog_compiler_static_works=no + +# Deal with AC_LIBTOOL_DLOPEN in one of two possible ways: +# - do not execute it at all in the ac_no_link case +# - preset the individual Autoconf test variables + +if ${test_ac_libtool_dlopen-false}; then + ac_cv_func_shl_load=no + ac_cv_lib_dld_shl_load=no + ac_cv_func_dlopen=no + ac_cv_lib_dl_dlopen=no + ac_cv_lib_svld_dlopen=no + ac_cv_lib_dld_dld_link=no + AC_LIBTOOL_DLOPEN +fi +AC_PROG_LIBTOOL + +AC_OUTPUT +]]) + +LT_AT_BOOTSTRAP([--install], [-I m4], [ignore], [ignore], [], [ignore], [ignore]) +LT_AT_CONFIGURE([]) +LT_AT_CONFIGURE([test_ac_libtool_dlopen=:]) + +AT_CLEANUP
