From tijl@coosemans.org  Thu Sep  5 14:12:46 2013
Return-Path: <tijl@coosemans.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1])
	(using TLSv1 with cipher ADH-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by hub.freebsd.org (Postfix) with ESMTP id 1F6ECF3A
	for <FreeBSD-gnats-submit@freebsd.org>; Thu,  5 Sep 2013 14:12:46 +0000 (UTC)
	(envelope-from tijl@coosemans.org)
Received: from mailrelay009.isp.belgacom.be (mailrelay009.isp.belgacom.be [195.238.6.176])
	by mx1.freebsd.org (Postfix) with ESMTP id B0D51218F
	for <FreeBSD-gnats-submit@freebsd.org>; Thu,  5 Sep 2013 14:12:45 +0000 (UTC)
Received: from 176.65-177-91.adsl-dyn.isp.belgacom.be (HELO kalimero.tijl.coosemans.org) ([91.177.65.176])
  by relay.skynet.be with ESMTP; 05 Sep 2013 16:12:42 +0200
Received: from kalimero.tijl.coosemans.org (kalimero.tijl.coosemans.org [127.0.0.1])
	by kalimero.tijl.coosemans.org (8.14.7/8.14.7) with ESMTP id r85ECfn4032229
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 5 Sep 2013 16:12:42 +0200 (CEST)
	(envelope-from tijl@kalimero.tijl.coosemans.org)
Received: (from tijl@localhost)
	by kalimero.tijl.coosemans.org (8.14.7/8.14.7/Submit) id r85ECfef032228;
	Thu, 5 Sep 2013 16:12:41 +0200 (CEST)
	(envelope-from tijl)
Message-Id: <201309051412.r85ECfef032228@kalimero.tijl.coosemans.org>
Date: Thu, 5 Sep 2013 16:12:41 +0200 (CEST)
From: Tijl Coosemans <tijl@FreeBSD.org>
Reply-To: Tijl Coosemans <tijl@FreeBSD.org>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: [patch] x11-servers/xorg-server: fix TLS variables with clang
X-Send-Pr-Version: 3.114
X-GNATS-Notify:

>Number:         181838
>Category:       ports
>Synopsis:       [patch] x11-servers/xorg-server: fix TLS variables with clang
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-x11
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Thu Sep 05 14:20:01 UTC 2013
>Closed-Date:    Sat Oct 19 14:14:36 CEST 2013
>Last-Modified:  Sat Oct 19 14:14:36 CEST 2013
>Originator:     Tijl Coosemans
>Release:        FreeBSD 10.0-CURRENT i386
>Organization:
>Environment:
>Description:
The configure test to find out how to declare thread local variables
is currently broken with clang because it accepts __declspec(thread)
eventhough it doesn't work.  So variables that are supposed to be
thread-local are currently global.  The attached patch adds
ac_cv_tls=__thread to CONFIGURE_ARGS.
>How-To-Repeat:
>Fix:

--- xorg-server.patch begins here ---
Index: x11-servers/xorg-server/Makefile
===================================================================
--- x11-servers/xorg-server/Makefile	(revision 326283)
+++ x11-servers/xorg-server/Makefile	(working copy)
@@ -22,7 +22,7 @@ SLAVE_PORT?=	no
 
 .if defined(WITH_NEW_XORG)
 XORG_VERSION=	1.12.4
-XORG_REVISION=	1
+XORG_REVISION=	2
 PLIST_SUB+=	OLD="@comment " NEW=""
 EXTRA_PATCHES+=	${FILESDIR}/extra-clang
 .else
@@ -58,6 +58,7 @@ CONFIGURE_ARGS?=--disable-dmx --disable-
 		--without-xmlto --disable-docs --disable-devel-docs \
 		--localstatedir=/var --without-dtrace --disable-xephyr \
 		--enable-record=yes
+CONFIGURE_ARGS+=ac_cv_tls=__thread
 
 .if ${SLAVE_PORT} == "no"
 SUB_FILES=	pkg-install pkg-deinstall
--- xorg-server.patch ends here ---

>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-ports-bugs->freebsd-x11 
Responsible-Changed-By: edwin 
Responsible-Changed-When: Thu Sep 5 14:20:10 UTC 2013 
Responsible-Changed-Why:  
Over to maintainer (via the GNATS Auto Assign Tool) 

http://www.freebsd.org/cgi/query-pr.cgi?pr=181838 

From: Niclas Zeising <zeising@freebsd.org>
To: bug-followup@FreeBSD.org, tijl@FreeBSD.org
Cc:  
Subject: Re: ports/181838: [patch] x11-servers/xorg-server: fix TLS variables
 with clang
Date: Fri, 06 Sep 2013 22:18:27 +0200

 Hi!
 Can you please elaborate a bit on this, exactly what happends when
 setting that configure variable?
 Have you tried and ensured that this doesn't break xserver built with gcc?
 Regards!
 -- 
 Niclas Zeising

From: Tijl Coosemans <tijl@FreeBSD.org>
To: Niclas Zeising <zeising@freebsd.org>
Cc: bug-followup@FreeBSD.org
Subject: Re: ports/181838: [patch] x11-servers/xorg-server: fix TLS
 variables with clang
Date: Fri, 6 Sep 2013 23:22:29 +0200

 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.

From: Niclas Zeising <zeising@freebsd.org>
To: Tijl Coosemans <tijl@FreeBSD.org>
Cc: bug-followup@FreeBSD.org
Subject: Re: ports/181838: [patch] x11-servers/xorg-server: fix TLS variables
 with clang
Date: Sat, 07 Sep 2013 01:52:44 +0200

 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.
 > 
 
 Thank you for your very excellent description!
 I'll look into this more during the weekend or beginning of next week.
 Your patch looks fine, now that I understand it properly ;). I just want
 to make sure that gcc still works, check the old xorg-server version,
 and look through the rest of the xorg ports, in case this is needed
 somewhere else as well.
 Regards!
 -- 
 Niclas Zeising

