Re: [Patch] libgomp: Add, if existing, -latomic to libgomp.spec --as-needed (was: Re: [RFC] Offloading and automatic linking of libraries)
On Mon, Oct 12, 2020 at 05:51:17PM +0200, Tobias Burnus wrote: > first: *PING*. > > secondly, I think the change to testsuite/lib/libgomp.exp's libgomp_init > is also needed. > (Hence, I now added it.) I have a too new system-installed libatomic to > be sure that > it fails without. I think for libgomp.spec we should add it solely for the offloading targets, neither GCC generated code for OpenMP construct nor libgomp itself needs -latomic on the hosts. Otherwise, if we want to add it --as-needed for all targets that have it, it should be done in gcc/configure* and gcc/gcc.c (and adjust then the testsuites + document in release notes). That would really need e.g. packaging changes for distros because libatomic-devel wouldn't be optional anymore (and likely also the static version would be needed too). Jakub
Re: [Patch] libgomp: Add, if existing, -latomic to libgomp.spec --as-needed (was: Re: [RFC] Offloading and automatic linking of libraries)
Hi all, first: *PING*. secondly, I think the change to testsuite/lib/libgomp.exp's libgomp_init is also needed. (Hence, I now added it.) I have a too new system-installed libatomic to be sure that it fails without. OK? Tobias - Mentor Graphics (Deutschland) GmbH, Arnulfstraße 201, 80634 München / Germany Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Alexander Walter libgomp: Add, if existing, -latomic to libgomp.spec --as-needed libgomp/ChangeLog: * acinclude.m4 (LIBGOMP_CHECK_LIBATOMIC): New; set @LIBATOMICSPEC@ is the target libatomic is built. * configure.ac: Call LIBGOMP_CHECK_LIBATOMIC. * libgomp.spec.in: Add @LIBATOMICSPEC@. * testsuite/lib/libgomp.exp (libgomp_init): Add libatomic unconditionally if the lib exists. * Makefile.in: Regenerate. * configure: Regenerate. * testsuite/Makefile.in: Regenerate. libgomp/Makefile.in | 1 + libgomp/acinclude.m4 | 63 libgomp/configure | 100 +- libgomp/configure.ac | 2 + libgomp/libgomp.spec.in | 2 +- libgomp/testsuite/Makefile.in | 1 + libgomp/testsuite/lib/libgomp.exp | 20 7 files changed, 175 insertions(+), 14 deletions(-) diff --git a/libgomp/Makefile.in b/libgomp/Makefile.in index 00d5e2919ee..a8ec69f1822 100644 --- a/libgomp/Makefile.in +++ b/libgomp/Makefile.in @@ -395,6 +395,7 @@ INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ INTPTR_T_KIND = @INTPTR_T_KIND@ LD = @LD@ LDFLAGS = @LDFLAGS@ +LIBATOMICSPEC = @LIBATOMICSPEC@ LIBOBJS = @LIBOBJS@ LIBS = @LIBS@ LIBTOOL = @LIBTOOL@ diff --git a/libgomp/acinclude.m4 b/libgomp/acinclude.m4 index dbf54d06db9..3d7e5e08c3a 100644 --- a/libgomp/acinclude.m4 +++ b/libgomp/acinclude.m4 @@ -365,3 +365,66 @@ if test $enable_symvers != no ; then esac fi ]) + +dnl Check whether libatomic exists +AC_DEFUN([LIBGOMP_CHECK_LIBATOMIC], [ + LIBATOMICSPEC= + libgomp_libatomic=no + + if echo " ${TARGET_CONFIGDIRS} " | grep " libatomic " > /dev/null 2>&1 ; then +libgomp_libatomic=yes; + fi + + AC_MSG_CHECKING([for target-libatomic support]) + AC_MSG_RESULT([$libgomp_libatomic]) + + if test "x$libgomp_libatomic" = xyes; then +dnl Check whether -Wl,--as-needed resp. -Wl,-zignore is supported +dnl +dnl Turn warnings into error to avoid testsuite breakage. So enable +dnl AC_LANG_WERROR, but there's currently (autoconf 2.64) no way to turn +dnl it off again. As a workaround, save and restore werror flag like +dnl AC_PATH_XTRA. +dnl Cf. http://gcc.gnu.org/ml/gcc-patches/2010-05/msg01889.html +ac_xsave_[]_AC_LANG_ABBREV[]_werror_flag=$ac_[]_AC_LANG_ABBREV[]_werror_flag +AC_CACHE_CHECK([whether --as-needed/-z ignore works], + [libgomp_cv_have_as_needed], + [ + # Test for native Solaris options first. + # No whitespace after -z to pass it through -Wl. + libgomp_cv_as_needed_option="-zignore" + libgomp_cv_no_as_needed_option="-zrecord" + save_LDFLAGS="$LDFLAGS" + LDFLAGS="$LDFLAGS -Wl,$libgomp_cv_as_needed_option -lm -Wl,$libompr_cv_no_as_needed_option" + libgomp_cv_have_as_needed=no + AC_LANG_WERROR + AC_LINK_IFELSE([AC_LANG_PROGRAM([])], + [libgomp_cv_have_as_needed=yes], + [libgomp_cv_have_as_needed=no]) + LDFLAGS="$save_LDFLAGS" + if test "x$libgomp_cv_have_as_needed" = xno; then + libgomp_cv_as_needed_option="--as-needed" + libgomp_cv_no_as_needed_option="--no-as-needed" + save_LDFLAGS="$LDFLAGS" + LDFLAGS="$LDFLAGS -Wl,$libgomp_cv_as_needed_option -lm -Wl,$libgomp_cv_no_as_needed_option" + libgomp_cv_have_as_needed=no + AC_LANG_WERROR + AC_LINK_IFELSE([AC_LANG_PROGRAM([])], + [libgomp_cv_have_as_needed=yes], + [libgomp_cv_have_as_needed=no]) + LDFLAGS="$save_LDFLAGS" + fi + ac_[]_AC_LANG_ABBREV[]_werror_flag=$ac_xsave_[]_AC_LANG_ABBREV[]_werror_flag +]) + +dnl For static libgfortran linkage, depend on libquadmath only if needed. +if test "x$libgomp_cv_have_as_needed" = xyes; then + LIBATOMICSPEC="$libgomp_cv_as_needed_option -latomic $libgomp_cv_no_as_needed_option" +else + LIBATOMICSPEC="-latomic" +fi + fi + + dnl For the spec file + AC_SUBST(LIBATOMICSPEC) +]) diff --git a/libgomp/configure b/libgomp/configure index e48371d5093..a4d93974084 100755 --- a/libgomp/configure +++ b/libgomp/configure @@ -630,6 +630,8 @@ ac_includes_default="\ ac_header_list= ac_func_list= +ac_c_werror_flag= +ac_c_werror_flag= ac_subst_vars='am__EXEEXT_FALSE am__EXEEXT_TRUE LTLIBOBJS @@ -653,6 +655,7 @@ USE_FORTRAN_FALSE USE_FORTRAN_TRUE link_gomp tmake_file +LIBATOMICSPEC XLDFLAGS XCFLAGS config_path @@ -11429,7 +11432,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 11432 "configure" +#line 11435 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@
Re: [Patch] libgomp: Add, if existing, -latomic to libgomp.spec --as-needed (was: Re: [RFC] Offloading and automatic linking of libraries)
On Fri, Oct 02, 2020 at 05:33:13PM +, Joseph Myers wrote: > On Fri, 2 Oct 2020, Tobias Burnus wrote: > > > However, this flag can be added into the offload-target's libgomp.spec, > > which avoids all kind of issues. That's what this patch now does. > > > > I tested it with x86_64-gnu-linux w/o + w/ nvptx-none. Result: > > * x86_64-gnu-linux's libgomp.spec: > > "*link_gomp: -lgomp %{static: -ldl } --as-needed -latomic --no-as-needed" > > * nvptx-none's libgomp.spec: > > "*link_gomp: -lgomp -latomic" > > > > On x86-64, a simple test program did not use and also did not link > > libatomic. > > > > OK? > > Do all testsuites that link using libgomp.spec also use the testsuite > logic from atomic-dg.exp to locate libatomic for build-tree testing > (otherwise -latomic will fail if it can't be found and there isn't an > installed system copy that the driver might fall back on, even with > --as-needed)? The only testsuite that uses libgomp.spec is libgomp/testsuite/, the gcc/testsuite/ tests if they test -fopenmp must be only dg-do compile tests, all the link and runtime tests are in libgomp. There is no ordering between libatomic and libgomp build, so we shouldn't be querying libatomic in libgomp configury. Not sure if we can rely on if libatomic is among configdirs then libatomic will be actually built. Jakub
Re: [Patch] libgomp: Add, if existing, -latomic to libgomp.spec --as-needed (was: Re: [RFC] Offloading and automatic linking of libraries)
On Fri, 2 Oct 2020, Tobias Burnus wrote: > However, this flag can be added into the offload-target's libgomp.spec, > which avoids all kind of issues. That's what this patch now does. > > I tested it with x86_64-gnu-linux w/o + w/ nvptx-none. Result: > * x86_64-gnu-linux's libgomp.spec: > "*link_gomp: -lgomp %{static: -ldl } --as-needed -latomic --no-as-needed" > * nvptx-none's libgomp.spec: > "*link_gomp: -lgomp -latomic" > > On x86-64, a simple test program did not use and also did not link libatomic. > > OK? Do all testsuites that link using libgomp.spec also use the testsuite logic from atomic-dg.exp to locate libatomic for build-tree testing (otherwise -latomic will fail if it can't be found and there isn't an installed system copy that the driver might fall back on, even with --as-needed)? My view as noted in bug 81358 is that --as-needed -latomic --no-as-needed should *always* be used (given --as-needed supported and libatomic built), not restricted to when libgomp is needed. But while adding it only for libgomp might make a useful improvement while reducing the extent to which global testsuite / configure test changes need to be made at the same time, some testsuite support should still be needed if not already in use. -- Joseph S. Myers jos...@codesourcery.com
[Patch] libgomp: Add, if existing, -latomic to libgomp.spec --as-needed (was: Re: [RFC] Offloading and automatic linking of libraries)
On 10/2/20 12:55 AM, Joseph Myers wrote: As discussed in bug 81358, I think --as-needed -latomic --no-as-needed should be used by the driver by default (when the compiler is configured with libatomic supported). I make a thinko initially by believing that the '-latomic' has to be specified by the user-invoked compiler via -foffload=-latomic' and that had to be put into the .spec file, causing all kind of problems. However, this flag can be added into the offload-target's libgomp.spec, which avoids all kind of issues. That's what this patch now does. I tested it with x86_64-gnu-linux w/o + w/ nvptx-none. Result: * x86_64-gnu-linux's libgomp.spec: "*link_gomp: -lgomp %{static: -ldl } --as-needed -latomic --no-as-needed" * nvptx-none's libgomp.spec: "*link_gomp: -lgomp -latomic" On x86-64, a simple test program did not use and also did not link libatomic. OK? Tobias - Mentor Graphics (Deutschland) GmbH, Arnulfstraße 201, 80634 München / Germany Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Alexander Walter libgomp: Add, if existing, -latomic to libgomp.spec --as-needed libgomp/ChangeLog: * acinclude.m4 (LIBGOMP_CHECK_LIBATOMIC): New; set @LIBATOMICSPEC@ is the target libatomic is built. * configure.ac: Call LIBGOMP_CHECK_LIBATOMIC. * libgomp.spec.in: Add @LIBATOMICSPEC@. * Makefile.in: Regenerate. * configure: Regenerate. * testsuite/Makefile.in: Regenerate. libgomp/Makefile.in | 1 + libgomp/acinclude.m4 | 63 ++ libgomp/configure | 100 +- libgomp/configure.ac | 2 + libgomp/libgomp.spec.in | 2 +- libgomp/testsuite/Makefile.in | 1 + 6 files changed, 166 insertions(+), 3 deletions(-) diff --git a/libgomp/Makefile.in b/libgomp/Makefile.in index 00d5e2919ee..a8ec69f1822 100644 --- a/libgomp/Makefile.in +++ b/libgomp/Makefile.in @@ -395,6 +395,7 @@ INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ INTPTR_T_KIND = @INTPTR_T_KIND@ LD = @LD@ LDFLAGS = @LDFLAGS@ +LIBATOMICSPEC = @LIBATOMICSPEC@ LIBOBJS = @LIBOBJS@ LIBS = @LIBS@ LIBTOOL = @LIBTOOL@ diff --git a/libgomp/acinclude.m4 b/libgomp/acinclude.m4 index dbf54d06db9..3d7e5e08c3a 100644 --- a/libgomp/acinclude.m4 +++ b/libgomp/acinclude.m4 @@ -365,3 +365,66 @@ if test $enable_symvers != no ; then esac fi ]) + +dnl Check whether libatomic exists +AC_DEFUN([LIBGOMP_CHECK_LIBATOMIC], [ + LIBATOMICSPEC= + libgomp_libatomic=no + + if echo " ${TARGET_CONFIGDIRS} " | grep " libatomic " > /dev/null 2>&1 ; then +libgomp_libatomic=yes; + fi + + AC_MSG_CHECKING([for target-libatomic support]) + AC_MSG_RESULT([$libgomp_libatomic]) + + if test "x$libgomp_libatomic" = xyes; then +dnl Check whether -Wl,--as-needed resp. -Wl,-zignore is supported +dnl +dnl Turn warnings into error to avoid testsuite breakage. So enable +dnl AC_LANG_WERROR, but there's currently (autoconf 2.64) no way to turn +dnl it off again. As a workaround, save and restore werror flag like +dnl AC_PATH_XTRA. +dnl Cf. http://gcc.gnu.org/ml/gcc-patches/2010-05/msg01889.html +ac_xsave_[]_AC_LANG_ABBREV[]_werror_flag=$ac_[]_AC_LANG_ABBREV[]_werror_flag +AC_CACHE_CHECK([whether --as-needed/-z ignore works], + [libgomp_cv_have_as_needed], + [ + # Test for native Solaris options first. + # No whitespace after -z to pass it through -Wl. + libgomp_cv_as_needed_option="-zignore" + libgomp_cv_no_as_needed_option="-zrecord" + save_LDFLAGS="$LDFLAGS" + LDFLAGS="$LDFLAGS -Wl,$libgomp_cv_as_needed_option -lm -Wl,$libompr_cv_no_as_needed_option" + libgomp_cv_have_as_needed=no + AC_LANG_WERROR + AC_LINK_IFELSE([AC_LANG_PROGRAM([])], + [libgomp_cv_have_as_needed=yes], + [libgomp_cv_have_as_needed=no]) + LDFLAGS="$save_LDFLAGS" + if test "x$libgomp_cv_have_as_needed" = xno; then + libgomp_cv_as_needed_option="--as-needed" + libgomp_cv_no_as_needed_option="--no-as-needed" + save_LDFLAGS="$LDFLAGS" + LDFLAGS="$LDFLAGS -Wl,$libgomp_cv_as_needed_option -lm -Wl,$libgomp_cv_no_as_needed_option" + libgomp_cv_have_as_needed=no + AC_LANG_WERROR + AC_LINK_IFELSE([AC_LANG_PROGRAM([])], + [libgomp_cv_have_as_needed=yes], + [libgomp_cv_have_as_needed=no]) + LDFLAGS="$save_LDFLAGS" + fi + ac_[]_AC_LANG_ABBREV[]_werror_flag=$ac_xsave_[]_AC_LANG_ABBREV[]_werror_flag +]) + +dnl For static libgfortran linkage, depend on libquadmath only if needed. +if test "x$libgomp_cv_have_as_needed" = xyes; then + LIBATOMICSPEC="$libgomp_cv_as_needed_option -latomic $libgomp_cv_no_as_needed_option" +else + LIBATOMICSPEC="-latomic" +fi + fi + + dnl For the spec file + AC_SUBST(LIBATOMICSPEC) +]) diff --git a/libgomp/configure b/libgomp/configure index e48371d5093..a4d93974084 100755 --- a/libgomp/configure +++ b/libgomp/configure @@ -630,6 +630,8 @@ ac_includes_default="\