Blame SOURCES/gcc8-foffload-default.patch

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