* [committed] d: gdc driver ignores -static-libstdc++ when automatically linking libstdc++ library
@ 2021-10-04 16:00 Iain Buclaw
2021-10-04 16:48 ` Iain Sandoe
0 siblings, 1 reply; 4+ messages in thread
From: Iain Buclaw @ 2021-10-04 16:00 UTC (permalink / raw)
To: 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)
--
2.30.2
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [committed] d: gdc driver ignores -static-libstdc++ when automatically linking libstdc++ library
2021-10-04 16:00 [committed] d: gdc driver ignores -static-libstdc++ when automatically linking libstdc++ library Iain Buclaw
@ 2021-10-04 16:48 ` Iain Sandoe
2021-10-05 8:02 ` ibuclaw
0 siblings, 1 reply; 4+ messages in thread
From: Iain Sandoe @ 2021-10-04 16:48 UTC (permalink / raw)
To: Iain Buclaw; +Cc: gcc-patches
Hi Iain
> On 4 Oct 2021, at 17:00, Iain Buclaw via Gcc-patches <gcc-patches@gcc.gnu.org> wrote:
>
> 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++]);
> + }
For targets that don’t support HAVE_LD_STATIC_DYNAMIC it would be useful
to push the option back out, so that they can use that to substitute a static version
of the library using %:replace-outfile(-lxxxxx libxxxxx+.a%s) [ see darwin.h for
examples. ] .. I suppose we could figure out a follow-on patch and test that on
Darwin?
so
#else
… code to push the -libstdc++ out
(yes, we do have this problem also with the g++ driver… I posted a patch eons
ago .. but suspect it was never applied)
Iain
> +#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
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [committed] d: gdc driver ignores -static-libstdc++ when automatically linking libstdc++ library
2021-10-04 16:48 ` Iain Sandoe
@ 2021-10-05 8:02 ` ibuclaw
2021-10-05 20:03 ` Iain Sandoe
0 siblings, 1 reply; 4+ messages in thread
From: ibuclaw @ 2021-10-05 8:02 UTC (permalink / raw)
To: Iain Sandoe; +Cc: gcc-patches
> On 04/10/2021 18:48 Iain Sandoe <idsandoe@googlemail.com> wrote:
>
> For targets that don’t support HAVE_LD_STATIC_DYNAMIC it would be useful
> to push the option back out, so that they can use that to substitute a static version
> of the library using %:replace-outfile(-lxxxxx libxxxxx+.a%s) [ see darwin.h for
> examples. ] .. I suppose we could figure out a follow-on patch and test that on
> Darwin?
>
> so
> #else
> … code to push the -libstdc++ out
>
> (yes, we do have this problem also with the g++ driver… I posted a patch eons
> ago .. but suspect it was never applied)
>
Sure, seems reasonable to me, will follow up.
I had a look at darwin.h, and it occurs to me that you probably will be wanting -static-libphobos added there as well, which means moving that option to common.opt.
Iain.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [committed] d: gdc driver ignores -static-libstdc++ when automatically linking libstdc++ library
2021-10-05 8:02 ` ibuclaw
@ 2021-10-05 20:03 ` Iain Sandoe
0 siblings, 0 replies; 4+ messages in thread
From: Iain Sandoe @ 2021-10-05 20:03 UTC (permalink / raw)
To: Iain Buclaw; +Cc: gcc-patches
Hi Iain,
> On 5 Oct 2021, at 09:02, ibuclaw@gdcproject.org wrote:
>
>> On 04/10/2021 18:48 Iain Sandoe <idsandoe@googlemail.com> wrote:
>>
>> For targets that don’t support HAVE_LD_STATIC_DYNAMIC it would be useful
>> to push the option back out, so that they can use that to substitute a static version
>> of the library using %:replace-outfile(-lxxxxx libxxxxx+.a%s) [ see darwin.h for
>> examples. ] .. I suppose we could figure out a follow-on patch and test that on
>> Darwin?
>>
>> so
>> #else
>> … code to push the -libstdc++ out
>>
>> (yes, we do have this problem also with the g++ driver… I posted a patch eons
>> ago .. but suspect it was never applied)
>>
>
> Sure, seems reasonable to me, will follow up.
as it happens the current state breaks Darwin bootstrap, there’s a “set but unused”.
fixed by https://gcc.gnu.org/pipermail/gcc-patches/2021-October/581016.html
if that fix is acceptible, then we can backport it to the branches too - which will also be broken; if not then we should shake down an alternate soon.
> I had a look at darwin.h, and it occurs to me that you probably will be wanting -static-libphobos added there as well, which means moving that option to common.opt.
could be; but the fix above at least provides independent control over the static-libstdc++ situation (which tends to be more problematic on Darwin, since libstdc++ (latest) is always co-installed with the system’s (very old) version.
Iain
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-10-05 20:03 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-04 16:00 [committed] d: gdc driver ignores -static-libstdc++ when automatically linking libstdc++ library Iain Buclaw
2021-10-04 16:48 ` Iain Sandoe
2021-10-05 8:02 ` ibuclaw
2021-10-05 20:03 ` Iain Sandoe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).