From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS22989 209.51.188.0/24 X-Spam-Status: No, score=-3.7 required=3.0 tests=AWL,BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, NICE_REPLY_A,RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL, SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 7835B1F5AE for ; Sat, 17 Jul 2021 16:21:35 +0000 (UTC) Received: from localhost ([::1]:55318 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m4n4I-00050l-AC for normalperson@yhbt.net; Sat, 17 Jul 2021 12:21:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48980) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m4n4D-00050G-77 for bug-gnulib@gnu.org; Sat, 17 Jul 2021 12:21:29 -0400 Received: from mo4-p00-ob.smtp.rzone.de ([81.169.146.162]:21566) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m4n4A-0007rx-CM for bug-gnulib@gnu.org; Sat, 17 Jul 2021 12:21:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1626538883; s=strato-dkim-0002; d=clisp.org; h=References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=ms6zuyhpRBadLQaViyKBppZ2yVVR/Xq62gwXmyV3cAI=; b=Oo63JH8BdRjkUQBqGGBWyPYXSp+0+nyoVN6/3T1e42EQ6aNZf4g5TC5Tjhef5h1rz3 LF45XbJcw40U2duSA7OTF6uwMgR6pJhP66N755KNoI4gkaj3nKMeJuCDYcse7plKSpIq C5z0yLDJwSPy5klV4e/7VGFjJQOWduHBrth71Qc0WYOckqr1lvj2/9fbB9skkgm2oi8r h02AX+XzCgm6q2hBlzqSTUyC0GXnDCru1uBig9/SWeCcqvZ6qJM7ubAIMqnILaeemomI zD9aom8bBk2fIrz9gpHBSBpNxFQms5IUSfAgPk1D2BUYUS7GT4SJtXidxK92LPT3qgL5 HDPg== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":Ln4Re0+Ic/6oZXR1YgKryK8brlshOcZlIWs+iCP5vnk6shH/DXj0JGsbh0vbrMZq" X-RZG-CLASS-ID: mo00 Received: from bruno.haible.de by smtp.strato.de (RZmta 47.28.1 DYNA|AUTH) with ESMTPSA id u08ae3x6HGLMFLu (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (curve X9_62_prime256v1 with 256 ECDH bits, eq. 3072 bits RSA)) (Client did not present a certificate); Sat, 17 Jul 2021 18:21:22 +0200 (CEST) From: Bruno Haible To: Florian Weimer Subject: Re: Undefined use of weak symbols in gnulib Date: Sat, 17 Jul 2021 18:21:22 +0200 Message-ID: <1895400.xVMIPgDotN@omega> User-Agent: KMail/5.1.3 (Linux/4.4.0-210-generic; KDE/5.18.0; x86_64; ; ) In-Reply-To: <87a6piluow.fsf@oldenburg.str.redhat.com> References: <87o8e0p92r.fsf@oldenburg.str.redhat.com> <1680226.UWtE2gOZdF@omega> <87a6piluow.fsf@oldenburg.str.redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Received-SPF: none client-ip=81.169.146.162; envelope-from=bruno@clisp.org; helo=mo4-p00-ob.smtp.rzone.de X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, NICE_REPLY_A=-0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: bug-gnulib@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Gnulib discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: bug-gnulib@gnu.org Errors-To: bug-gnulib-bounces+normalperson=yhbt.net@gnu.org Sender: "bug-gnulib" Florian Weimer wrote on 2021-04-28: > However, you should really remove those weak symbol > hacks. They won't have any effect for glibc 2.34 Done as follows. Tested on a Fedora Rawhide from today. Thanks for the suggestion. 2021-07-17 Bruno Haible Don't use '#pragma weak' for thread functions in Linux/glibc>=2.34. Suggested by Florian Weimer in . * m4/threadlib.m4 (gl_PTHREADLIB_BODY): Set gl_pthread_in_glibc and set LIBPMULTITHREAD accordingly. (gl_STDTHREADLIB_BODY): Update comments. (gl_THREADLIB_BODY): Define USE_POSIX_THREADS_FROM_LIBC. * lib/glthread/thread.h (c11_threads_in_use): Define to 1 if all POSIX thread functions are in libc. * lib/glthread/lock.h (c11_threads_in_use): Likewise. * lib/glthread/cond.h (c11_threads_in_use): Likewise. * lib/glthread/tls.h (c11_threads_in_use): Likewise. diff --git a/lib/glthread/cond.h b/lib/glthread/cond.h index 9858425..fbab08c 100644 --- a/lib/glthread/cond.h +++ b/lib/glthread/cond.h @@ -56,7 +56,9 @@ #include "glthread/lock.h" #if !defined c11_threads_in_use -# if HAVE_THREADS_H && USE_POSIX_THREADS_WEAK +# if HAVE_THREADS_H && USE_POSIX_THREADS_FROM_LIBC +# define c11_threads_in_use() 1 +# elif HAVE_THREADS_H && USE_POSIX_THREADS_WEAK # include # pragma weak thrd_exit # define c11_threads_in_use() (thrd_exit != NULL) diff --git a/lib/glthread/lock.h b/lib/glthread/lock.h index 624ce67..cc4c519 100644 --- a/lib/glthread/lock.h +++ b/lib/glthread/lock.h @@ -81,7 +81,9 @@ #include #if !defined c11_threads_in_use -# if HAVE_THREADS_H && USE_POSIX_THREADS_WEAK +# if HAVE_THREADS_H && USE_POSIX_THREADS_FROM_LIBC +# define c11_threads_in_use() 1 +# elif HAVE_THREADS_H && USE_POSIX_THREADS_WEAK # include # pragma weak thrd_exit # define c11_threads_in_use() (thrd_exit != NULL) diff --git a/lib/glthread/thread.h b/lib/glthread/thread.h index 3e84599..44f05f3 100644 --- a/lib/glthread/thread.h +++ b/lib/glthread/thread.h @@ -74,7 +74,9 @@ #include #if !defined c11_threads_in_use -# if HAVE_THREADS_H && USE_POSIX_THREADS_WEAK +# if HAVE_THREADS_H && USE_POSIX_THREADS_FROM_LIBC +# define c11_threads_in_use() 1 +# elif HAVE_THREADS_H && USE_POSIX_THREADS_WEAK # include # pragma weak thrd_exit # define c11_threads_in_use() (thrd_exit != NULL) diff --git a/lib/glthread/tls.h b/lib/glthread/tls.h index 9c2a280..aaaa4b6 100644 --- a/lib/glthread/tls.h +++ b/lib/glthread/tls.h @@ -47,7 +47,9 @@ #include #if !defined c11_threads_in_use -# if HAVE_THREADS_H && USE_POSIX_THREADS_WEAK +# if HAVE_THREADS_H && USE_POSIX_THREADS_FROM_LIBC +# define c11_threads_in_use() 1 +# elif HAVE_THREADS_H && USE_POSIX_THREADS_WEAK # include # pragma weak thrd_exit # define c11_threads_in_use() (thrd_exit != NULL) diff --git a/m4/threadlib.m4 b/m4/threadlib.m4 index 8fc3dfd..37b797c 100644 --- a/m4/threadlib.m4 +++ b/m4/threadlib.m4 @@ -1,4 +1,4 @@ -# threadlib.m4 serial 30 +# threadlib.m4 serial 31 dnl Copyright (C) 2005-2021 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -212,6 +212,27 @@ AC_DEFUN([gl_PTHREADLIB_BODY], LIBS=$save_LIBS test $gl_pthread_api = yes && break done + echo "$as_me:__oline__: gl_pthread_api=$gl_pthread_api" >&AS_MESSAGE_LOG_FD + echo "$as_me:__oline__: LIBPTHREAD=$LIBPTHREAD" >&AS_MESSAGE_LOG_FD + + gl_pthread_in_glibc=no + # On Linux with glibc >= 2.34, libc contains the fully functional + # pthread functions. + case "$host_os" in + linux*) + AC_EGREP_CPP([Lucky user], + [#include + #ifdef __GNU_LIBRARY__ + #if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 34) || (__GLIBC__ > 2) + Lucky user + #endif + #endif + ], + [gl_pthread_in_glibc=yes], + []) + ;; + esac + echo "$as_me:__oline__: gl_pthread_in_glibc=$gl_pthread_in_glibc" >&AS_MESSAGE_LOG_FD # Test for libpthread by looking for pthread_kill. (Not pthread_self, # since it is defined as a macro on OSF/1.) @@ -219,18 +240,22 @@ AC_DEFUN([gl_PTHREADLIB_BODY], # The program links fine without libpthread. But it may actually # need to link with libpthread in order to create multiple threads. AC_CHECK_LIB([pthread], [pthread_kill], - [LIBPMULTITHREAD=-lpthread - # On Solaris and HP-UX, most pthread functions exist also in libc. - # Therefore pthread_in_use() needs to actually try to create a - # thread: pthread_create from libc will fail, whereas - # pthread_create will actually create a thread. - # On Solaris 10 or newer, this test is no longer needed, because - # libc contains the fully functional pthread functions. - case "$host_os" in - solaris | solaris2.[1-9] | solaris2.[1-9].* | hpux*) - AC_DEFINE([PTHREAD_IN_USE_DETECTION_HARD], [1], - [Define if the pthread_in_use() detection is hard.]) - esac + [if test $gl_pthread_in_glibc = yes; then + LIBPMULTITHREAD= + else + LIBPMULTITHREAD=-lpthread + # On Solaris and HP-UX, most pthread functions exist also in libc. + # Therefore pthread_in_use() needs to actually try to create a + # thread: pthread_create from libc will fail, whereas + # pthread_create will actually create a thread. + # On Solaris 10 or newer, this test is no longer needed, because + # libc contains the fully functional pthread functions. + case "$host_os" in + solaris | solaris2.[1-9] | solaris2.[1-9].* | hpux*) + AC_DEFINE([PTHREAD_IN_USE_DETECTION_HARD], [1], + [Define if the pthread_in_use() detection is hard.]) + esac + fi ]) elif test $gl_pthread_api != yes; then # Some library is needed. Try libpthread and libc_r. @@ -246,6 +271,7 @@ AC_DEFUN([gl_PTHREADLIB_BODY], LIBPMULTITHREAD=-lc_r]) fi fi + echo "$as_me:__oline__: LIBPMULTITHREAD=$LIBPMULTITHREAD" >&AS_MESSAGE_LOG_FD fi AC_MSG_CHECKING([whether POSIX threads API is available]) AC_MSG_RESULT([$gl_pthread_api]) @@ -311,7 +337,8 @@ AC_DEFUN([gl_STDTHREADLIB_BODY], dnl glibc >= 2.29 has thrd_create in libpthread. dnl FreeBSD >= 10 has thrd_create in libstdthreads; this library depends dnl on libpthread (for the symbol 'pthread_mutexattr_gettype'). - dnl AIX >= 7.1 and Solaris >= 11.4 have thrd_create in libc. + dnl glibc >= 2.34, AIX >= 7.1, and Solaris >= 11.4 have thrd_create in + dnl libc. AC_CHECK_FUNCS([thrd_create]) if test $ac_cv_func_thrd_create = yes; then LIBSTDTHREAD= @@ -481,7 +508,10 @@ AC_DEFUN([gl_THREADLIB_BODY], gl_threads_api=posix AC_DEFINE([USE_POSIX_THREADS], [1], [Define if the POSIX multithreading library can be used.]) - if test -n "$LIBMULTITHREAD" || test -n "$LTLIBMULTITHREAD"; then + if test -z "$LIBMULTITHREAD" && test -z "$LTLIBMULTITHREAD"; then + AC_DEFINE([USE_POSIX_THREADS_FROM_LIBC], [1], + [Define if references to the POSIX multithreading library are satisfied by libc.]) + else if case "$gl_cv_have_weak" in *yes) true;; *) false;; esac; then AC_DEFINE([USE_POSIX_THREADS_WEAK], [1], [Define if references to the POSIX multithreading library should be made weak.]) @@ -576,7 +606,9 @@ dnl flavours option weak result dnl --------------- --------- --------- -------- --------- dnl Linux 2.4/glibc posix -lpthread Y OK dnl -dnl GNU Hurd/glibc posix +dnl Linux/glibc 2.34 posix Y OK +dnl +dnl GNU Hurd/glibc posix -lpthread Y OK dnl dnl Ubuntu 14.04 posix -pthread Y OK dnl