Blame SOURCES/gcc8-foffload-default.patch

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