From debbugs-submit-bounces@debbugs.gnu.org Tue Apr 05 10:23:58 2022 Received: (at submit) by debbugs.gnu.org; 5 Apr 2022 14:23:58 +0000 Received: from localhost ([127.0.0.1]:55771 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nbk67-0000St-Bn for submit@debbugs.gnu.org; Tue, 05 Apr 2022 10:23:58 -0400 Received: from lists.gnu.org ([209.51.188.17]:41940) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nbiDI-0002rt-VN for submit@debbugs.gnu.org; Tue, 05 Apr 2022 08:23:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60058) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nbiDI-0002ms-QW for bug-libtool@gnu.org; Tue, 05 Apr 2022 08:23:12 -0400 Received: from smtp5-g21.free.fr ([212.27.42.5]:9846) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nbiDE-0003Q5-Sn for bug-libtool@gnu.org; Tue, 05 Apr 2022 08:23:12 -0400 Received: from nicolasthinkpad.home (unknown [IPv6:2a01:e0a:918:cdf0:5fb2:bbf9:1b44:bf4b]) by smtp5-g21.free.fr (Postfix) with ESMTPS id C487C5FFC0 for ; Tue, 5 Apr 2022 14:23:04 +0200 (CEST) Received: from nicolas by nicolasthinkpad.home with local (Exim 4.94.2) (envelope-from ) id 1nbgm3-000FQU-BC for bug-libtool@gnu.org; Tue, 05 Apr 2022 12:50:59 +0200 Date: Tue, 5 Apr 2022 12:50:59 +0200 From: Nicolas Boulenguez To: bug-libtool@gnu.org Subject: when linking a shared library on Linux, libtool 2.4.6 ignores libfoo.so arguments Message-ID: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="PgrnQFoVlmNhbN1/" Content-Disposition: inline Received-SPF: pass client-ip=212.27.42.5; envelope-from=nicolas.boulenguez@free.fr; helo=smtp5-g21.free.fr X-Spam_score_int: -13 X-Spam_score: -1.4 X-Spam_bar: - X-Spam_report: (-1.4 / 5.0 requ) BAYES_00=-1.9, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-Spam-Score: 0.4 (/) X-Debbugs-Envelope-To: submit X-Mailman-Approved-At: Tue, 05 Apr 2022 10:23:54 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.2 (--) --PgrnQFoVlmNhbN1/ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hello. When linking a shared library or a program against a (locally built, not installed) foo library, it is recommended to prefer dir/libfoo.so over -Ldir -lfoo which only adds complexity and unwanted ambiguity (for example, /usr/lib/libfoo.{a,so} may silently be selected if dir/libfoo.so is unexpectedly missing). Libtool recognizes such options when linking a program, but ignores them when linking a shared library. The attached reproducer * builds with -Ldir -lfoo in order to ensure that the sources are correct * demonstrates the link failure with a direct path * builds with the attached patch applied and a direct path Just in case it helps, the original bug report is here: Bug-Debian: https://bugs.debian.org/960469 Thanks. --PgrnQFoVlmNhbN1/ Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="draft960469.diff" Description: allow dir/libfoo.so as argument when linking a shared library This already works for programs, and is actually recommended for uninstalled yet libraries instead of the more ambiguous -Ldir -lfoo. Bug-Debian: https://bugs.debian.org/960469 Author: Nicolas Boulenguez --- a/build-aux/ltmain.in +++ b/build-aux/ltmain.in @@ -5517,6 +5517,13 @@ continue ;; + *.so) + # An explicit path to a shared library. + func_append deplibs " $arg" + func_append old_deplibs " $arg" + continue + ;; + *.la) # A libtool-controlled library. @@ -5871,6 +5878,16 @@ func_resolve_sysroot "$deplib" lib=$func_resolve_sysroot_result ;; + *.so) + # FIXME: linkmode=prog copies .so arguments without this stanza. Duplicate code? + if test lib = "$linkmode"; then + deplibs="$deplib $deplibs" + test lib = "$linkmode" && newdependency_libs="$deplib $newdependency_libs" + elif test prog != "$linkmode"; then + func_warning "shared library '$deplib' ignored for archive/object" + fi + continue + ;; *.$libext) if test conv = "$pass"; then deplibs="$deplib $deplibs" --PgrnQFoVlmNhbN1/ Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=reproducer #!/bin/sh # Demonstrate the issue and check the fix. # Tested with GNU libtool 2.4.6 on Debian 5.10/GNU Linux x86_64. fix=draft960469.diff tmpdir=reproducer_temporary_directory set -C -e -f -u -v mkdir $tmpdir cd $tmpdir recreate_template() { find . -mindepth 1 -delete cat > hello.c < void hello (void) { printf ("If you are reading this, all probably went OK.\n"); } EOF cat > redirect.c < main.c < configure.ac < Makefile.am <> Makefile.am echo 'EXTRA_libredirect_la_DEPENDENCIES = libhello.so' >> Makefile.am autoreconf -i ./configure make LD_LIBRARY_PATH=. ./main # Recommended way (libhello.so). Currently fails. recreate_template echo 'libredirect_la_LIBADD = libhello.so' >> Makefile.am autoreconf -i ./configure ! make # Recommended way, with libtool patched. Should succeed. recreate_template echo 'libredirect_la_LIBADD = libhello.so' >> Makefile.am autoreconf -i ./configure patch -p2 libtool ../$fix make LD_LIBRARY_PATH=. ./main --PgrnQFoVlmNhbN1/--