Blame SOURCES/gcc10-foffload-default.patch

12fb06
2019-01-17  Jakub Jelinek  <jakub@redhat.com>
12fb06
12fb06
	* gcc.c (offload_targets_default): New variable.
12fb06
	(process_command): Set it if -foffload is defaulted.
12fb06
	(driver::maybe_putenv_OFFLOAD_TARGETS): Add OFFLOAD_TARGET_DEFAULT=1
12fb06
	into environment if -foffload has been defaulted.
12fb06
	* lto-wrapper.c (OFFLOAD_TARGET_DEFAULT_ENV): Define.
12fb06
	(compile_offload_image): If OFFLOAD_TARGET_DEFAULT
12fb06
	is in the environment, don't fail if corresponding mkoffload
12fb06
	can't be found.
12fb06
	(compile_images_for_offload_targets): Likewise.  Free and clear
12fb06
	offload_names if no valid offload is found.
12fb06
libgomp/
12fb06
	* target.c (gomp_load_plugin_for_device): If a plugin can't be
12fb06
	dlopened, assume it has no devices silently.
12fb06
12fb06
--- gcc/gcc.c.jj	2017-01-17 10:28:40.000000000 +0100
12fb06
+++ gcc/gcc.c	2017-01-20 16:26:29.649962902 +0100
12fb06
@@ -290,6 +290,10 @@ static const char *spec_host_machine = D
12fb06
 
12fb06
 static char *offload_targets = NULL;
12fb06
 
12fb06
+/* Set to true if -foffload has not been used and offload_targets
12fb06
+   is set to the configured in default.  */
12fb06
+static bool offload_targets_default;
12fb06
+
12fb06
 /* Nonzero if cross-compiling.
12fb06
    When -b is used, the value comes from the `specs' file.  */
12fb06
 
12fb06
@@ -4457,7 +4461,10 @@ process_command (unsigned int decoded_op
12fb06
   /* If the user didn't specify any, default to all configured offload
12fb06
      targets.  */
12fb06
   if (ENABLE_OFFLOADING && offload_targets == NULL)
12fb06
-    handle_foffload_option (OFFLOAD_TARGETS);
12fb06
+    {
12fb06
+      handle_foffload_option (OFFLOAD_TARGETS);
12fb06
+      offload_targets_default = true;
12fb06
+    }
12fb06
 
12fb06
   if (output_file
12fb06
       && strcmp (output_file, "-") != 0
12fb06
@@ -7693,6 +7700,8 @@ driver::maybe_putenv_OFFLOAD_TARGETS ()
12fb06
       obstack_grow (&collect_obstack, offload_targets,
12fb06
 		    strlen (offload_targets) + 1);
12fb06
       xputenv (XOBFINISH (&collect_obstack, char *));
12fb06
+      if (offload_targets_default)
12fb06
+	  xputenv ("OFFLOAD_TARGET_DEFAULT=1");
12fb06
     }
12fb06
 
12fb06
   free (offload_targets);
12fb06
--- gcc/lto-wrapper.c.jj	2017-01-01 12:45:34.000000000 +0100
12fb06
+++ gcc/lto-wrapper.c	2017-01-20 16:34:18.294016997 +0100
12fb06
@@ -52,6 +52,7 @@ along with GCC; see the file COPYING3.
12fb06
 /* Environment variable, used for passing the names of offload targets from GCC
12fb06
    driver to lto-wrapper.  */
12fb06
 #define OFFLOAD_TARGET_NAMES_ENV	"OFFLOAD_TARGET_NAMES"
12fb06
+#define OFFLOAD_TARGET_DEFAULT_ENV	"OFFLOAD_TARGET_DEFAULT"
12fb06
 
12fb06
 enum lto_mode_d {
12fb06
   LTO_MODE_NONE,			/* Not doing LTO.  */
12fb06
@@ -822,6 +823,12 @@ compile_offload_image (const char *targe
12fb06
 	break;
12fb06
       }
12fb06
 
12fb06
+  if (!compiler && getenv (OFFLOAD_TARGET_DEFAULT_ENV))
12fb06
+    {
12fb06
+      free_array_of_ptrs ((void **) paths, n_paths);
12fb06
+      return NULL;
12fb06
+    }
12fb06
+
12fb06
   if (!compiler)
12fb06
     fatal_error (input_location,
12fb06
 		 "could not find %s in %s (consider using %<-B%>)",
12fb06
@@ -885,6 +892,7 @@ compile_images_for_offload_targets (unsi
12fb06
   unsigned num_targets = parse_env_var (target_names, &names, NULL);
12fb06
 
12fb06
   int next_name_entry = 0;
12fb06
+  bool hsa_seen = false;
12fb06
   const char *compiler_path = getenv ("COMPILER_PATH");
12fb06
   if (!compiler_path)
12fb06
     goto out;
12fb06
@@ -897,18 +905,26 @@ compile_images_for_offload_targets (unsi
12fb06
       /* HSA does not use LTO-like streaming and a different compiler, skip
12fb06
 	 it. */
12fb06
       if (strcmp (names[i], "hsa") == 0)
12fb06
-	continue;
12fb06
+	{
12fb06
+	  hsa_seen = true;
12fb06
+	  continue;
12fb06
+	}
12fb06
 
12fb06
       offload_names[next_name_entry]
12fb06
 	= compile_offload_image (names[i], compiler_path, in_argc, in_argv,
12fb06
 				 compiler_opts, compiler_opt_count,
12fb06
 				 linker_opts, linker_opt_count);
12fb06
       if (!offload_names[next_name_entry])
12fb06
-	fatal_error (input_location,
12fb06
-		     "problem with building target image for %s", names[i]);
12fb06
+	continue;
12fb06
       next_name_entry++;
12fb06
     }
12fb06
 
12fb06
+  if (next_name_entry == 0 && !hsa_seen)
12fb06
+    {
12fb06
+      free (offload_names);
12fb06
+      offload_names = NULL;
12fb06
+    }
12fb06
+
12fb06
  out:
12fb06
   free_array_of_ptrs ((void **) names, num_targets);
12fb06
 }
12fb06
--- libgomp/target.c.jj	2017-01-01 12:45:52.000000000 +0100
12fb06
+++ libgomp/target.c	2017-01-20 20:12:13.756710875 +0100
12fb06
@@ -2356,7 +2356,7 @@ gomp_load_plugin_for_device (struct gomp
12fb06
 
12fb06
   void *plugin_handle = dlopen (plugin_name, RTLD_LAZY);
12fb06
   if (!plugin_handle)
12fb06
-    goto dl_fail;
12fb06
+    return 0;
12fb06
 
12fb06
   /* Check if all required functions are available in the plugin and store
12fb06
      their handlers.  None of the symbols can legitimately be NULL,