[Pixman] pixman on iOS

Siarhei Siamashka siarhei.siamashka at gmail.com
Thu Oct 25 16:03:26 PDT 2012


On Thu, 25 Oct 2012 14:57:29 -0700
Jeremy Huddleston Sequoia <jeremyhu at apple.com> wrote:

> On Oct 25, 2012, at 14:44, Siarhei Siamashka
> <siarhei.siamashka at gmail.com> wrote:
> 
> > 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
> 
> We should maybe try using -Werror=ignored-attributes in the test, or
> just prefer the first one.

Using -Werror=ignored-attributes will not help because clang-3.1 (and
maybe older versions too) just silently ignores __declspec(thread).
This non-working TLS problem could have been detected by the pixman test
suite if clang had OpenMP support. In any case, I was just lucky to
notice the fresh warning when doing preemptive testing for the current
clang svn (just to be sure that pixman would not need any ugly compiler
bug workarounds for the upcoming clang-3.2).

Regarding your original patch, how does iOS behave when somebody
tries to use __thread keyword? Does it fail compilation?

Also, as mentioned in your commit message, xorg-server is likely to
have the same TLS problem if somebody ever tries to compile it with
clang in linux:
    http://cgit.freedesktop.org/xorg/xserver/commit/?id=bb4d145bd25e2aee

As I don't have iOS and have no idea how TLS works there, I would
prefer to step down and let you take care of the issue.

-- 
Best regards,
Siarhei Siamashka


More information about the Pixman mailing list