Message ID | 6AF41B3F-BB52-4B75-9336-54A9587CD627@codesourcery.com |
---|---|
State | New |
Headers | show |
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 >
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
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
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 --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)