Fix TLS detection: test with linker, add --disable-compiler-tls
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fri, 9 Nov 2012 02:45:04 +0000 (21:45 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fri, 9 Nov 2012 02:49:45 +0000 (21:49 -0500)
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 <mathieu.desnoyers@efficios.com>
README
config/ax_tls.m4
configure.ac

diff --git a/README b/README
index 81afe0e2757c8bceabef7c50ff4102d0600aa8d3..83330eab1e5ab82cd128dd6c68cdc247f1f272a8 100644 (file)
--- 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.
index 5ab1a413d1414792e6b0098b7c13a42d56d9bdee..7c86daf147cdc8f068161f2dc128bbfd7ef2ebc2 100644 (file)
@@ -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 <stdlib.h>
-               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
   ])
index 4d0c7f4131dfcaadcaa679e70c4bde421de0704f..1d04062f48f41d32022cb2adeec70c1628b95cea 100644 (file)
@@ -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.")
+])
This page took 0.0261 seconds and 4 git commands to generate.