From: Bruno Haible <bruno@clisp.org>
To: Florian Weimer <fweimer@redhat.com>
Cc: bug-gnulib@gnu.org
Subject: Re: Undefined use of weak symbols in gnulib
Date: Sat, 17 Jul 2021 18:21:22 +0200 [thread overview]
Message-ID: <1895400.xVMIPgDotN@omega> (raw)
In-Reply-To: <87a6piluow.fsf@oldenburg.str.redhat.com>
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 <bruno@clisp.org>
Don't use '#pragma weak' for thread functions in Linux/glibc>=2.34.
Suggested by Florian Weimer <fweimer@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
next prev parent reply other threads:[~2021-07-17 16:21 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-27 5:53 Undefined use of weak symbols in gnulib Florian Weimer
2021-04-27 6:50 ` Paul Eggert
2021-04-27 6:58 ` Florian Weimer
2021-04-27 7:13 ` Paul Eggert
2021-04-27 7:24 ` Andreas Schwab
2021-04-27 11:06 ` Florian Weimer
2021-04-28 0:09 ` Bruno Haible
2021-04-28 2:10 ` H.J. Lu
2021-04-28 2:13 ` H.J. Lu
2021-05-05 20:31 ` Fangrui Song
2021-04-28 8:35 ` Florian Weimer
2021-04-28 13:15 ` Michael Matz
2021-04-28 7:44 ` Florian Weimer
2021-04-28 14:48 ` Bruno Haible
2021-04-28 17:44 ` Florian Weimer
2021-07-17 14:38 ` Bruno Haible
2021-07-17 14:55 ` Florian Weimer
2021-07-17 16:39 ` Bruno Haible
2021-07-27 20:02 ` Joseph Myers
2021-07-27 20:19 ` Florian Weimer
2021-07-27 23:38 ` Paul Eggert
2021-07-17 16:21 ` Bruno Haible [this message]
2021-04-27 23:22 ` Bruno Haible
2021-04-27 23:47 ` Bruno Haible
2021-04-28 7:57 ` Florian Weimer
2021-04-28 14:40 ` Bruno Haible
2021-04-28 17:43 ` Florian Weimer
2021-04-29 15:15 ` Bruno Haible
2021-04-30 9:55 ` Florian Weimer
2021-04-29 6:33 ` Ben Pfaff
2021-05-03 1:44 ` Alan Modra
2021-07-12 10:04 ` Michael Hudson-Doyle
2021-07-12 15:03 ` Florian Weimer
2021-07-12 15:30 ` Matthias Klose
2021-07-12 15:37 ` Florian Weimer
2021-07-13 0:22 ` Michael Hudson-Doyle
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://lists.gnu.org/mailman/listinfo/bug-gnulib
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1895400.xVMIPgDotN@omega \
--to=bruno@clisp.org \
--cc=bug-gnulib@gnu.org \
--cc=fweimer@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).