diff mbox series

offload-defaulted: Config option to silently ignore uninstalled offload compilers

Message ID 15f34348-0053-2f31-0603-fd0eefa33897@codesourcery.com
State New
Headers show
Series offload-defaulted: Config option to silently ignore uninstalled offload compilers | expand

Commit Message

Tobias Burnus April 27, 2021, 10:22 a.m. UTC
This is based on Jakub's patch* which is used with many distributions – and is has
to be maintained by all of them; otherwise issues like lp #1878760 might creep in,
as discussed in #gcc yesterday. - As I am a huge fan of reducing code duplication
and local patches, I propose to add it to GCC proper behind a configure flag.

The patch idea is: offloading support is configured for one or multiple offload devices
but compilation silently ignores a target if its offload compiler is not found at
compile time and also dlopen errors of the associated libgomp plugin is also
silently ignored such that also the system where the program is run do not show
a run-time error.

This makes a lot of sense for distribution compilers – as it permits to configure
GCC to support offloading to one/multiple offload targets, but the actual
offload compiler and the run-time support can be put into separate, optional packages.

(When -foffload=$TARGET is specified explicitly, it still gives
an error if the offload compiler is not installed; this does not not affect the
libgomp/run-time side.)

However, for nondistro builds, compilers are usually installed "as is" and not
split into different packages – thus, compilation or run-time issues should give
an error.

Hence, the distro behaviour is only active when configured with
--enable-offload-defaulted.

Comments? OK for mainline?

Tobias
* https://src.fedoraproject.org/rpms/gcc/blob/rawhide/f/gcc11-foffload-default.patch

-----------------
Mentor Graphics (Deutschland) GmbH, Arnulfstrasse 201, 80634 München Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Frank Thürauf

Comments

Jakub Jelinek April 28, 2021, 2:05 p.m. UTC | #1
On Tue, Apr 27, 2021 at 12:22:44PM +0200, Tobias Burnus wrote:
> 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-27  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.
> 
> lto-plugin/ChangeLog:
> 
> 	* Makefile.in: Regenerate.
> 	* configure: Regenerate.
> 
> zlib/ChangeLog:
> 
> 	* configure: Regenerate.

