Blame SOURCES/gcc11-foffload-default.patch

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