ports/181838: [patch] x11-servers/xorg-server: fix TLS variables with clang
Tijl Coosemans
tijl at FreeBSD.org
Sun Sep 8 10:20:01 UTC 2013
The following reply was made to PR ports/181838; it has been noted by GNATS.
From: Tijl Coosemans <tijl at FreeBSD.org>
To: Niclas Zeising <zeising at freebsd.org>
Cc: bug-followup at FreeBSD.org
Subject: Re: ports/181838: [patch] x11-servers/xorg-server: fix TLS
variables with clang
Date: Sun, 8 Sep 2013 12:18:15 +0200
On Sat, 07 Sep 2013 23:51:32 +0200 Niclas Zeising wrote:
> On 09/06/13 23:22, Tijl Coosemans wrote:
>> On Fri, 06 Sep 2013 22:18:27 +0200 Niclas Zeising wrote:
>>> Can you please elaborate a bit on this, exactly what happends when
>>> setting that configure variable?
>>
>> The configure script tests how to declare a thread-local variable. For
>> clang and gcc this is done using the __thread keyword like this:
>>
>> __thread int thread_specific_int_var;
>>
>> Other compilers use __declspec(thread) instead of __thread.
>>
>> The code in configure comes from the XORG_TLS call in configure.ac.
>> XORG_TLS is defined in m4/xorg-tls.m4. Here are the relevant bits:
>>
>> 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)
>>
>> The for-loop runs over the elements in $keywords and sets ac_cv_tls
>> to the keyword if the compiler accepts it. The problem is that clang
>> accepts __declspec(thread) but it doesn't actually work (there's a
>> warning about this but no error) so when the for-loop ends ac_cv_tls
>> is set to __declspec(thread). Because the test is inside AC_CACHE_VAL
>> it can be skipped by defining ac_cv_tls which is what the patch does.
>>
>> I found a similar test in pixman but there the for-loop contains a
>> break so it ends on the first successful keyword (i.e. __thread).
>>
>>> Have you tried and ensured that this doesn't break xserver built with
>>> gcc?
>>
>> No, I currently don't have gcc installed, but the keyword for gcc is
>> also __thread. You could search for __thread in a config.log generated
>> with gcc to verify this.
>
> Looking through the git history of xorg-server, I noticed that this test
> has changed in later versions. I changed the TLS test to mimic this
> way, and it seems to work. I just want a second set of eyes, can you
> please test the attached patch?
Yes that works too. It's the same as in the pixman configure script.
More information about the freebsd-x11
mailing list