I would probably not regenerate configure/Makefiles that haven't been
touched, so lto-plugin/* and zlib/* above.

Otherwise LGTM.

	Jakub
Matthias Klose April 28, 2021, 2:13 p.m. UTC | #2
On 4/27/21 12:22 PM, Tobias Burnus wrote:
> This is based on Jakub's patch* which is used with many distributions – and is has
> to be maintained by all of them; otherwise issues like lp #1878760 might creep in,
> as discussed in #gcc yesterday. - As I am a huge fan of reducing code duplication
> and local patches, I propose to add it to GCC proper behind a configure flag.
> 
> The patch idea is: offloading support is configured for one or multiple offload
> devices
> but compilation silently ignores a target if its offload compiler is not found at
> compile time and also dlopen errors of the associated libgomp plugin is also
> silently ignored such that also the system where the program is run do not show
> a run-time error.
> 
> This makes a lot of sense for distribution compilers – as it permits to configure
> GCC to support offloading to one/multiple offload targets, but the actual
> offload compiler and the run-time support can be put into separate, optional
> packages.
> 
> (When -foffload=$TARGET is specified explicitly, it still gives
> an error if the offload compiler is not installed; this does not not affect the
> libgomp/run-time side.)
> 
> However, for nondistro builds, compilers are usually installed "as is" and not
> split into different packages – thus, compilation or run-time issues should give
> an error.
> 
> Hence, the distro behaviour is only active when configured with
> --enable-offload-defaulted.
> 
> Comments? OK for mainline?

please document that option in gcc/doc/install.texi.

Matthias
Tobias Burnus April 28, 2021, 4:56 p.m. UTC | #3
On 28.04.21 16:13, Matthias Klose wrote:

> On 4/27/21 12:22 PM, Tobias Burnus wrote:
>> Hence, the distro behaviour is only active when configured with
>> --enable-offload-defaulted.
> please document that option in gcc/doc/install.texi.

Like attached? Or do you have some other wording suggestions?

Tobias

-----------------
Mentor Graphics (Deutschland) GmbH, Arnulfstrasse 201, 80634 München Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Frank Thürauf
Matthias Klose April 28, 2021, 4:59 p.m. UTC | #4
On 4/28/21 6:56 PM, Tobias Burnus wrote:
> On 28.04.21 16:13, Matthias Klose wrote:
> 
>> On 4/27/21 12:22 PM, Tobias Burnus wrote:
>>> Hence, the distro behaviour is only active when configured with
>>> --enable-offload-defaulted.
>> please document that option in gcc/doc/install.texi.
> 
> Like attached? Or do you have some other wording suggestions?

looks fine.
Jakub Jelinek April 28, 2021, 5:02 p.m. UTC | #5
On Wed, Apr 28, 2021 at 06:56:37PM +0200, Tobias Burnus wrote:
> On 28.04.21 16:13, Matthias Klose wrote:
> 
> > On 4/27/21 12:22 PM, Tobias Burnus wrote:
> > > Hence, the distro behaviour is only active when configured with
> > > --enable-offload-defaulted.
> > please document that option in gcc/doc/install.texi.
> 
> Like attached? Or do you have some other wording suggestions?
> 
> Tobias
> 
> -----------------
> Mentor Graphics (Deutschland) GmbH, Arnulfstrasse 201, 80634 München Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Frank Thürauf

> doc/install.texi: Document --enable-offload-defaulted config option
> 
> Document configure --enable-offload-defaulted option added in
> commit r12-218-gfe5bfa6704179f8db7d1ae0b485439e9896df8eb
> 
> gcc/ChangeLog:
> 
>         * doc/install.texi (--enable-offload-defaulted): Document.
> 
> diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi
> index 4c38244ae58..e5e26571eb1 100644
> --- a/gcc/doc/install.texi
> +++ b/gcc/doc/install.texi
> @@ -2239,6 +2239,12 @@ specifying paths @var{path1}, @dots{}, @var{pathN}.
>      --enable-offload-targets=x86_64-intelmicemul-linux-gnu=/path/to/x86_64/compiler,nvptx-none
>  @end smallexample
>  
> +@item --enable-offload-defaulted
> +
> +Tell GCC that configured but not installed offload compilers and libgomp
> +plugins are silently ignored.  Useful for distribution compilers where
> +those are in separate optional packages.

I'd add at the end
"and where the presence or absence of those optional packages should determine
the actual supported offloading target set rather than the GCC configure time
selection".

LGTM otherwise.

	Jakub
diff mbox series

Patch

diff --git a/configure b/configure
index 504f6410274..7dd1fd5bb69 100755
--- 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.
diff --git a/gcc/config.in b/gcc/config.in
index 313c13c8e49..fb88acb3c34 100644
--- a/gcc/config.in
+++ b/gcc/config.in
@@ -2190,6 +2190,12 @@ 
 #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
diff --git a/gcc/configure b/gcc/configure
index 33eae5451ad..f5bef76ef77 100755
--- a/gcc/configure
+++ b/gcc/configure
@@ -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
diff --git a/libgomp/Makefile.in b/libgomp/Makefile.in
index eb868b36704..9685704c355 100644
--- a/libgomp/Makefile.in
+++ b/libgomp/Makefile.in
@@ -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.
 #
diff --git a/libgomp/config.h.in b/libgomp/config.h.in
index 03123dc1e60..e702625ab6e 100644
--- a/libgomp/config.h.in
+++ b/libgomp/config.h.in
@@ -143,6 +143,9 @@ 
    */
 #undef LT_OBJDIR
 
+/* Define to 1 to if -foffload is defaulted */
+#undef OFFLOAD_DEFAULTED
+
 /* Define to offload plugins, separated by commas. */
 #undef OFFLOAD_PLUGINS
 
