Blame SOURCES/gcc7-foffload-default.patch

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