Blame SOURCES/gcc8-foffload-default.patch

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