From 75478b32ffe53b0d8b5e687d9cf7ebdd77a085de Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Thu, 8 Nov 2012 21:45:04 -0500 Subject: [PATCH] Fix TLS detection: test with linker, add --disable-compiler-tls NetBSD 5.1 and older, as well as Darwin, succeed to compile code containing TLS, but cannot link it. Test with linker in addition to compiler for TLS support. Also add a --disable-compiler-tls configure option to allow users to force using the pthread getspecific fall back. Fixes #288 Signed-off-by: Mathieu Desnoyers --- README | 7 +++++++ config/ax_tls.m4 | 13 ++++--------- configure.ac | 21 ++++++++++++++++++++- 3 files changed, 31 insertions(+), 10 deletions(-) diff --git a/README b/README index 81afe0e..83330ea 100644 --- a/README +++ b/README @@ -274,3 +274,10 @@ Interaction with fork() call_rcu_after_fork_parent() after the fork(). The child process must invoke call_rcu_after_fork_child(). These three APIs are suitable for passing to pthread_atfork(). + +Thread Local Storage (TLS) + + Userspace RCU can fall back on pthread_getspecific() to emulate + TLS variables on systems where it is not available. This behavior + can be forced by specifying --disable-compiler-tls as configure + argument. diff --git a/config/ax_tls.m4 b/config/ax_tls.m4 index 5ab1a41..7c86daf 100644 --- a/config/ax_tls.m4 +++ b/config/ax_tls.m4 @@ -69,16 +69,11 @@ AC_DEFUN([AX_TLS], [ for ax_tls_keyword in $ax_tls_keywords; do AS_CASE([$ax_tls_keyword], [none], [ac_cv_tls=none ; break], - [AC_TRY_COMPILE( - [#include - static void - foo(void) { - static ] $ax_tls_keyword [ int bar; - exit(1); - }], - [], + [AC_TRY_LINK( + [$ax_tls_keyword int foo;], + [++foo;], [ac_cv_tls=$ax_tls_keyword ; break], - ac_cv_tls=none + [ac_cv_tls=none] )]) done ]) diff --git a/configure.ac b/configure.ac index 4d0c7f4..1d04062 100644 --- a/configure.ac +++ b/configure.ac @@ -28,7 +28,20 @@ AH_TEMPLATE([CONFIG_RCU_COMPAT_ARCH], [Compatibility mode for i386 which lacks c AH_TEMPLATE([CONFIG_RCU_ARM_HAVE_DMB], [Use the dmb instruction if available for use on ARM.]) AH_TEMPLATE([CONFIG_RCU_TLS], [TLS provided by the compiler.]) -AX_TLS(AC_DEFINE_UNQUOTED([CONFIG_RCU_TLS], $ac_cv_tls), [:]) +# Allow overriding storage used for TLS variables. +AC_ARG_ENABLE([compiler-tls], + AS_HELP_STRING([--disable-compiler-tls], [Use pthread_getspecific() to emulate Thread Local Storage (TLS) variables.]), + [def_compiler_tls=$enableval], + [def_compiler_tls="yes"]) + +# If not overridden, use ax_tls.m4 to check if TLS is available. +AS_IF([test "x$def_compiler_tls" = "xyes"], + [AX_TLS([def_tls_detect=$ac_cv_tls], [:])], + [:]) + +AS_IF([test "x$def_tls_detect" = "x"], + [:], + [AC_DEFINE_UNQUOTED([CONFIG_RCU_TLS], $def_tls_detect)]) # Checks for programs. AC_PROG_CC @@ -252,3 +265,9 @@ AS_IF([test "x$def_smp_support" = "xyes"],[ ],[ AS_ECHO("SMP support disabled.") ]) + +AS_IF([test "x$def_tls_detect" = "x"],[ + AS_ECHO("Thread Local Storage (TLS): pthread_getspecific().") +],[ + AS_ECHO("Thread Local Storage (TLS): $def_tls_detect.") +]) -- 2.34.1