diff mbox

[g++,driver] Push -static-libstdc++ back onto the command line to allow spec substitutions to use it.

Message ID 6AF41B3F-BB52-4B75-9336-54A9587CD627@codesourcery.com
State New
Headers show

Commit Message

Iain Sandoe June 18, 2015, 8:12 a.m. UTC
Hi,

This came up in a User question last night and reminded me that I had a patch for it in my Q.

----

Usually g++ driver support for -static-libstdc++ is provided by "-Bstatic -lstdc++ -Bdynamic" and is currently disabled for targets without that linker support.  However, actually, there is still an opportunity for those targets to implement the functionality with a spec substituation like:

%{static-libstdc++:%:replace-outfile(-lstdc++ libstdc++.a%s)}

However, this doesn't currently work because the g++ driver swallows "-static-libstdc++" so it's never seen by the specs.
The patch below pushes -static-libstdc++ onto the output command line (for targets without -Bstatic/dynamic)  so that such specs have an opportunity to fire.

OK for trunk?
Iain

gcc/cp:
	* g++spec.c (lang_specific_driver): Push "-static-libstdc++" back to the output
	command line when the target linker does not support -Bstatic/dynamic so that it
	is available for spec substitions to act on.


---
gcc/cp/g++spec.c | 9 +++++++++
1 file changed, 9 insertions(+)

Comments

Iain Sandoe July 12, 2015, 11:20 p.m. UTC | #1
Ping

On 18 Jun 2015, at 09:12, Iain Sandoe wrote:

> Hi,
> 
> This came up in a User question last night and reminded me that I had a patch for it in my Q.
> 
> ----
> 
> Usually g++ driver support for -static-libstdc++ is provided by "-Bstatic -lstdc++ -Bdynamic" and is currently disabled for targets without that linker support.  However, actually, there is still an opportunity for those targets to implement the functionality with a spec substituation like:
> 
> %{static-libstdc++:%:replace-outfile(-lstdc++ libstdc++.a%s)}
> 
> However, this doesn't currently work because the g++ driver swallows "-static-libstdc++" so it's never seen by the specs.
> The patch below pushes -static-libstdc++ onto the output command line (for targets without -Bstatic/dynamic)  so that such specs have an opportunity to fire.
> 
> OK for trunk?
> Iain
> 
> gcc/cp:
> 	* g++spec.c (lang_specific_driver): Push "-static-libstdc++" back to the output
> 	command line when the target linker does not support -Bstatic/dynamic so that it
> 	is available for spec substitions to act on.
> 
> 
> ---
> gcc/cp/g++spec.c | 9 +++++++++
> 1 file changed, 9 insertions(+)
> 
> diff --git a/gcc/cp/g++spec.c b/gcc/cp/g++spec.c
> index 6536d7e..48a9708 100644
> --- a/gcc/cp/g++spec.c
> +++ b/gcc/cp/g++spec.c
> @@ -363,6 +363,15 @@ lang_specific_driver (struct cl_decoded_option **in_decoded_options,
> 			   &new_decoded_options[j]);
> 	  j++;
> 	}
> +#else
> +      /* For linkers that don't support Bstatic/dynamic push the flag back
> +         so that spec substitution can see it.  */
> +      if (library > 1 && !static_link)
> +        {
> +          generate_option (OPT_static_libstdc__, NULL, 0, CL_DRIVER,
> +                           &new_decoded_options[j]);
> +          j++;
> +        }
> #endif
>    }
>  if (saw_math)
> -- 
> 2.2.1
>
Jason Merrill July 14, 2015, 5:24 p.m. UTC | #2
On 06/18/2015 04:12 AM, Iain Sandoe wrote:
> The patch below pushes -static-libstdc++ onto the output command line (for targets without -Bstatic/dynamic)  so that such specs have an opportunity to fire.

Won't that produce an unrecognized flag error from the linker?

Jason
Iain Sandoe July 14, 2015, 5:45 p.m. UTC | #3
On 14 Jul 2015, at 18:24, Jason Merrill wrote:

> On 06/18/2015 04:12 AM, Iain Sandoe wrote:
>> The patch below pushes -static-libstdc++ onto the output command line (for targets without -Bstatic/dynamic)  so that such specs have an opportunity to fire.
> 
> Won't that produce an unrecognized flag error from the linker?

IFF the target doesn't support -Bstatic/dynamic  *and* doesn't provide a spec %{static-libstdc++:...
then, that could happen.

There's a fairly small group of non-binutils targets - other than Darwin that would be maybe AIX and some Solaris versions (and I believe that the native linkers there do support -Bstatic/dynamic), however, I'll double-check with the maintainers.
Iain
Iain Sandoe Sept. 7, 2015, 6:04 p.m. UTC | #4
On 14 Jul 2015, at 18:45, Iain Sandoe wrote:

> 
> On 14 Jul 2015, at 18:24, Jason Merrill wrote:
> 
>> On 06/18/2015 04:12 AM, Iain Sandoe wrote:
>>> The patch below pushes -static-libstdc++ onto the output command line (for targets without -Bstatic/dynamic)  so that such specs have an opportunity to fire.
>> 
>> Won't that produce an unrecognized flag error from the linker?
> 
> IFF the target doesn't support -Bstatic/dynamic  *and* doesn't provide a spec %{static-libstdc++:...
> then, that could happen.
> 
> There's a fairly small group of non-binutils targets - other than Darwin that would be maybe AIX and some Solaris versions (and I believe that the native linkers there do support -Bstatic/dynamic), however, I'll double-check with the maintainers.

I checked with David (AIX) and Rainer (Solaris) as the only other two platforms I could think of off-hand that use non-binutils linkers.  Neither should be affected by the change,
OK for trunk?
Iain
diff mbox

Patch

diff --git a/gcc/cp/g++spec.c b/gcc/cp/g++spec.c
index 6536d7e..48a9708 100644
--- a/gcc/cp/g++spec.c
+++ b/gcc/cp/g++spec.c
@@ -363,6 +363,15 @@  lang_specific_driver (struct cl_decoded_option **in_decoded_options,
			   &new_decoded_options[j]);
	  j++;
	}
+#else
+      /* For linkers that don't support Bstatic/dynamic push the flag back
+         so that spec substitution can see it.  */
+      if (library > 1 && !static_link)
+        {
+          generate_option (OPT_static_libstdc__, NULL, 0, CL_DRIVER,
+                           &new_decoded_options[j]);
+          j++;
+        }
#endif
    }
  if (saw_math)