From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mout-p-102.mailbox.org (mout-p-102.mailbox.org [80.241.56.152]) by sourceware.org (Postfix) with ESMTPS id 943093858010 for ; Mon, 4 Oct 2021 16:00:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 943093858010 Received: from smtp1.mailbox.org (smtp1.mailbox.org [IPv6:2001:67c:2050:105:465:1:1:0]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-102.mailbox.org (Postfix) with ESMTPS id 4HNQRl21M0zQjbb; Mon, 4 Oct 2021 18:00:51 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de From: Iain Buclaw To: gcc-patches@gcc.gnu.org Subject: [committed] d: gdc driver ignores -static-libstdc++ when automatically linking libstdc++ library Date: Mon, 4 Oct 2021 18:00:46 +0200 Message-Id: <20211004160046.566990-1-ibuclaw@gdcproject.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 3D52E1898 X-Spam-Status: No, score=-14.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 04 Oct 2021 16:00:54 -0000 Hi, This patch adds handling of `-static-libstc++' to the gdc driver, so that libstdc++ is appropriately linked if it is either needed or seen on the command-line. This is required for bootstrapping the self hosted D front-end, so will also be backported to all supported releases. Bootstrapped and regression tested, and committed to mainline. Regards Iain. --- PR d/102574 gcc/d/ChangeLog: * d-spec.cc (lang_specific_driver): Link libstdc++ statically if -static-libstdc++ was given on command-line. --- gcc/d/d-spec.cc | 43 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/gcc/d/d-spec.cc b/gcc/d/d-spec.cc index 16ff1539e9f..5adc662c6f2 100644 --- a/gcc/d/d-spec.cc +++ b/gcc/d/d-spec.cc @@ -83,6 +83,9 @@ lang_specific_driver (cl_decoded_option **in_decoded_options, /* "-lstdc++" if it appears on the command line. */ const cl_decoded_option *saw_libcxx = 0; + /* True if we saw `-static-libstdc++'. */ + bool saw_static_libcxx = false; + /* Whether we need the C++ STD library. */ bool need_stdcxx = false; @@ -248,6 +251,11 @@ lang_specific_driver (cl_decoded_option **in_decoded_options, shared_libgcc = false; break; + case OPT_static_libstdc__: + saw_static_libcxx = true; + args[i] |= SKIPOPT; + break; + case OPT_static_libphobos: if (phobos_library != PHOBOS_NOLINK) phobos_library = PHOBOS_STATIC; @@ -452,16 +460,33 @@ lang_specific_driver (cl_decoded_option **in_decoded_options, #endif } - if (saw_libcxx) - new_decoded_options[j++] = *saw_libcxx; - else if (need_stdcxx) + if (saw_libcxx || need_stdcxx) { - generate_option (OPT_l, - (saw_profile_flag - ? LIBSTDCXX_PROFILE - : LIBSTDCXX), - 1, CL_DRIVER, &new_decoded_options[j++]); - added_libraries++; +#ifdef HAVE_LD_STATIC_DYNAMIC + if (saw_static_libcxx && !static_link) + { + generate_option (OPT_Wl_, LD_STATIC_OPTION, 1, CL_DRIVER, + &new_decoded_options[j++]); + } +#endif + if (saw_libcxx) + new_decoded_options[j++] = *saw_libcxx; + else if (need_stdcxx) + { + generate_option (OPT_l, + (saw_profile_flag + ? LIBSTDCXX_PROFILE + : LIBSTDCXX), + 1, CL_DRIVER, &new_decoded_options[j++]); + added_libraries++; + } +#ifdef HAVE_LD_STATIC_DYNAMIC + if (saw_static_libcxx && !static_link) + { + generate_option (OPT_Wl_, LD_DYNAMIC_OPTION, 1, CL_DRIVER, + &new_decoded_options[j++]); + } +#endif } if (shared_libgcc && !static_link) -- 2.30.2