Blame SOURCES/gcc10-foffload-default.patch

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