From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com [IPv6:2607:f8b0:4864:20::102e]) by sourceware.org (Postfix) with ESMTPS id 8719C385842A; Tue, 9 Apr 2024 17:25:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8719C385842A 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 8719C385842A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::102e ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712683547; cv=none; b=vOHtCayj7P7mIjk+HvWo3/fJJkfYAjeJa6w7YMsxEKhb7M4UMQTqWKXEdOopkp3KyfSfUV1xX8uZTkqJjkCEX3S9uYSPTZINtZN8BBH7sA0Cm3HUDJSaV6C4RCdjHX6bB3AawSshNDdZpDBbi6R9qWjW7On1uFvxPIlqORmcatQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712683547; c=relaxed/simple; bh=4VvEz4oZVSa+/MTfQKPnbHh+9i5uGMd/5tzDwK5Ibhc=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=R0uqAwc88gCqhb2zelSxgYbaZZyGbZQJZ+8yADmyWbbzfuqBLVOO4qWa1bbmgH6y80xYxKPZdP+LzJDpRldki3HtsK+xyFz2xu0eNyO4tnk4rUXv6jiOkis3wQxTMfoCSNtT73T6i4IwodVZY3CfYgYJ9mLxSdT7kgC2r/b3zJk= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pj1-x102e.google.com with SMTP id 98e67ed59e1d1-2a484f772e2so2747512a91.3; Tue, 09 Apr 2024 10:25:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712683543; x=1713288343; darn=gcc.gnu.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=Fm+NZQlqKEb0xQ38vfwlWg4mEzLEd8dnuIYz4M1gg5U=; b=gfoyuftt/AcEI5PlXtWY16AZ67bJ2sbNhAP1TX0RoXoTcAk+CaXRzg7XBWCBWE+xm/ OwHI8MXyXnJo+hhFny07lGkI+QCzLosua11oHaZg729WF5b0JIiJtRUWzqJFBmbDKlg3 JyT1GT5bMAOunjJ5hGDj4dbVQxCqzqDoVDmfSS23BfXE5EtPU7mKdgyD5s6DoVOmpGhv xB4KINf9TRH7D0ubvYN/tsMKfzLeG8yBvwyBcIK+9YVGVSgYCD3R6veJWnk9Al9EBUKX zcVmI1WmPwkFdxGcVSNSotUhdYj8IoXk7Wfic97XRbmFgIc/IsF2DwxEH2gwIHjTBG8o 3JqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712683543; x=1713288343; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Fm+NZQlqKEb0xQ38vfwlWg4mEzLEd8dnuIYz4M1gg5U=; b=I9RFeK3aCgN/HqFoVvTaWU1JygW/9P2b6B65zCcDIoGNktCdMfu+SABZFmY43quCil CXN0FAnDfhV/wcOTF6pRUe/FwWlFX6F0UKH/vfidhdi8niOZ+MG8CsH0LWG4ewG6Gx2D D/URsmdGmRJglleyTKBpWRvcOILIYCUK0qaFlOKYh10idPoBD2/vp85Y9e1sORsm/6l5 TS4Y/zbS8tlEisk0tKtYTlO1Ax9ftD6Atc4bvRJVk/zrjl8Jfvm3NBm9Wc251wB2DTG4 5hctLOQ7Yp54SS8/399OmqD892PrhoKaPxYCKgz4Ku9rhQuBdUV2EM2ameQdu04CeOQ+ /e4g== X-Forwarded-Encrypted: i=1; AJvYcCUhdcBOsR6syKXt5frH7KiUwncmc2zfOMNuR23x9ie7AdrrDA/CLNWff0kxJuMN4sO9wlfW9kb07cSypj+DVSJLm68G X-Gm-Message-State: AOJu0YxTgKL8BxjfhRyofsldUghia9LTaV1lbL1mgTedafvVd0KAvaMV Kr82ct0x/bnELDbUa4Xx1DOB6RRnYUgSnVJXWBZCi5Z6FNm+TLMglFjLr31uuK5I6L86Q0AFPd5 k8rxEqw2SYJWRdxjpokCTLHKSpUwaaO9A X-Google-Smtp-Source: AGHT+IHiOMvRj5IORatSgNmTpllN3GreBXZmai59WQdLWdfo0VXeARhiynNmvmo4h3e+Jr4ZBcSXAbFGxnqYYKRCftk= X-Received: by 2002:a17:90a:b898:b0:2a4:80c3:a858 with SMTP id o24-20020a17090ab89800b002a480c3a858mr278393pjr.44.1712683543424; Tue, 09 Apr 2024 10:25:43 -0700 (PDT) MIME-Version: 1.0 References: <20240409170615.1778896-1-hjl.tools@gmail.com> In-Reply-To: <20240409170615.1778896-1-hjl.tools@gmail.com> From: Andrew Pinski Date: Tue, 9 Apr 2024 10:25:32 -0700 Message-ID: Subject: Re: [PATCH] libgfortran: Disable gthreads weak symbols for glibc 2.34 To: "H.J. Lu" Cc: GCC Patches , Florian Weimer , Jakub Jelinek , "" Content-Type: multipart/alternative; boundary="00000000000037f8050615ad3672" X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,HTML_MESSAGE,KAM_NUMSUBJECT,RCVD_IN_DNSWL_NONE,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 List-Id: --00000000000037f8050615ad3672 Content-Type: text/plain; charset="UTF-8" On Tue, Apr 9, 2024, 10:07 H.J. Lu wrote: > 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. > First you forgot to cc fortran@. Second the issue is in gthrd-posix.h which should be fixed instead of libgfortran since the issue will also be seen with libobjc, and the other users of gthrd. Note the fix for libstdc++ was also done in the wrong location too and should have done once and for all in gthrd-posix.h. Thanks, Andrew > 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 > -- > 2.44.0 > > --00000000000037f8050615ad3672--