Blame SOURCES/gcc8-foffload-default.patch

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