From patchwork Fri Apr 24 21:40:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Buclaw X-Patchwork-Id: 1276710 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=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: 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=ny/zAuS+; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4986zY69lCz9sPF for ; Sat, 25 Apr 2020 07:40:40 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 164333894E79; Fri, 24 Apr 2020 21:40:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 164333894E79 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1587764438; bh=TeH/j5c3XMLVd88bgLMF6oxT5xgapSzsfI79qEy7A5o=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=ny/zAuS+9SEOS/2Nid/1ReJAK9ucrE4/cVupz1S1JglYxeybKHM/6+KSKhstl20hY 7kePrM12YwDlagIhNkTsLKRleUWHz6rVkHIu6WUr5a1GnD5652eeW8Lj9NcdYuGVPs PZvy616JQdDJpDIaGwVUBZr1lQA6GQ1l/YHDg8Mg= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mout-p-101.mailbox.org (mout-p-101.mailbox.org [80.241.56.151]) by sourceware.org (Postfix) with ESMTPS id 98406386EC42 for ; Fri, 24 Apr 2020 21:40:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 98406386EC42 Received: from smtp2.mailbox.org (smtp2.mailbox.org [80.241.60.241]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by mout-p-101.mailbox.org (Postfix) with ESMTPS id 4986zP2XxMzKmtX; Fri, 24 Apr 2020 23:40:33 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp2.mailbox.org ([80.241.60.241]) by spamfilter06.heinlein-hosting.de (spamfilter06.heinlein-hosting.de [80.241.56.125]) (amavisd-new, port 10030) with ESMTP id uBgWufvDIVyE; Fri, 24 Apr 2020 23:40:30 +0200 (CEST) To: gcc-patches@gcc.gnu.org Subject: [committed] d: Fix order of precedence for -defaultlib and -debuglib Date: Fri, 24 Apr 2020 23:40:28 +0200 Message-Id: <20200424214028.19489-1-ibuclaw@gdcproject.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 669BF176A X-Rspamd-Score: 1.30 / 15.00 / 15.00 X-Spam-Status: No, score=-28.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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@gcc.gnu.org Sender: "Gcc-patches" Hi, The order of precedence used by the upstream reference compiler for determining what library to link against is: - No library if -nophoboslib or -fno-druntime was seen. - The library passed to -debuglib if -g was also seen. - The library passed to -defaultlib - The in-tree libgphobos library. This patch aligns the D language driver to follow the same rules. Bootstrapped and regression tested on x86_64-linux-gnu, and committed to mainline. Regards Iain. --- gcc/d/ChangeLog: * d-spec.cc (need_phobos): Remove. (lang_specific_driver): Replace need_phobos with phobos_library. Reorder -debuglib and -defaultlib to have precedence over libphobos. (lang_specific_pre_link): Remove test for need_phobos. --- gcc/d/d-spec.cc | 84 +++++++++++++++++++++---------------------------- 1 file changed, 36 insertions(+), 48 deletions(-) diff --git a/gcc/d/d-spec.cc b/gcc/d/d-spec.cc index e0844222520..f4744763ab6 100644 --- a/gcc/d/d-spec.cc +++ b/gcc/d/d-spec.cc @@ -61,10 +61,6 @@ enum phobos_action static phobos_action phobos_library = PHOBOS_DEFAULT; -/* If true, use the standard D runtime library when linking with - standard libraries. */ -static bool need_phobos = true; - /* If true, do load libgphobos.spec even if not needed otherwise. */ static bool need_spec = false; @@ -151,13 +147,15 @@ lang_specific_driver (cl_decoded_option **in_decoded_options, break; case OPT_nophoboslib: - need_phobos = false; + phobos_library = PHOBOS_NOLINK; args[i] |= SKIPOPT; break; case OPT_fdruntime: if (!value) - need_phobos = false; + phobos_library = PHOBOS_NOLINK; + else + phobos_library = PHOBOS_LINK; break; case OPT_defaultlib_: @@ -165,7 +163,6 @@ lang_specific_driver (cl_decoded_option **in_decoded_options, free (CONST_CAST (char *, defaultlib)); if (arg != NULL) { - need_phobos = false; args[i] |= SKIPOPT; defaultlib = XNEWVEC (char, strlen (arg)); strcpy (CONST_CAST (char *, defaultlib), arg); @@ -177,7 +174,6 @@ lang_specific_driver (cl_decoded_option **in_decoded_options, free (CONST_CAST (char *, debuglib)); if (arg != NULL) { - need_phobos = false; args[i] |= SKIPOPT; debuglib = XNEWVEC (char, strlen (arg)); strcpy (CONST_CAST (char *, debuglib), arg); @@ -314,10 +310,11 @@ lang_specific_driver (cl_decoded_option **in_decoded_options, #endif /* Make sure to have room for the trailing NULL argument. - - needstdcxx might add `-lstdcxx' + - need_stdcxx might add `-lstdcxx' - libphobos adds `-Bstatic -lphobos -Bdynamic' - only_source adds 1 more arg, also maybe add `-o'. */ - num_args = argc + need_stdcxx + shared_libgcc + need_phobos * 4 + 2; + num_args = argc + need_stdcxx + shared_libgcc + + (phobos_library != PHOBOS_NOLINK) * 4 + 2; new_decoded_options = XNEWVEC (cl_decoded_option, num_args); i = 0; @@ -409,60 +406,51 @@ lang_specific_driver (cl_decoded_option **in_decoded_options, } /* Add `-lgphobos' if we haven't already done so. */ - if (phobos_library != PHOBOS_NOLINK && need_phobos) + if (phobos_library != PHOBOS_NOLINK) { /* Default to static linking. */ if (phobos_library != PHOBOS_DYNAMIC) phobos_library = PHOBOS_STATIC; #ifdef HAVE_LD_STATIC_DYNAMIC - if (phobos_library == PHOBOS_DYNAMIC && static_link) - { - generate_option (OPT_Wl_, LD_DYNAMIC_OPTION, 1, CL_DRIVER, - &new_decoded_options[j]); - j++; - } - else if (phobos_library == PHOBOS_STATIC && !static_link) + if (phobos_library == PHOBOS_STATIC && !static_link) { generate_option (OPT_Wl_, LD_STATIC_OPTION, 1, CL_DRIVER, - &new_decoded_options[j]); - j++; + &new_decoded_options[j++]); } #endif - - generate_option (OPT_l, - saw_profile_flag ? LIBPHOBOS_PROFILE : LIBPHOBOS, 1, - CL_DRIVER, &new_decoded_options[j]); - added_libraries++; - j++; - -#ifdef HAVE_LD_STATIC_DYNAMIC - if (phobos_library == PHOBOS_DYNAMIC && static_link) + /* Order of precedence in determining what library to link against is: + - `-l' from `-debuglib=' if `-g' was also seen. + - `-l' from `-defaultlib='. + - `-lgphobos' unless `-nophoboslib' or `-fno-druntime' was seen. */ + if (debuglib && saw_debug_flag) { - generate_option (OPT_Wl_, LD_STATIC_OPTION, 1, CL_DRIVER, - &new_decoded_options[j]); - j++; + generate_option (OPT_l, debuglib, 1, CL_DRIVER, + &new_decoded_options[j++]); + added_libraries++; } - else if (phobos_library == PHOBOS_STATIC && !static_link) + else if (defaultlib) + { + generate_option (OPT_l, defaultlib, 1, CL_DRIVER, + &new_decoded_options[j++]); + added_libraries++; + } + else + { + generate_option (OPT_l, + saw_profile_flag ? LIBPHOBOS_PROFILE : LIBPHOBOS, 1, + CL_DRIVER, &new_decoded_options[j++]); + added_libraries++; + } + +#ifdef HAVE_LD_STATIC_DYNAMIC + if (phobos_library == PHOBOS_STATIC && !static_link) { generate_option (OPT_Wl_, LD_DYNAMIC_OPTION, 1, CL_DRIVER, - &new_decoded_options[j]); - j++; + &new_decoded_options[j++]); } #endif } - else if (saw_debug_flag && debuglib) - { - generate_option (OPT_l, debuglib, 1, CL_DRIVER, - &new_decoded_options[j++]); - added_libraries++; - } - else if (defaultlib) - { - generate_option (OPT_l, defaultlib, 1, CL_DRIVER, - &new_decoded_options[j++]); - added_libraries++; - } if (saw_libcxx) new_decoded_options[j++] = *saw_libcxx; @@ -492,7 +480,7 @@ lang_specific_driver (cl_decoded_option **in_decoded_options, int lang_specific_pre_link (void) { - if ((phobos_library != PHOBOS_NOLINK && need_phobos) || need_spec) + if ((phobos_library != PHOBOS_NOLINK) || need_spec) do_spec ("%:include(libgphobos.spec)"); return 0;