From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1873) id 63BA9385800F; Mon, 4 Oct 2021 15:59:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 63BA9385800F MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Iain Buclaw To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-4146] d: gdc driver ignores -static-libstdc++ when automatically linking libstdc++ library X-Act-Checkin: gcc X-Git-Author: Iain Buclaw X-Git-Refname: refs/heads/master X-Git-Oldrev: c4ee0965371c9b243cca1305b443f54c5e4e236a X-Git-Newrev: c86a16b07b76604a8e3d556f135babab80e2b747 Message-Id: <20211004155936.63BA9385800F@sourceware.org> Date: Mon, 4 Oct 2021 15:59:36 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 04 Oct 2021 15:59:36 -0000 https://gcc.gnu.org/g:c86a16b07b76604a8e3d556f135babab80e2b747 commit r12-4146-gc86a16b07b76604a8e3d556f135babab80e2b747 Author: Iain Buclaw Date: Sun Oct 3 16:02:24 2021 +0200 d: gdc driver ignores -static-libstdc++ when automatically linking libstdc++ library Adds handling of `-static-libstc++' in the gdc driver, so that libstdc++ is appropriately linked if libstdc++ is either needed or seen on the command-line. PR d/102574 gcc/d/ChangeLog: * d-spec.cc (lang_specific_driver): Link libstdc++ statically if -static-libstdc++ was given on command-line. Diff: --- 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)