]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++, driver: Fix -static-libstdc++ for targets without Bstatic/dynamic.
authorIain Sandoe <iain@sandoe.co.uk>
Thu, 6 Jan 2022 08:37:18 +0000 (08:37 +0000)
committerIain Sandoe <iain@sandoe.co.uk>
Mon, 22 Apr 2024 13:08:45 +0000 (14:08 +0100)
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.c (lang_specific_driver): Preserve -static-libstdc++ in
the driver command line for targets without -Bstatic/dynamic support
in their static linker.

(cherry picked from commit a846817739c1e7b930d593cd51963d6b46b5dfc6)

gcc/cp/g++spec.c

index 3c9bd1490b4ae14462f628a84f5207f1f9cf345f..984106f10dd108c0bb23ac30df5f5a10abbddf6a 100644 (file)
@@ -222,7 +222,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_: