Blame SOURCES/gcc8-foffload-default.patch

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