From patchwork Wed Jan 22 15:39:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 1227349 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-518032-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=embecosm.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha1 header.s=default header.b=NM/XMP2/; dkim=pass (2048-bit key; unprotected) header.d=embecosm.com header.i=@embecosm.com header.a=rsa-sha256 header.s=google header.b=O5rTCfSt; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 482qMl0xJfz9sRG for ; Thu, 23 Jan 2020 02:39:29 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id; q=dns; s=default; b=u8TV9ymDqCg2 5BgZUqVc1JtQT+gcEY5H/FryU32kcrPH8X63vjDrqGelaipUJqDCQ2PJypHhleDt SrQLc8b7R7cQVPXtANgcqS23kudVHIcS8jQfSnDerSZy3KYzwM2i5Sjfq7jsdymg raz2MTFdJNgl9sSiE7uAYtnA8N3E5Kk= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id; s=default; bh=GOCZN3VrSHhxuCOxUy eD4sJkAhI=; b=NM/XMP2/ZAvHeeTSx0HneAnQC6vbe4VO5uzGUjNa8SQsu+ZsAe eVGdz+Fz53DdnN+CUgiSfdpDgiQhL6J/BVe24/y3lcP1WBR5TszToO6FF4i6jQNT hz4fT2PphzmDwFj1pQsXIQPGebXOGcPr9WzG1pZ2UiQvzCoj0wp6Dwd0I= Received: (qmail 98941 invoked by alias); 22 Jan 2020 15:39:21 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 98930 invoked by uid 89); 22 Jan 2020 15:39:20 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-21.3 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=H*MI:andrew, H*m:andrew, harder X-HELO: mail-wr1-f67.google.com Received: from mail-wr1-f67.google.com (HELO mail-wr1-f67.google.com) (209.85.221.67) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 22 Jan 2020 15:39:17 +0000 Received: by mail-wr1-f67.google.com with SMTP id z3so7815258wru.3 for ; Wed, 22 Jan 2020 07:39:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=from:to:cc:subject:date:message-id; bh=1eBBd51f52dN+MYiOT7GfFDFEekrR8DCN48RfXkCG9I=; b=O5rTCfSt8Hg8HL+JofWWkjSHRMw8qnCamo9uKzWmry/Hqk6tWLzueRHu7oSnZVl7d8 JhmE/uHrWlQP671v6+VZXfncDkgT0xZRcx7Ryc5R19RLMeQTNkp/bCKZCRUOdjYffVZg W1lnOKHTuxwUzcYBl2zhUmVg/7tDcOBz2/OPe8BbObYvx6Lgl+4jWl9luIBvdVk5JTY4 nqDnIkhGeJs5cHSusbXY7/AxjB+jswAhVt/4uqwyCeO7QtuOD8QNXNLVeYiEiEiPxBTh Q11B+MBmb4uWWEA74EV2JwlWv7Tmfv+1ZNeRuc0NyoqBYRtfH1T0d+YlGDwQRiVhCVam hj3g== Received: from localhost (host86-191-239-73.range86-191.btcentralplus.com. [86.191.239.73]) by smtp.gmail.com with ESMTPSA id u18sm57514895wrt.26.2020.01.22.07.39.13 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 22 Jan 2020 07:39:13 -0800 (PST) From: Andrew Burgess To: gcc-patches@gcc.gnu.org Cc: richard.bunt@arm.com, Andrew Burgess Subject: [PATCH] gcc: Add new configure options to allow static libraries to be selected Date: Wed, 22 Jan 2020 15:39:11 +0000 Message-Id: <20200122153911.21270-1-andrew.burgess@embecosm.com> X-IsSubscribed: yes The motivation behind this change is to make it easier for a user to link against static libraries on a target where dynamic libraries are the default library type (for example GNU/Linux). Further, my motivation is really for linking libraries into GDB, however, the binutils-gdb/config/ directory is a copy of gcc/config/ so changes for GDB need to be approved by the GCC project first. After making this change in the gcc/config/ directory I've run autoreconf on all of the configure scripts in the GCC tree and a couple have been updated, so I'll use one of these to describe what my change does. Consider libcpp, this library links against libiconv. Currently if the user builds on a system with both static and dynamic libiconv installed then autotools will pick up the dynamic libiconv by default. This is almost certainly the right thing to do. However, if the user wants to link against static libiconv then things are a little harder, they could remove the dynamic libiconv from their system, but this is probably a bad idea (other things might depend on that library), or the user can build their own version of libiconv, install it into a unique prefix, and then configure gcc using the --with-libiconv-prefix=DIR flag. This works fine, but is somewhat annoying, the static library available, I just can't get autotools to use it. My change then adds a new flag --with-libiconv-type=TYPE, where type is either auto, static, or shared. The default auto, ensures we keep the existing behaviour unchanged. If the user configures with --with-libiconv-type=static then the configure script will ignore any dynamic libiconv it finds, and will only look for a static libiconv, if no static libiconv is found then the configure will continue as though there is no libiconv at all available. Similarly a user can specify --with-libiconv-type=shared and force the use of shared libiconv, any static libiconv will be ignored. As I've implemented this change within the AC_LIB_LINKFLAGS_BODY macro then only libraries configured using the AC_LIB_LINKFLAGS or AC_LIB_HAVE_LINKFLAGS macros will gain the new configure flag. If this is accepted into GCC then there will be follow on patches for binutils and GDB to regenerate some configure scripts in those projects. For GCC only two configure scripts needed updated after this commit, libcpp and libstdc++-v3, both of which link against libiconv. config/ChangeLog: * lib-link.m4 (AC_LIB_LINKFLAGS_BODY): Add new --with-libXXX-type=... option. Use this to guide the selection of either a shared library or a static library. libcpp/ChangeLog: * configure: Regnerate. libstdc++-v3/ChangeLog: * configure: Regnerate. --- config/ChangeLog | 6 ++++++ config/lib-link.m4 | 22 ++++++++++++++++------ libcpp/ChangeLog | 4 ++++ libcpp/configure | 29 +++++++++++++++++++++++------ libstdc++-v3/ChangeLog | 4 ++++ libstdc++-v3/configure | 47 ++++++++++++++++++++++++++++++++--------------- 6 files changed, 85 insertions(+), 27 deletions(-) diff --git a/config/lib-link.m4 b/config/lib-link.m4 index eeb200d266d..662192e0a07 100644 --- a/config/lib-link.m4 +++ b/config/lib-link.m4 @@ -150,6 +150,11 @@ AC_DEFUN([AC_LIB_LINKFLAGS_BODY], fi fi ]) + AC_LIB_ARG_WITH([lib$1-type], +[ --with-lib$1-type=TYPE type of library to search for (auto/static/shared) ], + [ with_lib$1_type=$withval ], [ with_lib$1_type=auto ]) + lib_type=`eval echo \$with_lib$1_type` + dnl Search the library and its dependencies in $additional_libdir and dnl $LDFLAGS. Using breadth-first-seach. LIB[]NAME= @@ -195,13 +200,13 @@ AC_DEFUN([AC_LIB_LINKFLAGS_BODY], found_so= found_a= if test $use_additional = yes; then - if test -n "$shlibext" && test -f "$additional_libdir/lib$name.$shlibext"; then + if test -n "$shlibext" && test -f "$additional_libdir/lib$name.$shlibext" && test x$lib_type != xstatic; then found_dir="$additional_libdir" found_so="$additional_libdir/lib$name.$shlibext" if test -f "$additional_libdir/lib$name.la"; then found_la="$additional_libdir/lib$name.la" fi - else + elif test x$lib_type != xshared; then if test -f "$additional_libdir/lib$name.$libext"; then found_dir="$additional_libdir" found_a="$additional_libdir/lib$name.$libext" @@ -217,13 +222,13 @@ AC_DEFUN([AC_LIB_LINKFLAGS_BODY], case "$x" in -L*) dir=`echo "X$x" | sed -e 's/^X-L//'` - if test -n "$shlibext" && test -f "$dir/lib$name.$shlibext"; then + if test -n "$shlibext" && test -f "$dir/lib$name.$shlibext" && test x$lib_type != xstatic; then found_dir="$dir" found_so="$dir/lib$name.$shlibext" if test -f "$dir/lib$name.la"; then found_la="$dir/lib$name.la" fi - else + elif test x$lib_type != xshared; then if test -f "$dir/lib$name.$libext"; then found_dir="$dir" found_a="$dir/lib$name.$libext" @@ -487,8 +492,13 @@ AC_DEFUN([AC_LIB_LINKFLAGS_BODY], dnl known to the linker and runtime loader. (All the system dnl directories known to the linker should also be known to the dnl runtime loader, otherwise the system is severely misconfigured.) - LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-l$name" - LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-l$name" + if x$lib_type = xauto || x$lib_type = xshared; then + LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-l$name" + LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-l$name" + else + LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-l:lib$name.$libext" + LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-l:lib$name.$libext" + fi fi fi fi diff --git a/libcpp/configure b/libcpp/configure index a7aa35c5be0..7e53cade210 100755 --- a/libcpp/configure +++ b/libcpp/configure @@ -730,6 +730,7 @@ enable_werror_always with_gnu_ld enable_rpath with_libiconv_prefix +with_libiconv_type enable_maintainer_mode enable_checking enable_canonical_system_headers @@ -1383,6 +1384,7 @@ Optional Packages: --with-gnu-ld assume the C compiler uses GNU ld default=no --with-libiconv-prefix[=DIR] search for libiconv in DIR/include and DIR/lib --without-libiconv-prefix don't search for libiconv in includedir and libdir + --with-libiconv-type=TYPE type of library to search for (auto/static/shared) Some influential environment variables: CC C compiler command @@ -6753,6 +6755,16 @@ if test "${with_libiconv_prefix+set}" = set; then : fi + +# Check whether --with-libiconv-type was given. +if test "${with_libiconv_type+set}" = set; then : + withval=$with_libiconv_type; with_libiconv_type=$withval +else + with_libiconv_type=auto +fi + + lib_type=`eval echo \$with_libiconv_type` + LIBICONV= LTLIBICONV= INCICONV= @@ -6790,13 +6802,13 @@ fi found_so= found_a= if test $use_additional = yes; then - if test -n "$shlibext" && test -f "$additional_libdir/lib$name.$shlibext"; then + if test -n "$shlibext" && test -f "$additional_libdir/lib$name.$shlibext" && test x$lib_type != xstatic; then found_dir="$additional_libdir" found_so="$additional_libdir/lib$name.$shlibext" if test -f "$additional_libdir/lib$name.la"; then found_la="$additional_libdir/lib$name.la" fi - else + elif test x$lib_type != xshared; then if test -f "$additional_libdir/lib$name.$libext"; then found_dir="$additional_libdir" found_a="$additional_libdir/lib$name.$libext" @@ -6820,13 +6832,13 @@ fi case "$x" in -L*) dir=`echo "X$x" | sed -e 's/^X-L//'` - if test -n "$shlibext" && test -f "$dir/lib$name.$shlibext"; then + if test -n "$shlibext" && test -f "$dir/lib$name.$shlibext" && test x$lib_type != xstatic; then found_dir="$dir" found_so="$dir/lib$name.$shlibext" if test -f "$dir/lib$name.la"; then found_la="$dir/lib$name.la" fi - else + elif test x$lib_type != xshared; then if test -f "$dir/lib$name.$libext"; then found_dir="$dir" found_a="$dir/lib$name.$libext" @@ -7054,8 +7066,13 @@ fi done fi else - LIBICONV="${LIBICONV}${LIBICONV:+ }-l$name" - LTLIBICONV="${LTLIBICONV}${LTLIBICONV:+ }-l$name" + if x$lib_type = xauto || x$lib_type = xshared; then + LIBICONV="${LIBICONV}${LIBICONV:+ }-l$name" + LTLIBICONV="${LTLIBICONV}${LTLIBICONV:+ }-l$name" + else + LIBICONV="${LIBICONV}${LIBICONV:+ }-l:lib$name.$libext" + LTLIBICONV="${LTLIBICONV}${LTLIBICONV:+ }-l:lib$name.$libext" + fi fi fi fi diff --git a/libstdc++-v3/configure b/libstdc++-v3/configure index d2e516df6d0..a5b9c7ddd0c 100755 --- a/libstdc++-v3/configure +++ b/libstdc++-v3/configure @@ -931,6 +931,7 @@ enable_libstdcxx_time enable_tls enable_rpath with_libiconv_prefix +with_libiconv_type with_system_libunwind enable_linux_futex enable_symvers @@ -1664,6 +1665,7 @@ Optional Packages: --with-gnu-ld assume the C compiler uses GNU ld default=no --with-libiconv-prefix[=DIR] search for libiconv in DIR/include and DIR/lib --without-libiconv-prefix don't search for libiconv in includedir and libdir + --with-libiconv-type=TYPE type of library to search for (auto/static/shared) --with-system-libunwind use installed libunwind --with-default-libstdcxx-abi set the std::string ABI to use by default @@ -12053,7 +12055,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 12056 "configure" +#line 12058 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -12159,7 +12161,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 12162 "configure" +#line 12164 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -15851,7 +15853,7 @@ $as_echo "$glibcxx_cv_atomic_long_long" >&6; } # Fake what AC_TRY_COMPILE does. cat > conftest.$ac_ext << EOF -#line 15854 "configure" +#line 15856 "configure" int main() { typedef bool atomic_type; @@ -15886,7 +15888,7 @@ $as_echo "$glibcxx_cv_atomic_bool" >&6; } rm -f conftest* cat > conftest.$ac_ext << EOF -#line 15889 "configure" +#line 15891 "configure" int main() { typedef short atomic_type; @@ -15921,7 +15923,7 @@ $as_echo "$glibcxx_cv_atomic_short" >&6; } rm -f conftest* cat > conftest.$ac_ext << EOF -#line 15924 "configure" +#line 15926 "configure" int main() { // NB: _Atomic_word not necessarily int. @@ -15957,7 +15959,7 @@ $as_echo "$glibcxx_cv_atomic_int" >&6; } rm -f conftest* cat > conftest.$ac_ext << EOF -#line 15960 "configure" +#line 15962 "configure" int main() { typedef long long atomic_type; @@ -16110,7 +16112,7 @@ $as_echo "mutex" >&6; } # unnecessary for this test. cat > conftest.$ac_ext << EOF -#line 16113 "configure" +#line 16115 "configure" int main() { _Decimal32 d1; @@ -16152,7 +16154,7 @@ ac_compiler_gnu=$ac_cv_cxx_compiler_gnu # unnecessary for this test. cat > conftest.$ac_ext << EOF -#line 16155 "configure" +#line 16157 "configure" template struct same { typedef T2 type; }; @@ -16186,7 +16188,7 @@ $as_echo "$enable_int128" >&6; } rm -f conftest* cat > conftest.$ac_ext << EOF -#line 16189 "configure" +#line 16191 "configure" template struct same { typedef T2 type; }; @@ -29152,6 +29154,16 @@ if test "${with_libiconv_prefix+set}" = set; then : fi + +# Check whether --with-libiconv-type was given. +if test "${with_libiconv_type+set}" = set; then : + withval=$with_libiconv_type; with_libiconv_type=$withval +else + with_libiconv_type=auto +fi + + lib_type=`eval echo \$with_libiconv_type` + LIBICONV= LTLIBICONV= INCICONV= @@ -29189,13 +29201,13 @@ fi found_so= found_a= if test $use_additional = yes; then - if test -n "$shlibext" && test -f "$additional_libdir/lib$name.$shlibext"; then + if test -n "$shlibext" && test -f "$additional_libdir/lib$name.$shlibext" && test x$lib_type != xstatic; then found_dir="$additional_libdir" found_so="$additional_libdir/lib$name.$shlibext" if test -f "$additional_libdir/lib$name.la"; then found_la="$additional_libdir/lib$name.la" fi - else + elif test x$lib_type != xshared; then if test -f "$additional_libdir/lib$name.$libext"; then found_dir="$additional_libdir" found_a="$additional_libdir/lib$name.$libext" @@ -29219,13 +29231,13 @@ fi case "$x" in -L*) dir=`echo "X$x" | sed -e 's/^X-L//'` - if test -n "$shlibext" && test -f "$dir/lib$name.$shlibext"; then + if test -n "$shlibext" && test -f "$dir/lib$name.$shlibext" && test x$lib_type != xstatic; then found_dir="$dir" found_so="$dir/lib$name.$shlibext" if test -f "$dir/lib$name.la"; then found_la="$dir/lib$name.la" fi - else + elif test x$lib_type != xshared; then if test -f "$dir/lib$name.$libext"; then found_dir="$dir" found_a="$dir/lib$name.$libext" @@ -29453,8 +29465,13 @@ fi done fi else - LIBICONV="${LIBICONV}${LIBICONV:+ }-l$name" - LTLIBICONV="${LTLIBICONV}${LTLIBICONV:+ }-l$name" + if x$lib_type = xauto || x$lib_type = xshared; then + LIBICONV="${LIBICONV}${LIBICONV:+ }-l$name" + LTLIBICONV="${LTLIBICONV}${LTLIBICONV:+ }-l$name" + else + LIBICONV="${LIBICONV}${LIBICONV:+ }-l:lib$name.$libext" + LTLIBICONV="${LTLIBICONV}${LTLIBICONV:+ }-l:lib$name.$libext" + fi fi fi fi