Blame SOURCES/gcc7-foffload-default.patch

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