]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
offload-defaulted: Config option to silently ignore uninstalled offload compilers
authorTobias Burnus <tobias@codesourcery.com>
Wed, 28 Apr 2021 16:46:47 +0000 (18:46 +0200)
committerTobias Burnus <tobias@codesourcery.com>
Wed, 28 Apr 2021 16:46:47 +0000 (18:46 +0200)
If configured with --enable-offload-defaulted, configured but not installed
offload compilers and libgomp plugins are silently ignored.  Useful for
distribution compilers where those are in separate optional packages.

2021-04-28  Jakub Jelinek  <jakub@redhat.com>
    Tobias Burnus  <tobias@codesourcery.com>

ChangeLog:

* configure.ac (--enable-offload-defaulted): New.
* configure: Regenerate.

gcc/ChangeLog:

* configure.ac (OFFLOAD_DEFAULTED): AC_DEFINE if offload-defaulted.
* gcc.c (process_command): New variable.
(driver::maybe_putenv_OFFLOAD_TARGETS): If OFFLOAD_DEFAULTED,
set it if -foffload is defaulted.
* lto-wrapper.c (OFFLOAD_TARGET_DEFAULT_ENV): Define.
(compile_offload_image): If OFFLOAD_DEFAULTED and
OFFLOAD_TARGET_DEFAULT is in the environment, don't fail
if corresponding mkoffload can't be found.
(compile_images_for_offload_targets): Likewise.  Free and clear
offload_names if no valid offload is found.
* config.in: Regenerate.
* configure: Regenerate.

libgomp/ChangeLog:

* configure.ac (OFFLOAD_DEFAULTED): AC_DEFINE if offload-defaulted.
* target.c (gomp_load_plugin_for_device): If set and if a plugin
can't be dlopened, silently assume it has no devices.
* Makefile.in: Regenerate.
* config.h.in: Regenerate.
* configure: Regenerate.

12 files changed:
configure
configure.ac
gcc/config.in
gcc/configure
gcc/configure.ac
gcc/gcc.c
gcc/lto-wrapper.c
libgomp/Makefile.in
libgomp/config.h.in
libgomp/configure
libgomp/configure.ac
libgomp/target.c

index 504f6410274acdf97128a941e90a1c93cbb570f4..7dd1fd5bb6914d7626c086bf507593a14331bd9c 100755 (executable)
--- a/configure
+++ b/configure
@@ -786,6 +786,7 @@ with_build_libsubdir
 with_system_zlib
 enable_as_accelerator_for
 enable_offload_targets
+enable_offload_defaulted
 enable_gold
 enable_ld
 enable_compressed_debug_sections
@@ -1515,6 +1516,11 @@ Optional Features:
                           enable offloading to devices from comma-separated
                           LIST of TARGET[=DIR]. Use optional path to find
                           offload target compiler during the build
+  --enable-offload-defaulted
+               If enabled, configured but not installed offload compilers and
+               libgomp plugins are silently ignored.  Useful for distribution
+               compilers where those are in separate optional packages.
+
   --enable-gold[=ARG]     build gold [ARG={default,yes,no}]
   --enable-ld[=ARG]       build ld [ARG={default,yes,no}]
   --enable-compressed-debug-sections={all,gas,gold,ld,none}
@@ -2981,6 +2987,14 @@ else
 fi
 
 
+# Check whether --enable-offload-defaulted was given.
+if test "${enable_offload_defaulted+set}" = set; then :
+  enableval=$enable_offload_defaulted; enable_offload_defaulted=$enableval
+else
+  enable_offload_defaulted=
+fi
+
+
 # Handle --enable-gold, --enable-ld.
 # --disable-gold [--enable-ld]
 #     Build only ld.  Default option.
index 088e735c5dba53bb4b725a3e3a56e63c41378949..b923b0bb9ccdec3a263958938170f08de641d0fc 100644 (file)
@@ -300,6 +300,14 @@ AC_ARG_ENABLE(offload-targets,
   fi
 ], [enable_offload_targets=])
 
