darwin, d: Support outfile substitution for libphobos
authorIain Buclaw <ibuclaw@gdcproject.org>
Fri, 19 Nov 2021 08:09:54 +0000 (09:09 +0100)
committerIain Buclaw <ibuclaw@gdcproject.org>
Wed, 1 Dec 2021 18:49:44 +0000 (19:49 +0100)
In the gdc driver, this takes the previous fix for the Darwin D
bootstrap, and extends it to the -static-libphobos option as well.
Rather than pushing the -static-libphobos option back onto the command
line, the setting of SKIPOPT is instead conditionally removed.  The same
change has been repeated for -static-libstdc++ so there is now no need
to call generate_option to re-add it.

In the gcc driver, -static-libphobos has been added as a common option,
validated, and a new outfile substition added to config/darwin.h to
correctly replace -lgphobos with libgphobos.a.

gcc/ChangeLog:

* common.opt (static-libphobos): Add option.
* config/darwin.h (LINK_SPEC): Substitute -lgphobos with libgphobos.a
when linking statically.
* gcc.c (driver_handle_option): Set -static-libphobos as always valid.

gcc/d/ChangeLog:

* d-spec.cc (lang_specific_driver): Set SKIPOPT on -static-libstdc++
and -static-libphobos only when target supports LD_STATIC_DYNAMIC.
Remove generate_option to re-add -static-libstdc++.

libphobos/ChangeLog:

* testsuite/testsuite_flags.in: Add libphobos library directory as
search path to --gdcldflags.

gcc/common.opt
gcc/config/darwin.h
gcc/d/d-spec.cc
gcc/gcc.c
libphobos/testsuite/testsuite_flags.in

index 755e1a2..fa0a44f 100644 (file)
@@ -3531,6 +3531,10 @@ static-libgfortran
 Driver
 ; Documented for Fortran, but always accepted by driver.
 
+static-libphobos
+Driver
+; Documented for D, but always accepted by driver.
+
 static-libstdc++
 Driver
 
index 8d8d402..9895e7f 100644 (file)
@@ -450,6 +450,7 @@ extern GTY(()) int darwin_ms_struct;
                      %:replace-outfile(-lobjc libobjc-gnu.a%s); \
                     :%:replace-outfile(-lobjc -lobjc-gnu )}}\
    %{static|static-libgcc|static-libgfortran:%:replace-outfile(-lgfortran libgfortran.a%s)}\
+   %{static|static-libgcc|static-libphobos:%:replace-outfile(-lgphobos libgphobos.a%s)}\
    %{static|static-libgcc|static-libstdc++|static-libgfortran:%:replace-outfile(-lgomp libgomp.a%s)}\
    %{static|static-libgcc|static-libstdc++:%:replace-outfile(-lstdc++ libstdc++.a%s)}\
    %{force_cpusubtype_ALL:-arch %(darwin_arch)} \
index b12d28f..1304126 100644 (file)
@@ -253,13 +253,23 @@ lang_specific_driver (cl_decoded_option **in_decoded_options,
 
        case OPT_static_libstdc__:
          saw_static_libcxx = true;
+#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_static_libphobos:
          if (phobos_library != PHOBOS_NOLINK)
            phobos_library = PHOBOS_STATIC;
+#ifdef HAVE_LD_STATIC_DYNAMIC
+         /* Remove -static-libphobos 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_shared_libphobos:
@@ -460,7 +470,7 @@ lang_specific_driver (cl_decoded_option **in_decoded_options,
 #endif
     }
 
-  if (saw_libcxx || need_stdcxx)
+  if (saw_libcxx || saw_static_libcxx || need_stdcxx)
     {
 #ifdef HAVE_LD_STATIC_DYNAMIC
       if (saw_static_libcxx && !static_link)
@@ -468,12 +478,6 @@ lang_specific_driver (cl_decoded_option **in_decoded_options,
          generate_option (OPT_Wl_, LD_STATIC_OPTION, 1, CL_DRIVER,
                           &new_decoded_options[j++]);
        }
-#else
-      /* Push the -static-libstdc++ option back onto the command so that
-        a target without LD_STATIC_DYNAMIC can use outfile substitution.  */
-      if (saw_static_libcxx && !static_link)
-       generate_option (OPT_static_libstdc__, NULL, 1, CL_DRIVER,
-                        &new_decoded_options[j++]);
 #endif
       if (saw_libcxx)
        new_decoded_options[j++] = *saw_libcxx;
index 6ff2278..694c257 100644 (file)
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -4576,10 +4576,12 @@ driver_handle_option (struct gcc_options *opts,
     case OPT_static_libgcc:
     case OPT_shared_libgcc:
     case OPT_static_libgfortran:
+    case OPT_static_libphobos:
     case OPT_static_libstdc__:
       /* These are always valid, since gcc.c itself understands the
-        first two, gfortranspec.c understands -static-libgfortran and
-        g++spec.c understands -static-libstdc++ */
+        first two, gfortranspec.c understands -static-libgfortran,
+        d-spec.cc understands -static-libphobos, and g++spec.c
+        understands -static-libstdc++ */
       validated = true;
       break;
 
index 93bf7cb..42053b2 100755 (executable)
@@ -46,6 +46,7 @@ case ${query} in
     --gdcldflags)
       GDCLDFLAGS="-B${BUILD_DIR}/src
                   -B${BUILD_DIR}/libdruntime/gcc
+                  -B${BUILD_DIR}/src/.libs
                   -L${BUILD_DIR}/src/.libs"
       echo ${GDCLDFLAGS}
       ;;