public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] c++, driver: Fix -static-libstdc++ for targets without Bstatic/dynamic.
@ 2022-12-04 16:30 Iain Sandoe
  2022-12-22 19:14 ` [Ping^1] " Iain Sandoe
  2022-12-22 21:15 ` Jason Merrill
  0 siblings, 2 replies; 4+ messages in thread
From: Iain Sandoe @ 2022-12-04 16:30 UTC (permalink / raw)
  To: gcc-patches; +Cc: jason

This fixes a long-standing problem on Darwin where we cannot independently set
-static-libstdc++ because the flag gets stripped by the g++ driver.

This patch is essentially the same as the one used for the 'D' driver and has
been in local use for some time.  It has also been tested on Linux.

OK for master?
backports?
thanks
Iain

-- >8 --

The current implementation for swapping between the static and shared c++
runtimes relies on the static linker supporting Bstatic/dynamic which is
not available for every target (Darwin's linker does not support this).

Specs substitution (%s) is an alternative solution for this (which is what
Darwin uses for Fortran, D and Objective-C).  However, specs substitution
requires that the '-static-libstdc++' be preserved in the driver's command
line.  The patch here arranges for this to be done when the configuration
determines that linker support for Bstatic/dynamic is missing.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>

gcc/cp/ChangeLog:

	* g++spec.cc (lang_specific_driver): Preserve -static-libstdc++ in
	the driver command line for targets without -Bstatic/dynamic support
	in their static linker.
---
 gcc/cp/g++spec.cc | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/gcc/cp/g++spec.cc b/gcc/cp/g++spec.cc
index 3d3b042dd56..f95d7965355 100644
--- a/gcc/cp/g++spec.cc
+++ b/gcc/cp/g++spec.cc
@@ -234,7 +234,12 @@ lang_specific_driver (struct cl_decoded_option **in_decoded_options,
 
 	case OPT_static_libstdc__:
 	  library = library >= 0 ? 2 : library;
+#ifdef HAVE_LD_STATIC_DYNAMIC
+	  /* Remove -static-libstdc++ from the command only if target supports
+	     LD_STATIC_DYNAMIC.  When not supported, it is left in so that a
+	     back-end target can use outfile substitution.  */
 	  args[i] |= SKIPOPT;
+#endif
 	  break;
 
 	case OPT_stdlib_:
-- 
2.37.1 (Apple Git-137.1)


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Ping^1] [PATCH] c++, driver: Fix -static-libstdc++ for targets without Bstatic/dynamic.
  2022-12-04 16:30 [PATCH] c++, driver: Fix -static-libstdc++ for targets without Bstatic/dynamic Iain Sandoe
@ 2022-12-22 19:14 ` Iain Sandoe
  2022-12-22 21:15 ` Jason Merrill
  1 sibling, 0 replies; 4+ messages in thread
From: Iain Sandoe @ 2022-12-22 19:14 UTC (permalink / raw)
  To: GCC Patches; +Cc: Jason Merrill

Hi
this has become more important since it seems I can no longer link a working gnat1 without
it,
thanks
Iain

> On 4 Dec 2022, at 16:30, Iain Sandoe via Gcc-patches <gcc-patches@gcc.gnu.org> wrote:
> 
> This fixes a long-standing problem on Darwin where we cannot independently set
> -static-libstdc++ because the flag gets stripped by the g++ driver.
> 
> This patch is essentially the same as the one used for the 'D' driver and has
> been in local use for some time.  It has also been tested on Linux.
> 
> OK for master?
> backports?
> thanks
> Iain
> 
> -- >8 --
> 
> The current implementation for swapping between the static and shared c++
> runtimes relies on the static linker supporting Bstatic/dynamic which is
> not available for every target (Darwin's linker does not support this).
> 
> Specs substitution (%s) is an alternative solution for this (which is what
> Darwin uses for Fortran, D and Objective-C).  However, specs substitution
> requires that the '-static-libstdc++' be preserved in the driver's command
> line.  The patch here arranges for this to be done when the configuration
> determines that linker support for Bstatic/dynamic is missing.
> 
> Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
> 
> gcc/cp/ChangeLog:
> 
> 	* g++spec.cc (lang_specific_driver): Preserve -static-libstdc++ in
> 	the driver command line for targets without -Bstatic/dynamic support
> 	in their static linker.
> ---
> gcc/cp/g++spec.cc | 5 +++++
> 1 file changed, 5 insertions(+)
> 
> diff --git a/gcc/cp/g++spec.cc b/gcc/cp/g++spec.cc
> index 3d3b042dd56..f95d7965355 100644
> --- a/gcc/cp/g++spec.cc
> +++ b/gcc/cp/g++spec.cc
> @@ -234,7 +234,12 @@ lang_specific_driver (struct cl_decoded_option **in_decoded_options,
> 
> 	case OPT_static_libstdc__:
> 	  library = library >= 0 ? 2 : library;
> +#ifdef HAVE_LD_STATIC_DYNAMIC
> +	  /* Remove -static-libstdc++ from the command only if target supports
> +	     LD_STATIC_DYNAMIC.  When not supported, it is left in so that a
> +	     back-end target can use outfile substitution.  */
> 	  args[i] |= SKIPOPT;
> +#endif
> 	  break;
> 
> 	case OPT_stdlib_:
> -- 
> 2.37.1 (Apple Git-137.1)
> 


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] c++, driver: Fix -static-libstdc++ for targets without Bstatic/dynamic.
  2022-12-04 16:30 [PATCH] c++, driver: Fix -static-libstdc++ for targets without Bstatic/dynamic Iain Sandoe
  2022-12-22 19:14 ` [Ping^1] " Iain Sandoe
@ 2022-12-22 21:15 ` Jason Merrill
  2022-12-22 21:21   ` Iain Sandoe
  1 sibling, 1 reply; 4+ messages in thread
From: Jason Merrill @ 2022-12-22 21:15 UTC (permalink / raw)
  To: iain, gcc-patches

On 12/4/22 11:30, Iain Sandoe wrote:
> This fixes a long-standing problem on Darwin where we cannot independently set
> -static-libstdc++ because the flag gets stripped by the g++ driver.
> 
> This patch is essentially the same as the one used for the 'D' driver and has
> been in local use for some time.  It has also been tested on Linux.
> 
> OK for master?
> backports?
> thanks
> Iain
> 
> -- >8 --
> 
> The current implementation for swapping between the static and shared c++
> runtimes relies on the static linker supporting Bstatic/dynamic which is
> not available for every target (Darwin's linker does not support this).
> 
> Specs substitution (%s) is an alternative solution for this (which is what
> Darwin uses for Fortran, D and Objective-C).  However, specs substitution
> requires that the '-static-libstdc++' be preserved in the driver's command
> line.  The patch here arranges for this to be done when the configuration
> determines that linker support for Bstatic/dynamic is missing.

Would it work to define LIBSTDCXX_STATIC instead?  If not, the patch is OK.

Really there should be a way for lang_specific_driver to mark a flag as 
"validated" rather than prune it.

> Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
> 
> gcc/cp/ChangeLog:
> 
> 	* g++spec.cc (lang_specific_driver): Preserve -static-libstdc++ in
> 	the driver command line for targets without -Bstatic/dynamic support
> 	in their static linker.
> ---
>   gcc/cp/g++spec.cc | 5 +++++
>   1 file changed, 5 insertions(+)
> 
> diff --git a/gcc/cp/g++spec.cc b/gcc/cp/g++spec.cc
> index 3d3b042dd56..f95d7965355 100644
> --- a/gcc/cp/g++spec.cc
> +++ b/gcc/cp/g++spec.cc
> @@ -234,7 +234,12 @@ lang_specific_driver (struct cl_decoded_option **in_decoded_options,
>   
>   	case OPT_static_libstdc__:
>   	  library = library >= 0 ? 2 : library;
> +#ifdef HAVE_LD_STATIC_DYNAMIC
> +	  /* Remove -static-libstdc++ from the command only if target supports
> +	     LD_STATIC_DYNAMIC.  When not supported, it is left in so that a
> +	     back-end target can use outfile substitution.  */
>   	  args[i] |= SKIPOPT;
> +#endif
>   	  break;
>   
>   	case OPT_stdlib_:


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] c++, driver: Fix -static-libstdc++ for targets without Bstatic/dynamic.
  2022-12-22 21:15 ` Jason Merrill
@ 2022-12-22 21:21   ` Iain Sandoe
  0 siblings, 0 replies; 4+ messages in thread
From: Iain Sandoe @ 2022-12-22 21:21 UTC (permalink / raw)
  To: Jason Merrill; +Cc: GCC Patches



> On 22 Dec 2022, at 21:15, Jason Merrill <jason@redhat.com> wrote:
> 
> On 12/4/22 11:30, Iain Sandoe wrote:
>> This fixes a long-standing problem on Darwin where we cannot independently set
>> -static-libstdc++ because the flag gets stripped by the g++ driver.
>> This patch is essentially the same as the one used for the 'D' driver and has
>> been in local use for some time.  It has also been tested on Linux.
>> OK for master?
>> backports?
>> thanks
>> Iain
>> -- >8 --
>> The current implementation for swapping between the static and shared c++
>> runtimes relies on the static linker supporting Bstatic/dynamic which is
>> not available for every target (Darwin's linker does not support this).
>> Specs substitution (%s) is an alternative solution for this (which is what
>> Darwin uses for Fortran, D and Objective-C).  However, specs substitution
>> requires that the '-static-libstdc++' be preserved in the driver's command
>> line.  The patch here arranges for this to be done when the configuration
>> determines that linker support for Bstatic/dynamic is missing.
> 
> Would it work to define LIBSTDCXX_STATIC instead?

Not without modifying the build of libstdc++.  When Darwin’s linker sees a convenience library with the
same name as a shared one, it will pick the shared one, so we would have to modify the build of libstdc++
to make the library named libstdc++-static.a or so (that was essentially what the Apple gcc-4.2.1 impl.
did AFAIR).

>  If not, the patch is OK.

Thanks.

> 
> Really there should be a way for lang_specific_driver to mark a flag as "validated" rather than prune it.

Yes - especially since we now already three drivers (c++, d, gm2) that need to do the same stuff for
handing libstdc++.
Iain

> 
>> Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
>> gcc/cp/ChangeLog:
>> 	* g++spec.cc (lang_specific_driver): Preserve -static-libstdc++ in
>> 	the driver command line for targets without -Bstatic/dynamic support
>> 	in their static linker.
>> ---
>>  gcc/cp/g++spec.cc | 5 +++++
>>  1 file changed, 5 insertions(+)
>> diff --git a/gcc/cp/g++spec.cc b/gcc/cp/g++spec.cc
>> index 3d3b042dd56..f95d7965355 100644
>> --- a/gcc/cp/g++spec.cc
>> +++ b/gcc/cp/g++spec.cc
>> @@ -234,7 +234,12 @@ lang_specific_driver (struct cl_decoded_option **in_decoded_options,
>>    	case OPT_static_libstdc__:
>>  	  library = library >= 0 ? 2 : library;
>> +#ifdef HAVE_LD_STATIC_DYNAMIC
>> +	  /* Remove -static-libstdc++ from the command only if target supports
>> +	     LD_STATIC_DYNAMIC.  When not supported, it is left in so that a
>> +	     back-end target can use outfile substitution.  */
>>  	  args[i] |= SKIPOPT;
>> +#endif
>>  	  break;
>>    	case OPT_stdlib_:
> 


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-12-22 21:21 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-04 16:30 [PATCH] c++, driver: Fix -static-libstdc++ for targets without Bstatic/dynamic Iain Sandoe
2022-12-22 19:14 ` [Ping^1] " Iain Sandoe
2022-12-22 21:15 ` Jason Merrill
2022-12-22 21:21   ` 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).