0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-08 10:31:50 -05:00

Merge #16059: configure: Fix thread_local detection

480e3415d7 configure: Add flag for enabling thread_local. (Carl Dong)

Pull request description:

  - When aiming for glibc compatibility, don't use thread_local. Fixes #15958.
  - FreeBSD has a buggy thread_local, don't use it. Fixes #16055.

  I've done a Gitian build on my local machine and the symbol tests seem to pass.

ACKs for commit 480e34:
  MarcoFalke:
    utACK 480e3415d7
  fanquake:
    tACK 480e341

Tree-SHA512: 334f21f7cf271c261b115a6410afd4ed4db3e84ad79b98c6c684c1dfa42b081f16d58e77695929e27b0fa173a894b959a327fe82821a3f3ed708b305a906ddd3
This commit is contained in:
MarcoFalke 2019-05-25 10:39:36 -04:00
commit e043bfce68
No known key found for this signature in database
GPG key ID: D2EA4850E7528B25

View file

@ -194,6 +194,12 @@ AC_ARG_ENABLE([glibc-back-compat],
[use_glibc_compat=$enableval], [use_glibc_compat=$enableval],
[use_glibc_compat=no]) [use_glibc_compat=no])
AC_ARG_ENABLE([threadlocal],
[AS_HELP_STRING([--enable-threadlocal],
[enable features that depend on the c++ thread_local keyword (currently just thread names in debug logs). (default is to enabled if there is platform support and glibc-back-compat is not enabled)])],
[use_thread_local=$enableval],
[use_thread_local=auto])
AC_ARG_ENABLE([asm], AC_ARG_ENABLE([asm],
[AS_HELP_STRING([--disable-asm], [AS_HELP_STRING([--disable-asm],
[disable assembly routines (enabled by default)])], [disable assembly routines (enabled by default)])],
@ -827,42 +833,49 @@ AC_LINK_IFELSE([AC_LANG_SOURCE([
] ]
) )
TEMP_LDFLAGS="$LDFLAGS" if test "x$use_thread_local" = xyes || { test "x$use_thread_local" = xauto && test "x$use_glibc_compat" = xno; }; then
LDFLAGS="$TEMP_LDFLAGS $PTHREAD_CFLAGS" TEMP_LDFLAGS="$LDFLAGS"
AC_MSG_CHECKING([for thread_local support]) LDFLAGS="$TEMP_LDFLAGS $PTHREAD_CFLAGS"
AC_LINK_IFELSE([AC_LANG_SOURCE([ AC_MSG_CHECKING([for thread_local support])
#include <thread> AC_LINK_IFELSE([AC_LANG_SOURCE([
static thread_local int foo = 0; #include <thread>
static void run_thread() { foo++;} static thread_local int foo = 0;
int main(){ static void run_thread() { foo++;}
for(int i = 0; i < 10; i++) { std::thread(run_thread).detach();} int main(){
return foo; for(int i = 0; i < 10; i++) { std::thread(run_thread).detach();}
} return foo;
])], }
[ ])],
case $host in [
*mingw*) case $host in
# mingw32's implementation of thread_local has also been shown to behave *mingw*)
# erroneously under concurrent usage; see: # mingw32's implementation of thread_local has also been shown to behave
# https://gist.github.com/jamesob/fe9a872051a88b2025b1aa37bfa98605 # erroneously under concurrent usage; see:
AC_MSG_RESULT(no) # https://gist.github.com/jamesob/fe9a872051a88b2025b1aa37bfa98605
;; AC_MSG_RESULT(no)
*darwin*) ;;
# TODO enable thread_local on later versions of Darwin where it is *darwin*)
# supported (per https://stackoverflow.com/a/29929949) # TODO enable thread_local on later versions of Darwin where it is
AC_MSG_RESULT(no) # supported (per https://stackoverflow.com/a/29929949)
;; AC_MSG_RESULT(no)
*) ;;
AC_DEFINE(HAVE_THREAD_LOCAL,1,[Define if thread_local is supported.]) *freebsd*)
AC_MSG_RESULT(yes) # FreeBSD's implementation of thread_local is also buggy (per
;; # https://groups.google.com/d/msg/bsdmailinglist/22ncTZAbDp4/Dii_pII5AwAJ)
esac AC_MSG_RESULT(no)
], ;;
[ *)
AC_MSG_RESULT(no) AC_DEFINE(HAVE_THREAD_LOCAL,1,[Define if thread_local is supported.])
] AC_MSG_RESULT(yes)
) ;;
LDFLAGS="$TEMP_LDFLAGS" esac
],
[
AC_MSG_RESULT(no)
]
)
LDFLAGS="$TEMP_LDFLAGS"
fi
# Check for different ways of gathering OS randomness # Check for different ways of gathering OS randomness
AC_MSG_CHECKING(for Linux getrandom syscall) AC_MSG_CHECKING(for Linux getrandom syscall)