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