diff --git a/libgomp/configure b/libgomp/configure
index 1917d7e273b..6161da579c0 100755
--- a/libgomp/configure
+++ b/libgomp/configure
@@ -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]];'.
diff --git a/libgomp/configure.ac b/libgomp/configure.ac
index c23fe004f1d..7df80a32765 100644
--- a/libgomp/configure.ac
+++ b/libgomp/configure.ac
@@ -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])
diff --git a/lto-plugin/Makefile.in b/lto-plugin/Makefile.in
index 20611c6b1e6..b33ffed6e48 100644
--- a/lto-plugin/Makefile.in
+++ b/lto-plugin/Makefile.in
@@ -350,8 +350,8 @@  libexecsub_LTLIBRARIES = liblto_plugin.la
 in_gcc_libs = $(foreach lib, $(libexecsub_LTLIBRARIES), $(gcc_build_dir)/$(lib))
 liblto_plugin_la_SOURCES = lto-plugin.c
 # Note that we intentionally override the bindir supplied by ACX_LT_HOST_FLAGS.
-liblto_plugin_la_LDFLAGS = $(AM_LDFLAGS) $(lt_host_flags) -module -avoid-version \
-	-bindir $(libexecsubdir) $(if $(wildcard \
+liblto_plugin_la_LDFLAGS = $(AM_LDFLAGS) $(lt_host_flags) -module \
+	-avoid-version -bindir $(libexecsubdir) $(if $(wildcard \
 	$(libiberty_noasan)),, $(if $(wildcard \
 	$(libiberty_pic)),,-Wc,$(libiberty)))
 # Can be simplified when libiberty becomes a normal convenience library.
diff --git a/lto-plugin/configure b/lto-plugin/configure
index baa84adbb6c..22a4357a58e 100755
--- a/lto-plugin/configure
+++ b/lto-plugin/configure
@@ -8429,23 +8429,25 @@  _LT_EOF
 fi
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_ld_force_load" >&5
 $as_echo "$lt_cv_ld_force_load" >&6; }
-    case $host_os in
-    rhapsody* | darwin1.[012])
+    # Allow for Darwin 4-7 (macOS 10.0-10.3) although these are not expect to
+    # build without first building modern cctools / linker.
+    case $host_cpu-$host_os in
+    *-rhapsody* | *-darwin1.[012])
       _lt_dar_allow_undefined='${wl}-undefined ${wl}suppress' ;;
-    darwin1.*)
+    *-darwin1.*)
       _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' ;;
-    darwin*) # darwin 5.x on
-      # if running on 10.5 or later, the deployment target defaults
-      # to the OS version, if on x86, and 10.4, the deployment
-      # target defaults to 10.4. Don't you love it?
-      case ${MACOSX_DEPLOYMENT_TARGET-10.0},$host in
-	10.0,*86*-darwin8*|10.0,*-darwin[91]*)
-	  _lt_dar_allow_undefined='${wl}-undefined ${wl}dynamic_lookup' ;;
+    *-darwin*)
+      # darwin 5.x (macOS 10.1) onwards we only need to adjust when the
+      # deployment target is forced to an earlier version.
+      case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host in
+	UNSET,*-darwin[89]*|UNSET,*-darwin[12][0123456789]*)
+	  ;;
 	10.[012][,.]*)
-	  _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' ;;
-	10.*)
-	  _lt_dar_allow_undefined='${wl}-undefined ${wl}dynamic_lookup' ;;
-      esac
+	  _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress'
+	  ;;
+	*)
+	  ;;
+     esac
     ;;
   esac
     if test "$lt_cv_apple_cc_single_mod" = "yes"; then
@@ -11950,7 +11952,7 @@  else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11963 "configure"
+#line 11955 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -12056,7 +12058,7 @@  else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 12069 "configure"
+#line 12061 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
diff --git a/zlib/configure b/zlib/configure
index f489f31bc70..05c41b7e12d 100755
--- a/zlib/configure
+++ b/zlib/configure
@@ -4169,7 +4169,7 @@  case "$host" in
     case "$enable_cet" in
       auto)
 	# Check if target supports multi-byte NOPs
-	# and if assembler supports CET insn.
+	# and if compiler and assembler support CET insn.
 	cet_save_CFLAGS="$CFLAGS"
 	CFLAGS="$CFLAGS -fcf-protection"
 	cat confdefs.h - <<_ACEOF >conftest.$ac_ext
@@ -10735,7 +10735,7 @@  else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 10748 "configure"
+#line 10738 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -10841,7 +10841,7 @@  else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 10854 "configure"
+#line 10844 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H