Blame SOURCES/gcc11-foffload-default.patch

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