Blame SOURCES/gcc11-foffload-default.patch

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