From: Niclas Zeising <zeising@freebsd.org>
To: Tijl Coosemans <tijl@FreeBSD.org>
Cc: bug-followup@FreeBSD.org
Subject: Re: ports/181838: [patch] x11-servers/xorg-server: fix TLS variables
 with clang
Date: Sat, 07 Sep 2013 23:51:32 +0200

 This is a multi-part message in MIME format.
 --------------090100090803040407060508
 Content-Type: text/plain; charset=UTF-8
 Content-Transfer-Encoding: 7bit
 
 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.
 > 
 
 Hi!
 
 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?
 Regards!
 -- 
 Niclas Zeising
 
 --------------090100090803040407060508
 Content-Type: text/x-patch;
  name="xserver-tls.diff"
 Content-Transfer-Encoding: 7bit
 Content-Disposition: attachment;
  filename="xserver-tls.diff"
 
 Index: Makefile
 ===================================================================
 --- Makefile	(revision 1141)
 +++ Makefile	(working copy)
 @@ -31,7 +31,8 @@
  XORG_VERSION=	1.12.4
  XORG_REVISION=	1
  PLIST_SUB+=	OLD="@comment " NEW=""
 -EXTRA_PATCHES+=	${FILESDIR}/extra-clang
 +EXTRA_PATCHES+=	${FILESDIR}/extra-clang \
 +		${FILESDIR}/extra-configure
  .else
  XORG_VERSION=	1.7.7
  XORG_REVISION=	8
 Index: files/extra-configure
 ===================================================================
 --- files/extra-configure	(revision 0)
 +++ files/extra-configure	(working copy)
 @@ -0,0 +1,11 @@
 +--- configure.orig	2013-09-07 22:11:27.210621324 +0200
 ++++ configure	2013-09-07 22:11:52.912624338 +0200
 +@@ -22839,7 +22839,7 @@
 + }
 + _ACEOF
 + if ac_fn_c_try_compile "$LINENO"; then :
 +-  ac_cv_tls=$kw
 ++  ac_cv_tls=$kw; break ;
 + fi
 + rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 +         done
 
 Property changes on: files/extra-configure
 ___________________________________________________________________
 Added: fbsd:nokeywords
 ## -0,0 +1 ##
 +yes
 \ No newline at end of property
 Added: svn:eol-style
 ## -0,0 +1 ##
 +native
 \ No newline at end of property
 Added: svn:mime-type
 ## -0,0 +1 ##
 +text/plain
 \ No newline at end of property
 
 --------------090100090803040407060508--

From: Tijl Coosemans <tijl@FreeBSD.org>
To: Niclas Zeising <zeising@freebsd.org>
Cc: bug-followup@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.
State-Changed-From-To: open->analyzed 
State-Changed-By: zeising 
State-Changed-When: Sun Sep 8 11:18:18 UTC 2013 
State-Changed-Why:  
The issue has been resolved and a patch comitted to the xorg development repo. 
It will be merged to the ports tree soon. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=181838 
State-Changed-From-To: analyzed->closed 
State-Changed-By: tijl 
State-Changed-When: Sat Oct 19 14:13:47 CEST 2013 
State-Changed-Why:  
Fix committed. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=181838 
>Unformatted:
