summaryrefslogtreecommitdiff
path: root/debian/patches/gcc-foffload-default.diff
blob: 1ad0556e62bf6fe8409c0ae7faca23407d9d7658 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# DP: Allow setting offload targets by OFFLOAD_TARGET_DEFAULT

http://pkgs.fedoraproject.org/cgit/rpms/gcc.git/tree/gcc7-foffload-default.patch

2017-01-20  Jakub Jelinek  <jakub@redhat.com>

	* gcc.c (offload_targets_default): New variable.
	(process_command): Set it if -foffload is defaulted.
	(driver::maybe_putenv_OFFLOAD_TARGETS): Add OFFLOAD_TARGET_DEFAULT=1
	into environment if -foffload has been defaulted.
	* lto-wrapper.c (OFFLOAD_TARGET_DEFAULT_ENV): Define.
	(compile_images_for_offload_targets): If OFFLOAD_TARGET_DEFAULT
	is in the environment, don't fail if corresponding mkoffload
	can't be found.  Free and clear offload_names if no valid offload
	is found.
libgomp/
	* target.c (gomp_load_plugin_for_device): If a plugin can't be
	dlopened, assume it has no devices silently.

--- a/src/gcc/gcc.c
+++ b/src/gcc/gcc.c
@@ -301,6 +301,10 @@ static const char *spec_host_machine = D
 
 static char *offload_targets = NULL;
 
+/* Set to true if -foffload has not been used and offload_targets
+   is set to the configured in default.  */
+static bool offload_targets_default;
+
 /* Nonzero if cross-compiling.
    When -b is used, the value comes from the `specs' file.  */
 
@@ -4680,7 +4684,10 @@ process_command (unsigned int decoded_op
   /* If the user didn't specify any, default to all configured offload
      targets.  */
   if (ENABLE_OFFLOADING && offload_targets == NULL)
-    handle_foffload_option (OFFLOAD_TARGETS);
+    {
+      handle_foffload_option (OFFLOAD_TARGETS);
+      offload_targets_default = true;
+    }
 
   if (output_file
       && strcmp (output_file, "-") != 0
@@ -7898,6 +7905,8 @@ driver::maybe_putenv_OFFLOAD_TARGETS ()
       obstack_grow (&collect_obstack, offload_targets,
 		    strlen (offload_targets) + 1);
       xputenv (XOBFINISH (&collect_obstack, char *));
+      if (offload_targets_default)
+	xputenv ("OFFLOAD_TARGET_DEFAULT=1");
     }
 
   free (offload_targets);
--- a/src/gcc/lto-wrapper.c
+++ b/src/gcc/lto-wrapper.c
@@ -52,6 +52,7 @@ along with GCC; see the file COPYING3.
 /* Environment variable, used for passing the names of offload targets from GCC
    driver to lto-wrapper.  */
 #define OFFLOAD_TARGET_NAMES_ENV	"OFFLOAD_TARGET_NAMES"
+#define OFFLOAD_TARGET_DEFAULT_ENV	"OFFLOAD_TARGET_DEFAULT"
 
 enum lto_mode_d {
   LTO_MODE_NONE,			/* Not doing LTO.  */
@@ -881,8 +882,10 @@ compile_images_for_offload_targets (unsi
   if (!target_names)
     return;
   unsigned num_targets = parse_env_var (target_names, &names, NULL);
+  const char *target_names_default = getenv (OFFLOAD_TARGET_DEFAULT_ENV);
 
   int next_name_entry = 0;
+  bool hsa_seen = false;
   const char *compiler_path = getenv ("COMPILER_PATH");
   if (!compiler_path)
     goto out;
@@ -895,18 +898,32 @@ compile_images_for_offload_targets (unsi
       /* HSA does not use LTO-like streaming and a different compiler, skip
 	 it. */
       if (strcmp (names[i], "hsa") == 0)
-	continue;
+	{
+	  hsa_seen = true;
+	  continue;
+	}
 
       offload_names[next_name_entry]
 	= compile_offload_image (names[i], compiler_path, in_argc, in_argv,
 				 compiler_opts, compiler_opt_count,
 				 linker_opts, linker_opt_count);
       if (!offload_names[next_name_entry])
-	fatal_error (input_location,
-		     "problem with building target image for %s\n", names[i]);
+	{
+	  if (target_names_default != NULL)
+	    continue;
+	  fatal_error (input_location,
+		       "problem with building target image for %s\n",
+		       names[i]);
+	}
       next_name_entry++;
     }
 
+  if (next_name_entry == 0 && !hsa_seen)
+    {
+      free (offload_names);
+      offload_names = NULL;
+    }
+
  out:
   free_array_of_ptrs ((void **) names, num_targets);
 }
--- a/src/libgomp/target.c
+++ b/src/libgomp/target.c
@@ -2592,7 +2592,7 @@ gomp_load_plugin_for_device (struct gomp
 
   void *plugin_handle = dlopen (plugin_name, RTLD_LAZY);
   if (!plugin_handle)
-    goto dl_fail;
+    return 0;
 
   /* Check if all required functions are available in the plugin and store
      their handlers.  None of the symbols can legitimately be NULL,