From patchwork Fri Oct 2 10:57:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 1375652 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4C2n5M50Mvz9sPB for ; Fri, 2 Oct 2020 20:57:42 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BF949398C017; Fri, 2 Oct 2020 10:57:40 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from esa3.mentor.iphmx.com (esa3.mentor.iphmx.com [68.232.137.180]) by sourceware.org (Postfix) with ESMTPS id D9C56397240F for ; Fri, 2 Oct 2020 10:57:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org D9C56397240F Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=Tobias_Burnus@mentor.com IronPort-SDR: 5oaJoHYylJvmaTy0OPu4oRzDKxss3djtGL8akA6JVfJP/iDKL3O9JC03PhTqGQg5USBpZhuKLR LOfh8WKyHJRPk/Lc95tFuLIO+KTZ6PGe49p2k2k+Dd0GPJPznwV3SjIFTVkDLowg8UXoSO2rlq Q78fHVbKrRmJvAhXYyzQ/EMWf7adR9+x4FOA6ThLIVFf5+P3wFNVXU7f57D4OO9jLyKkK2Oi4O /i4YAj7RUYu+wjE98j+hct04ce7msFvmTI5BAGaWUbXumhrFIIvk9gdrA9+qxlack7Kiep775k bqs= X-IronPort-AV: E=Sophos;i="5.77,327,1596528000"; d="diff'?scan'208";a="53499144" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa3.mentor.iphmx.com with ESMTP; 02 Oct 2020 02:57:33 -0800 IronPort-SDR: kdbsf+bk6Ck3X3qCKW+72+neh4zveDeIcOwvmYwL8KQ+FmDfR8gplf8tK/wpFmzCo1FTTp3ft3 DaOQJGicL2GQYeQCqKtN6LM0W5vVs9TyMsYd0DHJP32raeCxySewv60fahCRasdxy5XizUV4dC +Cj3wSxKmr1hVWovaE/GDJcmuAy8HD+v5fgFHMZXpVob+vuwb7cXpGgnyL/35MJVFkDORcIHQE 6IUlyDGxsakwXiY6hEN8VVf4M/hz1XyXvZNcxz5DcWmi3UJyQ09S9mquDvOKgmFCCt/G8msvFD VpA= Subject: [Patch] libgomp: Add, if existing, -latomic to libgomp.spec --as-needed (was: Re: [RFC] Offloading and automatic linking of libraries) To: Jakub Jelinek References: <60309bf9-1d3a-7937-f4c6-3124ac01e422@codesourcery.com> From: Tobias Burnus Message-ID: Date: Fri, 2 Oct 2020 12:57:28 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.12.0 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: SVR-IES-MBX-08.mgc.mentorg.com (139.181.222.8) To svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, KAM_SHORT, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tobias Burnus , gcc-patches , Joseph Myers , Andrew Stubbs Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" 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="\ 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 @@ -11535,7 +11538,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 11538 "configure" +#line 11541 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -16756,6 +16759,99 @@ FCFLAGS="$FCFLAGS $CET_FLAGS" + + LIBATOMICSPEC= + libgomp_libatomic=no + + if echo " ${TARGET_CONFIGDIRS} " | grep " libatomic " > /dev/null 2>&1 ; then + libgomp_libatomic=yes; + fi + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for target-libatomic support" >&5 +$as_echo_n "checking for target-libatomic support... " >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $libgomp_libatomic" >&5 +$as_echo "$libgomp_libatomic" >&6; } + + if test "x$libgomp_libatomic" = xyes; then + ac_xsave_c_werror_flag=$ac_c_werror_flag + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether --as-needed/-z ignore works" >&5 +$as_echo_n "checking whether --as-needed/-z ignore works... " >&6; } +if ${libgomp_cv_have_as_needed+:} false; then : + $as_echo_n "(cached) " >&6 +else + + # 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_c_werror_flag=yes + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + libgomp_cv_have_as_needed=yes +else + libgomp_cv_have_as_needed=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + 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_c_werror_flag=yes + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + libgomp_cv_have_as_needed=yes +else + libgomp_cv_have_as_needed=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + LDFLAGS="$save_LDFLAGS" + fi + ac_c_werror_flag=$ac_xsave_c_werror_flag + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libgomp_cv_have_as_needed" >&5 +$as_echo "$libgomp_cv_have_as_needed" >&6; } + + 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 + + + + # Conditionalize the makefile for this target machine. tmake_file_= for f in ${tmake_file} diff --git a/libgomp/configure.ac b/libgomp/configure.ac index e4f30cbb082..2ee2c1a16d8 100644 --- a/libgomp/configure.ac +++ b/libgomp/configure.ac @@ -348,6 +348,8 @@ AC_SUBST(config_path) AC_SUBST(XCFLAGS) AC_SUBST(XLDFLAGS) +LIBGOMP_CHECK_LIBATOMIC + # Conditionalize the makefile for this target machine. tmake_file_= for f in ${tmake_file} diff --git a/libgomp/libgomp.spec.in b/libgomp/libgomp.spec.in index 5651603f487..c42d8b28848 100644 --- a/libgomp/libgomp.spec.in +++ b/libgomp/libgomp.spec.in @@ -1,3 +1,3 @@ # This spec file is read by gcc when linking. It is used to specify the # standard libraries we need in order to link with libgomp. -*link_gomp: @link_gomp@ +*link_gomp: @link_gomp@ @LIBATOMICSPEC@ diff --git a/libgomp/testsuite/Makefile.in b/libgomp/testsuite/Makefile.in index e48c3f2f9b0..cf2ce55d126 100644 --- a/libgomp/testsuite/Makefile.in +++ b/libgomp/testsuite/Makefile.in @@ -173,6 +173,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@