[Pixman] [PATCH] configure.ac: Fix/workaround broken TLS for clang and mingw-w64

Siarhei Siamashka siarhei.siamashka at gmail.com
Wed Nov 28 11:18:01 PST 2012


Earlier commit a069da6c66da407cc52e1e92321d69c68fd6beb5
introduced a regression, which breaks clang and mingw-w64.

This happens because the configure script now evaluates __thread
and __declspec(thread) as the possible candidatates for TLS
support. But unfortunately unsupported __declspec is not handled
gracefully by clang (in linux, iOS is likely fine) and by mingw-w64:

=== clang-3.1 ===

configure:13722: checking for thread local storage (TLS) support
configure:13750: clang -c -g -O2 -Wall -fno-strict-aliasing -fvisibility=hidden  conftest.c >&5
configure:13750: $? = 0
configure:13750: clang -c -g -O2 -Wall -fno-strict-aliasing -fvisibility=hidden  conftest.c >&5
configure:13750: $? = 0
configure:13758: result: __declspec(thread)

=== mingw-w64 ===

configure:13782: checking for thread local storage (TLS) support
configure:13810: i686-w64-mingw32-gcc -c -g -O2 -Wall -fno-strict-aliasing conftest.c >&5
configure:13810: $? = 0
configure:13810: i686-w64-mingw32-gcc -c -g -O2 -Wall -fno-strict-aliasing conftest.c >&5
conftest.c:39:1: warning: 'thread' attribute directive ignored [-Wattributes]
configure:13810: $? = 0
configure:13818: result: __declspec(thread)

So mingw-w64 spits a scary warning when trying __declspec(thread),
but does not fail compilation. Which results in __declspec(thread)
being selected. For clang there is even no visible indication that
__declspec(thread) is not supported, it is just ignored without
any warnings or errors with the same result.

Running "make check" can detect broken TLS when pixman is compiled
with OpenMP enabled. So in theory we fully have it under control.
The reason why the problem has not been spotted earlier is that
clang does not support OpenMP yet, and mingw/cygwin are not
generally enjoying as much testing as normal linux builds.

The simple workaround implemented in this patch just changes the
order of checks for __thread and __declspec(thread), thus giving
the __thread keyword higher priority.

Fixes bug https://bugs.freedesktop.org/show_bug.cgi?id=57591
reported by Benjamin Gilbert.
---
 configure.ac |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/configure.ac b/configure.ac
index 45b709d..235145d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -850,7 +850,7 @@ dnl Thread local storage
 AC_MSG_CHECKING(for thread local storage (TLS) support)
 AC_CACHE_VAL(ac_cv_tls, [
     ac_cv_tls=none
-    keywords="__thread __declspec(thread)"
+    keywords="__declspec(thread) __thread"
     for kw in $keywords ; do
         AC_TRY_COMPILE([
 #if defined(__MINGW32__) && !(__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5))
-- 
1.7.8.6



More information about the Pixman mailing list