]> git.ipfire.org Git - thirdparty/gcc.git/blobdiff - gcc/lto-wrapper.c
offload-defaulted: Config option to silently ignore uninstalled offload compilers
[thirdparty/gcc.git] / gcc / lto-wrapper.c
index fe10f4f4fbb8b36a12cdea4373abf9ff72ec6f41..e95b0d849baaee50cb317ce25df81925dddd8635 100644 (file)
@@ -1,5 +1,5 @@
 /* Wrapper to call lto.  Used by collect2 and the linker plugin.
-   Copyright (C) 2009-2020 Free Software Foundation, Inc.
+   Copyright (C) 2009-2021 Free Software Foundation, Inc.
 
    Factored out of collect2 by Rafael Espindola <espindola@google.com>
 
@@ -52,6 +52,7 @@ along with GCC; see the file COPYING3.  If not see
 /* Environment variable, used for passing the names of offload targets from GCC
    driver to lto-wrapper.  */
 #define OFFLOAD_TARGET_NAMES_ENV       "OFFLOAD_TARGET_NAMES"
+#define OFFLOAD_TARGET_DEFAULT_ENV     "OFFLOAD_TARGET_DEFAULT"
 
 /* By default there is no special suffix for target executables.  */
 #ifdef TARGET_EXECUTABLE_SUFFIX
@@ -323,8 +324,9 @@ merge_and_complain (struct cl_decoded_option **decoded_options,
                  if (cf_protection_option
                      && cf_protection_option->value == CF_CHECK)
                    fatal_error (input_location,
-                                "option -fcf-protection with mismatching values"
+                                "option %qs with mismatching values"
                                 " (%s, %s)",
+                                "-fcf-protection",
                                 (*decoded_options)[j].arg, foption->arg);
                  else
                    {
@@ -905,6 +907,13 @@ compile_offload_image (const char *target, const char *compiler_path,
        compiler = paths[i];
        break;
       }
+#if OFFLOAD_DEFAULTED
+  if (!compiler && getenv (OFFLOAD_TARGET_DEFAULT_ENV))
+    {
+      free_array_of_ptrs ((void **) paths, n_paths);
+      return NULL;
+    }
+#endif
 
   if (!compiler)
     fatal_error (input_location,
@@ -975,6 +984,7 @@ compile_images_for_offload_targets (unsigned in_argc, char *in_argv[],
   if (!target_names)
     return;
   unsigned num_targets = parse_env_var (target_names, &names, NULL);
+  int next_name_entry = 0;
 
   const char *compiler_path = getenv ("COMPILER_PATH");
   if (!compiler_path)
@@ -985,15 +995,28 @@ compile_images_for_offload_targets (unsigned in_argc, char *in_argv[],
   offload_names = XCNEWVEC (char *, num_targets + 1);
   for (unsigned i = 0; i < num_targets; i++)
     {
-      offload_names[i]
+      offload_names[next_name_entry]
        = compile_offload_image (names[i], compiler_path, in_argc, in_argv,
                                 compiler_opts, compiler_opt_count,
                                 linker_opts, linker_opt_count);
-      if (!offload_names[i])
+      if (!offload_names[next_name_entry])
+#if OFFLOAD_DEFAULTED
+       continue;
+#else
        fatal_error (input_location,
                     "problem with building target image for %s", names[i]);
+#endif
+      next_name_entry++;
     }
 
+#if OFFLOAD_DEFAULTED
+  if (next_name_entry == 0)
+    {
+      free (offload_names);
+      offload_names = NULL;
+    }
+#endif
+
  out:
   free_array_of_ptrs ((void **) names, num_targets);
 }
@@ -1303,8 +1326,6 @@ init_num_threads (void)
 #endif
 }
 
-/* FIXME: once using -std=c++11, we can use std::thread::hardware_concurrency.  */
-
 /* Test and return reason why a jobserver cannot be detected.  */
 
 static const char *
@@ -1584,8 +1605,9 @@ run_gcc (unsigned argc, char *argv[])
       if (jobserver && jobserver_error != NULL)
        {
          warning (0, jobserver_error);
-         parallel = 0;
+         /* Fall back to auto parallelism.  */
          jobserver = 0;
+         auto_parallel = 1;
        }
       else if (!jobserver && jobserver_error == NULL)
        {
@@ -1779,6 +1801,8 @@ cont1:
        {
          char buf[256];
          init_num_threads ();
+         if (nthreads_var == 0)
+           nthreads_var = 1;
          if (verbose)
            fprintf (stderr, "LTO parallelism level set to %ld\n",
                     nthreads_var);