Blame SOURCES/gcc11-foffload-default.patch

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