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