Blame SOURCES/gcc9-foffload-default.patch

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