From patchwork Mon Oct 4 16:00:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Buclaw X-Patchwork-Id: 1536208 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=s15dCbfs; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HNQSt2Vbvz9t5G for ; Tue, 5 Oct 2021 03:01:50 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9A5E43857807 for ; Mon, 4 Oct 2021 16:01:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9A5E43857807 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1633363307; bh=L5UZU/JHu8tUbyjIyVenQnxMDhowekODEkUlzMrOv3o=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=s15dCbfs2vCEs1LVem6H5Z8wLbKqfVaEoc1Br13hp4Cswkwu4pOkHiszv1pAtzD31 KWhny5z7obOVufGSv6MXnSL+nZ2e8FQpSx+BQ8Fdj3allBIquYKsK0d6z5NQcpP6dy Jn9P6ydAwITl8F10WnfxOBLId2CNuoCbnr660ESw= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 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 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-Patchwork-Original-From: Iain Buclaw via Gcc-patches From: Iain Buclaw Reply-To: Iain Buclaw Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" 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)