+AC_ARG_ENABLE(offload-defaulted,
+[AS_HELP_STRING([--enable-offload-defaulted]
+               [If enabled, configured but not installed offload compilers and
+               libgomp plugins are silently ignored.  Useful for distribution
+               compilers where those are in separate optional packages.])],
+[enable_offload_defaulted=$enableval],
+[enable_offload_defaulted=])
+
 # Handle --enable-gold, --enable-ld.
 # --disable-gold [--enable-ld]
 #     Build only ld.  Default option.
index 313c13c8e49b1b58534d6b737dd7f51e62b948a0..fb88acb3c34e67ccf0ebda560a3195a624a36397 100644 (file)
 #endif
 
 
+/* Define to 1 to if -foffload is defaulted */
+#ifndef USED_FOR_TARGET
+#undef OFFLOAD_DEFAULTED
+#endif
+
+
 /* Define to offload targets, separated by commas. */
 #ifndef USED_FOR_TARGET
 #undef OFFLOAD_TARGETS
index 33eae5451adc41135c8f3416d459553da86ea96b..f5bef76ef7765d8461af1302ba2837966705e51e 100755 (executable)
@@ -8058,6 +8058,12 @@ $as_echo "#define ENABLE_OFFLOADING 0" >>confdefs.h
 
 fi
 
+if test "x$enable_offload_defaulted" = xyes; then
+
+$as_echo "#define OFFLOAD_DEFAULTED 1" >>confdefs.h
+
+fi
+
 
 # Check whether --with-multilib-list was given.
 if test "${with_multilib_list+set}" = set; then :
@@ -19392,7 +19398,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 19395 "configure"
+#line 19401 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -19498,7 +19504,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 19501 "configure"
+#line 19507 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
index 96a6f62b0d37fae8faeff8172835c81a234789fb..22305e3707176c5056e1b0b1ab81827bc8485cb4 100644 (file)
@@ -1139,6 +1139,11 @@ else
     [Define this to enable support for offloading.])
 fi
 
