Blame SOURCES/gcc7-foffload-default.patch

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