This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: PATCH: libgcc: Enable TLS for Linux/x86


On Fri, Jul 06, 2007 at 11:49:08AM +0200, Paolo Bonzini wrote:
> >>>Paolo, what about old binutils?  I don't know what we require nowadays
> >>>but I doubt it's sufficient for __thread.  I think we still need a
> >>>link test, or at least an assembler test.
> >>Agreed.  I thought I had specified that, but I only mentioned testing 
> >>the triplet.
> >
> >Here is the updated patch. I added AS_CHECK_TLS to config/tls.m4.
> >Tested on Linux/Intel64.
> 
> Thinking more about it, please call this macro GCC_CHECK_CC_TLS and the 
> corresponding #define HAVE_CC_TLS.
> 
> We are already testing for assembler-level TLS support in 
> gcc/configure.ac and the test has a completely different shape.
> 

This is the patch I am checking in.

Thanks.


H.J.
----
config/

2007-07-06  H.J. Lu  <hongjiu.lu@intel.com>

	* tls.m4 (GCC_CHECK_CC_TLS): New.

libgcc/

2007-07-06  H.J. Lu  <hongjiu.lu@intel.com>

	* config.host (tmake_file): Add t-tls for i[34567]86-*-linux*
	and x86_64-*-linux*.

	* config/t-tls: New file.

	* Makefile.in (INTERNAL_CFLAGS): Add @set_have_cc_tls@. 

	* configure.ac: Include ../config/enable.m4 and
	../config/tls.m4.  Use GCC_CHECK_CC_TLS to check if assembler
	supports TLS and substitute set_have_cc_tls.

libbid/

2007-07-06  H.J. Lu  <hongjiu.lu@intel.com>

	* bid_conf.h (BID_THREAD): Defined only if both HAVE_CC_TLS
	and USE_TLS are defined.

--- gcc/config/tls.m4.tls	2007-02-11 07:29:47.000000000 -0800
+++ gcc/config/tls.m4	2007-07-06 06:32:44.000000000 -0700
@@ -73,3 +73,16 @@ AC_DEFUN([GCC_CHECK_TLS], [
     AC_DEFINE(HAVE_TLS, 1,
 	      [Define to 1 if the target supports thread-local storage.])
   fi])
+
+dnl Check whether the target assembler supports TLS.
+AC_DEFUN([GCC_CHECK_CC_TLS], [
+  GCC_ENABLE(tls, yes, [], [Use thread-local storage])
+  AC_CACHE_CHECK([whether the target asssembler upports thread-local storage],
+		 have_cc_tls, [
+    AC_COMPILE_IFELSE([__thread int a; int b; int main() { return a = b; }],
+      [have_cc_tls=yes], [have_cc_tls=no])]
+    )])
+  if test "$enable_tls $have_cc_tls" = "yes yes"; then
+    AC_DEFINE(HAVE_CC_TLS, 1,
+	      [Define to 1 if the target assembler supports thread-local storage.])
+  fi])
--- gcc/libgcc/Makefile.in.tls	2007-07-05 18:02:55.000000000 -0700
+++ gcc/libgcc/Makefile.in	2007-07-06 06:41:53.000000000 -0700
@@ -216,7 +216,8 @@ override CFLAGS := $(filter-out -fprofil
 # options in LIBGCC2_CFLAGS.  But LIBGCC2_CFLAGS may contain -g0, and CFLAGS
 # will usually contain -g, so for the moment CFLAGS goes first.  We must
 # include CFLAGS - that's where multilib options live.
-INTERNAL_CFLAGS = $(CFLAGS) $(LIBGCC2_CFLAGS) $(HOST_LIBGCC2_CFLAGS) $(INCLUDES)
+INTERNAL_CFLAGS = $(CFLAGS) $(LIBGCC2_CFLAGS) $(HOST_LIBGCC2_CFLAGS) \
+		  $(INCLUDES) @set_have_cc_tls@
 
 MULTIDIR := $(shell $(CC) $(CFLAGS) -print-multi-directory)
 MULTIOSDIR := $(shell $(CC) $(CFLAGS) -print-multi-os-directory)
--- gcc/libgcc/config.host.tls	2007-06-14 05:12:39.000000000 -0700
+++ gcc/libgcc/config.host	2007-07-06 06:32:44.000000000 -0700
@@ -654,3 +654,9 @@ m32c-*-elf*)
 	exit 1
 	;;
 esac
+
+case ${host} in
+i[34567]86-*-linux* | x86_64-*-linux*)
+	tmake_file="${tmake_file} t-tls"
+	;;
+esac
--- gcc/libgcc/config/libbid/bid_conf.h.tls	2007-07-05 07:13:24.000000000 -0700
+++ gcc/libgcc/config/libbid/bid_conf.h	2007-07-06 06:32:44.000000000 -0700
@@ -41,7 +41,7 @@ Software Foundation, 51 Franklin Street,
 #endif
 
 #ifndef BID_THREAD
-#ifdef USE_TLS
+#if defined (HAVE_CC_TLS) && defined (USE_TLS)
 #define BID_THREAD __thread
 #endif
 #endif
--- gcc/libgcc/config/t-tls.tls	2007-07-05 18:02:55.000000000 -0700
+++ gcc/libgcc/config/t-tls	2007-07-06 06:32:44.000000000 -0700
@@ -0,0 +1,2 @@
+# Use thread-local storage
+gcc_compile_bare += -DUSE_TLS
--- gcc/libgcc/configure.ac.tls	2007-07-05 18:02:55.000000000 -0700
+++ gcc/libgcc/configure.ac	2007-07-06 06:32:44.000000000 -0700
@@ -1,5 +1,7 @@
 dnl Process this file with autoconf to produce a configure script.
 
+sinclude(../config/enable.m4)
+sinclude(../config/tls.m4)
 sinclude(../config/acx.m4)
 sinclude(../config/no-executables.m4)
 sinclude(../config/lib-ld.m4)
@@ -169,6 +171,17 @@ else
 fi
 AC_SUBST(vis_hide)
 
+# See if we have thread-local storage.  We can only test assembler
+# sicne link-time and run-time tests require the newly built
+# gcc, which can't be used to build executable due to that libgcc
+# is yet to be built here.
+GCC_CHECK_CC_TLS
+set_have_cc_tls
+if test "$enable_tls $have_cc_tls" = "yes yes"; then
+  set_have_cc_tls="-DHAVE_CC_TLS"
+fi
+AC_SUBST(set_have_cc_tls)
+
 # Conditionalize the makefile for this target machine.
 tmake_file_=
 for f in ${tmake_file}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]