Blame SOURCES/gcc7-foffload-default.patch

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