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 <br...@clisp.org> Don't use '#pragma weak' for thread functions in Linux/glibc>=2.34. Suggested by Florian Weimer <fwei...@redhat.com> in <https://lists.gnu.org/archive/html/bug-gnulib/2021-04/msg00211.html>. * 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 <threads.h> # 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 <stdlib.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 <threads.h> # 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 <stdlib.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 <threads.h> # 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 <stdlib.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 <threads.h> # 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 <features.h> + #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