From: Mathieu Desnoyers Date: Fri, 9 Nov 2012 02:45:04 +0000 (-0500) Subject: Fix TLS detection: test with linker, add --disable-compiler-tls X-Git-Tag: v0.7.6~4 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=88c66efb5a534828dbb2a4128339e3491758de49;p=urcu.git 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 --- diff --git a/README b/README index 303c6ec..72d9270 100644 --- a/README +++ b/README @@ -260,3 +260,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 c07e850..5b0990d 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.") +])