On Sun, Feb 12, 2012 at 09:02:44AM -0500, nobled wrote:
> Judging by the patch that tried to change the tls_model:
> https://bugs.freedesktop.org/show_bug.cgi?id=35268
> It looks like we'd need to disable enable_asm if the tls_model
> attribute isn't supported, since it would probably end up defaulting
> to general-dynamic for PIC code IIRC, and the assembly depends on it
> being initial-exec. Clang still doesn't support the tls_model
> attribute, and it doesn't fail compilation: it just gives a
> -Wattributes warning, so we might need to add '-Werror -Wattributes'
> (to catch the versions before -Wattributes was added, which give an
> 'unknown warning option' warning) to the test-compilation CFLAGS...
> 
> Plus, the test would have to be moved to before enable_asm is decided
> and adds the -DUSE_X86_ASM, etc defines.
> 

Thanks for the comments, I refined the patch according to you and
Dan's suggestion. Here is the new version. As to the version check
of CLANG, I haven't handled it as I don't have the environment at
hand. Could you help to add it?

>From 75de119cf92cb43cecd4813267ed0c76979ddef4 Mon Sep 17 00:00:00 2001
From: Zhigang Gong <zhigang.g...@linux.intel.com>
Date: Mon, 13 Feb 2012 17:26:21 +0800
Subject: [PATCH 1/2 v2] configure.ac: Enable GLX_USE_TLS if possible.

If the system support tls, we prefer to enable it by default
just as xserver does. Actually, the checking code is copied
from xserver/configure.ac.
According to nobled's suggestion, move the checking before
enable_asm. As if tls_model is not supported, then asm may
can't work correctly. Then we check the tls model first,
and if doesn't support it, we need to disable the asm code.

Signed-off-by: Zhigang Gong <zhigang.g...@linux.intel.com>
Reviewed-by: Dan Nicholson <dbn.li...@gmail.com>
---
 acinclude.m4 |   36 ++++++++++++++++++++++++++++++++++++
 configure.ac |   25 ++++++++++++++++++++++---
 2 files changed, 58 insertions(+), 3 deletions(-)

diff --git a/acinclude.m4 b/acinclude.m4
index a5b389d..509de5b 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -117,3 +117,39 @@ if test "$enable_pic" != no; then
 fi
 AC_SUBST([PIC_FLAGS])
 ])# MESA_PIC_FLAGS
+
+dnl TLS detection
+AC_DEFUN([MESA_TLS],
+[AC_MSG_CHECKING(for thread local storage (TLS) support)
+AC_CACHE_VAL(ac_cv_tls, [
+    ac_cv_tls=none
+    keywords="__thread __declspec(thread)"
+    for kw in $keywords ; do
+        AC_TRY_COMPILE([int $kw test;], [], ac_cv_tls=$kw)
+    done
+])
+AC_MSG_RESULT($ac_cv_tls)
+
+if test "$ac_cv_tls" != "none"; then
+    AC_MSG_CHECKING(for tls_model attribute support)
+    saved_CFLAGS="$CFLAGS"
+    if test "x$acv_mesa_CLANG" = "xyes"; then
+        CFLAGS="$CFLAGS -Wattribute -Werror"
+    fi
+    AC_CACHE_VAL(ac_cv_tls_model, [
+        AC_TRY_COMPILE([int $ac_cv_tls 
__attribute__((tls_model("initial-exec"))) test;], [],
+                       ac_cv_tls_model=yes, ac_cv_tls_model=no)
+    ])
+    CFLAGS="$saved_CFLAGS"
+    AC_MSG_RESULT($ac_cv_tls_model)
+
+    AC_MSG_CHECKING([for $CC option to define TLS variable])
+    if test "x$ac_cv_tls_model" = "xyes" ; then
+        TLS=$ac_cv_tls' __attribute__((tls_model(\"initial-exec\")))'
+    else
+        TLS=$ac_cv_tls
+    fi
+    DEFINES="$DEFINES -DTLS=\"$TLS\""
+    AC_MSG_RESULT([$TLS])
+fi
+])
diff --git a/configure.ac b/configure.ac
index b2b1ab8..3423cb2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -433,6 +433,11 @@ AC_SUBST([VG_LIB_GLOB])
 AC_SUBST([GLAPI_LIB_GLOB])
 
 dnl
+dnl Check tls model support 
+dnl
+MESA_TLS
+
+dnl
 dnl Arch/platform-specific settings
 dnl
 AC_ARG_ENABLE([asm],
@@ -446,6 +451,14 @@ ASM_FLAGS=""
 MESA_ASM_SOURCES=""
 GLAPI_ASM_SOURCES=""
 AC_MSG_CHECKING([whether to enable assembly])
+
+if test "x$ac_cv_tls_model" = "xno" ; then
+dnl
+dnl If tls model is not supported, disable asm.
+dnl
+    enable_asm=no
+fi
+
 test "x$enable_asm" = xno && AC_MSG_RESULT([no])
 # disable if cross compiling on x86/x86_64 since we must run gen_matypes
 if test "x$enable_asm" = xyes && test "x$cross_compiling" = xyes; then
@@ -1102,9 +1115,15 @@ dnl
 
 AC_ARG_ENABLE([glx-tls],
     [AS_HELP_STRING([--enable-glx-tls],
-        [enable TLS support in GLX @<:@default=disabled@:>@])],
-    [GLX_USE_TLS="$enableval"],
-    [GLX_USE_TLS=no])
+        [enable TLS support in GLX @<:@default=auto@:>@])],
+    [GLX_USE_TLS=$enableval
+     if test "x$GLX_USE_TLS" = "xyes" && test "${ac_cv_tls}" = "none" ; then
+        AC_MSG_ERROR([GLX with TLS support requested, but the compiler does 
not support it.])
+     fi],
+    [GLX_USE_TLS=no
+     if test "${ac_cv_tls}" != "none" ; then
+        GLX_USE_TLS=yes
+     fi])
 AC_SUBST(GLX_TLS, ${GLX_USE_TLS})
 
 AS_IF([test "x$GLX_USE_TLS" = xyes],
-- 
1.7.4.4

_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to