+if test "x$enable_offload_defaulted" = xyes; then
+  AC_DEFINE(OFFLOAD_DEFAULTED, 1,
+    [Define to 1 to if -foffload is defaulted])
+fi
+
 AC_ARG_WITH(multilib-list,
 [AS_HELP_STRING([--with-multilib-list], [select multilibs (AArch64, SH and x86-64 only)])],
 :,
index 7837553958b44a124c7d710a6cea0b15d7a041e2..bd561ac570fbbbe2fd9997a86aef99a860c355da 100644 (file)
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -319,6 +319,12 @@ static const char *spec_host_machine = DEFAULT_REAL_TARGET_MACHINE;
 
 static char *offload_targets = NULL;
 
+#if OFFLOAD_DEFAULTED
+/* Set to true if -foffload has not been used and offload_targets
+   is set to the configured in default.  */
+static bool offload_targets_default;
+#endif
+
 /* Nonzero if cross-compiling.
    When -b is used, the value comes from the `specs' file.  */
 
@@ -4828,7 +4834,12 @@ process_command (unsigned int decoded_options_count,
   /* 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);
+#if OFFLOAD_DEFAULTED
+      offload_targets_default = true;
+#endif
+    }
 
   if (output_file
       && strcmp (output_file, "-") != 0
@@ -8484,6 +8495,10 @@ driver::maybe_putenv_OFFLOAD_TARGETS () const
       obstack_grow (&collect_obstack, offload_targets,
                    strlen (offload_targets) + 1);
       xputenv (XOBFINISH (&collect_obstack, char *));
+#if OFFLOAD_DEFAULTED
+      if (offload_targets_default)
+       xputenv ("OFFLOAD_TARGET_DEFAULT=1");
+#endif
     }
 
   free (offload_targets);
index 49894e4fc615f9f7b5e20b40a0ede19289d43dd7..e95b0d849baaee50cb317ce25df81925dddd8635 100644 (file)
@@ -52,6 +52,7 @@ along with GCC; see the file COPYING3.  If not see
 /* 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"
 
 /* By default there is no special suffix for target executables.  */
 #ifdef TARGET_EXECUTABLE_SUFFIX
@@ -906,6 +907,13 @@ compile_offload_image (const char *target, const char *compiler_path,
        compiler = paths[i];
        break;
       }
+#if OFFLOAD_DEFAULTED
+  if (!compiler && getenv (OFFLOAD_TARGET_DEFAULT_ENV))
+    {
+      free_array_of_ptrs ((void **) paths, n_paths);
+      return NULL;
+    }
+#endif
 
   if (!compiler)
     fatal_error (input_location,
@@ -976,6 +984,7 @@ compile_images_for_offload_targets (unsigned in_argc, char *in_argv[],
   if (!target_names)
     return;
   unsigned num_targets = parse_env_var (target_names, &names, NULL);
+  int next_name_entry = 0;
 
   const char *compiler_path = getenv ("COMPILER_PATH");
   if (!compiler_path)
@@ -986,15 +995,28 @@ compile_images_for_offload_targets (unsigned in_argc, char *in_argv[],
   offload_names = XCNEWVEC (char *, num_targets + 1);
   for (unsigned i = 0; i < num_targets; i++)
     {
-      offload_names[i]
+      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[i])
+      if (!offload_names[next_name_entry])
+#if OFFLOAD_DEFAULTED
+       continue;
+#else
        fatal_error (input_location,
                     "problem with building target image for %s", names[i]);
+#endif
+      next_name_entry++;
     }
 
+#if OFFLOAD_DEFAULTED
+  if (next_name_entry == 0)
+    {
+      free (offload_names);
+      offload_names = NULL;
+    }
+#endif
+
  out:
   free_array_of_ptrs ((void **) names, num_targets);
 }
index eb868b36704ac3c01c1c2270fdbcffd1edb708a4..9685704c355b374ee0ff3a52d4d629624fbecb6d 100644 (file)
@@ -16,7 +16,7 @@
 
 # Plugins for offload execution, Makefile.am fragment.
 #
-# Copyright (C) 2014-2020 Free Software Foundation, Inc.
+# Copyright (C) 2014-2021 Free Software Foundation, Inc.
 #
 # Contributed by Mentor Embedded.
 #
index 03123dc1e60c78e5d25b126d04929bdc2bae18f7..e702625ab6e2f4b1106389a12d8dd279dfd44857 100644 (file)
    */
 #undef LT_OBJDIR
 
+/* Define to 1 to if -foffload is defaulted */
+#undef OFFLOAD_DEFAULTED
+
 /* Define to offload plugins, separated by commas. */
 #undef OFFLOAD_PLUGINS
 
index 1917d7e273b0402b99d2c4d6d7d4df71569af885..6161da579c0e0448f6b37f461ec06270f36069b4 100755 (executable)
@@ -14995,6 +14995,12 @@ $as_echo "#define LIBGOMP_OFFLOADED_ONLY 1" >>confdefs.h
 
 fi
 
+if test "x$enable_offload_defaulted" = xyes; then
+
+$as_echo "#define OFFLOAD_DEFAULTED 1" >>confdefs.h
+
+fi
+
 # The cast to long int works around a bug in the HP C Compiler
 # version HP92453-01 B.11.11.23709.GP, which incorrectly rejects
 # declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'.
index c23fe004f1d9fcbdf0c2d951d20c8dec5bd43cca..7df80a32765e4d1fec10a0dfbe072b3a7ce4895a 100644 (file)
@@ -221,6 +221,11 @@ if test x$libgomp_offloaded_only = xyes; then
             [Define to 1 if building libgomp for an accelerator-only target.])
 fi
 
+if test "x$enable_offload_defaulted" = xyes; then
+  AC_DEFINE(OFFLOAD_DEFAULTED, 1,
+    [Define to 1 to if -foffload is defaulted])
+fi
+
 AC_CHECK_SIZEOF([void *])
 
 m4_include([plugin/configfrag.ac])
index 4a4e1f8074565c32f94a2ee01d674531df772091..2150e5d79b29e6df1e8ab8c370ab977ea367cab3 100644 (file)
@@ -3173,7 +3173,11 @@ gomp_load_plugin_for_device (struct gomp_device_descr *device,
 
   void *plugin_handle = dlopen (plugin_name, RTLD_LAZY);
   if (!plugin_handle)
+#if OFFLOAD_DEFAULTED
+    return 0;
+#else
     goto dl_fail;
+#endif
 
   /* Check if all required functions are available in the plugin and store
      their handlers.  None of the symbols can legitimately be NULL,