From patchwork Tue Apr 9 17:06:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 88254 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5870B3858431 for ; Tue, 9 Apr 2024 17:06:47 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) by sourceware.org (Postfix) with ESMTPS id 3F2093858D20 for ; Tue, 9 Apr 2024 17:06:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3F2093858D20 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 3F2093858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::62b ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712682381; cv=none; b=sSoWcoSaaJtTC6LjHH8jh6xGSZakXoxGi4dj7EYX5PCmoBB91fGIYm06NO5b8v0PZfqZvTy2ZoZKI9fwaU4K67jwFZ6UCt8owEEtPJj58IF2ZxEZ+XltCdGj9DYwbwL7mSIoiqgn22AcR4mh88hxH/nr6+cyLfJhSm7LvwvGFcY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712682381; c=relaxed/simple; bh=kRH5ROv6tnllzKNKnDhLaPjYtLp2cIx6oYfuyo38PZs=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=tGfocFARluwY6cRWtiKBvDhMwsde8DGPOsuxCI6wOZnICxyyYdQrh3qZEBhF2Mebpm3h0t2QfTNc2Tr8rFEpE1tX1WJEFTwXUT18Zc7wWPCvJYYUhjRZAiuH3TpQgSpCkCc7dIgz3uudCzAgYGzdDL6vDNyKsQ8GlHSeVtnexW0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-1e3e56c9d2cso26338415ad.1 for ; Tue, 09 Apr 2024 10:06:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712682378; x=1713287178; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=y3Xsq39/yEBTauA6ftsNWCwznfbqOdPeWWjzwAwXTIE=; b=LxezxX7qY1d2GAxrGNzDRaTfS/wsrsf3+0bjhEgio/qo43T+1in1dydG9ekhLtR2Zh WUna5eeqKhXeenTa7kUeaBo5ngAzfH2O/Vlq5v53c/Vf7RQnymlgGm6hE7j6RCnGq82R qRhghiau6mzqUQbRdkkmSREHWxBZ3IHPXZ7ecS8PH9mRLqT/CkwB23s+frO5eyZYvS+q +tzTjcu7Xx3BbqhN+6l0hce/X4N6Ww2YY8zjZ8sHRde+aLRpSgwxIimBOc3OZjsbVZSg oyKWvCm0gqzN47bWleN8Zin62WoLQtxjglsCBr4bUL68UfLFUy8EXhRGGKjl+4PNsOvV PQJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712682378; x=1713287178; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=y3Xsq39/yEBTauA6ftsNWCwznfbqOdPeWWjzwAwXTIE=; b=vfyRyiQRV1U4CAtzYBFWXpA63tVrgKW1fDG7EDvLJjhwhcH3hweY+3S734CG3o3Yw1 JAKw/aQH4X3YvyPbsxuc0ySJJMDAVmQQFjnjhitflfLbeLa3ePuQgqCB5sRInkE4SR38 EIhzeDpfcwqQbL2cbOo+sIP4Co+1sNPs9spxnRneJOzcFxi/zoeiKHK6pflFRuXAoRim wTW4J3ZTNv3EVjn2Uu6C6Qfoscx6Aca1N/0JggVDyYO/tGr7vtdfLGF57oybQY8mKoxX M0gYTGk3IbqxQZqBeUrGV3U11Ja5rPRt8q6yAMSv81coBfcLAEpelZCCfSLGXM1ZtZUw 62QA== X-Gm-Message-State: AOJu0YzuUt5uydv8xUO5dR7DC0+t1hJdNu5jCFosBAdZ/VHIN7qxorVA UkcuFFc1VPzdrSDfL4YsOzoqPEet+yRbtiOfyM7UAlRhf/h+I8cA7GS4rJXe X-Google-Smtp-Source: AGHT+IGhfclBBHuBIi0hGePnKbMWuwN24IZ0iKzWh9/hBtrwG/BFavCHEVM8qzcyCLu2Ng7khniT+A== X-Received: by 2002:a17:903:120b:b0:1e3:ff5e:159f with SMTP id l11-20020a170903120b00b001e3ff5e159fmr478918plh.18.1712682377681; Tue, 09 Apr 2024 10:06:17 -0700 (PDT) Received: from gnu-cfl-3.localdomain ([172.56.169.48]) by smtp.gmail.com with ESMTPSA id i14-20020a17090332ce00b001e41f969997sm4519047plr.195.2024.04.09.10.06.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Apr 2024 10:06:17 -0700 (PDT) Received: from gnu-cfl-3.. (localhost [IPv6:::1]) by gnu-cfl-3.localdomain (Postfix) with ESMTP id A01E5740097; Tue, 9 Apr 2024 10:06:15 -0700 (PDT) From: "H.J. Lu" To: gcc-patches@gcc.gnu.org Cc: fweimer@redhat.com, jakub@redhat.com Subject: [PATCH] libgfortran: Disable gthreads weak symbols for glibc 2.34 Date: Tue, 9 Apr 2024 10:06:15 -0700 Message-ID: <20240409170615.1778896-1-hjl.tools@gmail.com> X-Mailer: git-send-email 2.44.0 MIME-Version: 1.0 X-Spam-Status: No, score=-3020.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_NUMSUBJECT, RCVD_IN_DNSWL_NONE, RCVD_IN_SBL_CSS, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Since Glibc 2.34 all pthreads symbols are defined directly in libc not libpthread, and since Glibc 2.32 we have used __libc_single_threaded to avoid unnecessary locking in single-threaded programs. This means there is no reason to avoid linking to libpthread now, and so no reason to use weak symbols defined in gthr-posix.h for all the pthread_xxx functions. Also add prune_warnings to libgomp.exp to prune glibc static link warning: .*: warning: Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version us ed for linking libgfortran/ PR libgfortran/114646 * acinclude.m4: Define GTHREAD_USE_WEAK 0 for glibc 2.34 or above on Linux. * configure: Regenerated. libgomp/ PR libgfortran/114646 * testsuite/lib/libgomp.exp (prune_warnings): New. * testsuite/libgomp.fortran/pr114646-1.f90: New test. * testsuite/libgomp.fortran/pr114646-2.f90: Likewise. --- libgfortran/acinclude.m4 | 14 +++++++++ libgfortran/configure | 29 +++++++++++++++++++ libgomp/testsuite/lib/libgomp.exp | 14 +++++++++ .../testsuite/libgomp.fortran/pr114646-1.f90 | 11 +++++++ .../testsuite/libgomp.fortran/pr114646-2.f90 | 22 ++++++++++++++ 5 files changed, 90 insertions(+) create mode 100644 libgomp/testsuite/libgomp.fortran/pr114646-1.f90 create mode 100644 libgomp/testsuite/libgomp.fortran/pr114646-2.f90 diff --git a/libgfortran/acinclude.m4 b/libgfortran/acinclude.m4 index a73207e5465..f4642494c4f 100644 --- a/libgfortran/acinclude.m4 +++ b/libgfortran/acinclude.m4 @@ -92,6 +92,20 @@ void foo (void); AC_DEFINE(GTHREAD_USE_WEAK, 0, [Define to 0 if the target shouldn't use #pragma weak]) ;; + *-*-linux*) + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ +#include +#if !__GLIBC_PREREQ(2, 34) +#error glibc version is too old +#endif +]], [[]])], + libgfor_cv_use_pragma_weak=no, + libgfor_cv_use_pragma_weak=yes) + if test $libgfor_cv_use_pragma_weak = no; then + AC_DEFINE(GTHREAD_USE_WEAK, 0, + [Define to 0 if the target shouldn't use #pragma weak]) + fi + ;; esac]) dnl Check whether target effectively supports weakref diff --git a/libgfortran/configure b/libgfortran/configure index 774dd52fc95..1f477256b75 100755 --- a/libgfortran/configure +++ b/libgfortran/configure @@ -31057,6 +31057,35 @@ $as_echo "#define SUPPORTS_WEAK 1" >>confdefs.h $as_echo "#define GTHREAD_USE_WEAK 0" >>confdefs.h + ;; + *-*-linux*) + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +#include +#if !__GLIBC_PREREQ(2, 34) +#error glibc version is too old +#endif + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + libgfor_cv_use_pragma_weak=no +else + libgfor_cv_use_pragma_weak=yes +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + if test $libgfor_cv_use_pragma_weak = no; then + +$as_echo "#define GTHREAD_USE_WEAK 0" >>confdefs.h + + fi ;; esac diff --git a/libgomp/testsuite/lib/libgomp.exp b/libgomp/testsuite/lib/libgomp.exp index cab926a798b..9cfa6d7b31d 100644 --- a/libgomp/testsuite/lib/libgomp.exp +++ b/libgomp/testsuite/lib/libgomp.exp @@ -54,6 +54,20 @@ set dg-do-what-default run set libgomp_compile_options "" +# Prune messages that aren't useful. + +proc prune_warnings { text } { + + verbose "prune_warnings: entry: $text" 2 + + # Ignore warning from -static: warning: Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking + regsub -all "(^|\n)\[^\n\]*: warning: Using 'dlopen' in statically linked\[^\n\]*" $text "" text + + verbose "prune_warnings: exit: $text" 2 + + return $text +} + # # libgomp_init # diff --git a/libgomp/testsuite/libgomp.fortran/pr114646-1.f90 b/libgomp/testsuite/libgomp.fortran/pr114646-1.f90 new file mode 100644 index 00000000000..a48e6103343 --- /dev/null +++ b/libgomp/testsuite/libgomp.fortran/pr114646-1.f90 @@ -0,0 +1,11 @@ +! PR libgfortran/114646 +! { dg-do run } +! { dg-additional-options "-static" } + +!$OMP PARALLEL +!$OMP CRITICAL + write(6,*) "Hello world" +!$OMP END CRITICAL +!$OMP END PARALLEL + write(6,*) "Done!" +END diff --git a/libgomp/testsuite/libgomp.fortran/pr114646-2.f90 b/libgomp/testsuite/libgomp.fortran/pr114646-2.f90 new file mode 100644 index 00000000000..8c0d7526f95 --- /dev/null +++ b/libgomp/testsuite/libgomp.fortran/pr114646-2.f90 @@ -0,0 +1,22 @@ +! PR libgfortran/114646 +! { dg-do run } +! { dg-additional-options "-static" } + + use omp_lib + implicit none + integer, parameter :: NT = 4 + integer :: nThreads(NT) + + print *, 'Call omp_set_dynamic' +!$ call omp_set_dynamic(.false.) + print *, 'Call omp_set_num_threads' +!$ call omp_set_num_threads(NT) + print *, 'Now enter the parallel region' + +!$omp parallel default(none) shared(nThreads) + nThreads(omp_get_thread_num()+1) = omp_get_num_threads() +!$omp end parallel + + print*, nThreads + + END