[Pixman] pixman on iOS

Siarhei Siamashka siarhei.siamashka at gmail.com
Thu Oct 25 14:44:26 PDT 2012


On Mon, 13 Feb 2012 16:16:30 -0800
Jeremy Huddleston <jeremyhu at apple.com> wrote:

> From: Jeremy Huddleston <jeremyhu at apple.com>
> Date: Sat, 11 Feb 2012 00:44:38 -0800
> Subject: [PATCH 2/2] Expand TLS support beyond __thread to
> __declspec(thread)
> 
> Also prefer initial-exec if available.  This code was pretty much
> coppied from a similar commit that I made to xorg-server in April.
> 
> cf: xorg/xserver: bb4d145bd25e2aee988b100ecf1105ea3b6a40b8
> 
> Signed-off-by: Jeremy Huddleston <jeremyhu at apple.com>

This commit seems to cause troubles for clang in linux.
Running pixman configure with clang-3.1 prefers the use
of __declspec(thread) for TLS:

checking for gettimeofday... yes
checking sys/time.h usability... yes
checking sys/time.h presence... yes
checking for sys/time.h... yes
checking for thread local storage (TLS) support... __declspec(thread)

And config.log contains:

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)

So clang seems to accept both __thread and __declspec(thread) but
selects the latter because it is the last in the list.


For the current clang svn (soon to be clang-3.2) we get a bit different
result in config.log:

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
conftest.c:45:16: warning: __declspec attribute 'thread' is not supported [-Wignored-attributes]
int __declspec(thread) test;
               ^
1 warning generated.
configure:13750: $? = 0
configure:13758: result: __declspec(thread)

Here clang-3.2 produces a warning about __declspec(thread), but does not
fail compilation. Which results in __declspec(thread) also being
selected for TLS.


A simple test demonstrates that __declspec(thread) does not work
correctly in clang:

/************************************/
#include <pthread.h>
#include <unistd.h>
#include <assert.h>

int __declspec(thread) a = 0;

void *thread_func(void * arg)
{
     a++;
     sleep(1);
     assert(a == 1);
     return NULL;
}

int main(void)
{
     pthread_t thread1, thread2;
     pthread_create(&thread1, NULL, thread_func, NULL);
     pthread_create(&thread2, NULL, thread_func, NULL);
     pthread_join(thread1, NULL);
     pthread_join(thread2, NULL); 
     return 0;
}
/************************************/

On a positive side, looks like clang-3.2 is going to be able to pass
pixman test suite successfully.

I would suggest to just change the order of checks for
__declspec(thread) and __thread in configure.ac

-- 
Best regards,
Siarhei Siamashka


More information about the Pixman mailing list