PATCH: libgcc: Enable TLS for Linux/x86
H.J. Lu
hjl@lucon.org
Thu Jul 5 21:16:00 GMT 2007
On Thu, Jul 05, 2007 at 05:44:27PM +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.
H.J.
---
config/
2007-07-05 H.J. Lu <hongjiu.lu@intel.com>
* tls.m4 (AS_CHECK_TLS): New.
libgcc/
2007-07-05 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 (gcc_compile_bare): Add @set_have_as_tls@.
* configure.ac: Include ../config/enable.m4 and
../config/tls.m4. Use AS_CHECK_TLS to check if assembler
supports TLS and substitute set_have_as_tls.
libbid/
2007-07-05 H.J. Lu <hongjiu.lu@intel.com>
* bid_conf.h (BID_THREAD): Defined only if both HAVE_AS_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-05 13:50:46.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([AS_CHECK_TLS], [
+ GCC_ENABLE(tls, yes, [], [Use thread-local storage])
+ AC_CACHE_CHECK([whether the target asssembler upports thread-local storage],
+ have_as_tls, [
+ AC_COMPILE_IFELSE([__thread int a; int b; int main() { return a = b; }],
+ [have_as_tls=yes], [have_as_tls=no])]
+ )])
+ if test "$enable_tls $have_as_tls" = "yes yes"; then
+ AC_DEFINE(HAVE_AS_TLS, 1,
+ [Define to 1 if the target assembler supports thread-local storage.])
+ fi])
--- gcc/libgcc/Makefile.in.tls 2007-07-05 07:16:20.000000000 -0700
+++ gcc/libgcc/Makefile.in 2007-07-05 14:05:46.000000000 -0700
@@ -225,7 +225,8 @@ MULTIOSSUBDIR := $(shell if test $(MULTI
inst_libdir = $(libsubdir)$(MULTISUBDIR)
inst_slibdir = $(slibdir)$(MULTIOSSUBDIR)
-gcc_compile_bare = $(CC) $(INTERNAL_CFLAGS)
+# If we can use thread-local storage
+gcc_compile_bare = $(CC) $(INTERNAL_CFLAGS) @set_have_as_tls@
compile_deps = -MT $@ -MD -MP -MF $(basename $@).dep
gcc_compile = $(gcc_compile_bare) -o $@ $(compile_deps)
gcc_s_compile = $(gcc_compile) -DSHARED
--- gcc/libgcc/config.host.tls 2007-06-14 05:12:39.000000000 -0700
+++ gcc/libgcc/config.host 2007-07-05 07:16:21.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-05 13:38:41.000000000 -0700
@@ -41,7 +41,7 @@ Software Foundation, 51 Franklin Street,
#endif
#ifndef BID_THREAD
-#ifdef USE_TLS
+#if defined (HAVE_AS_TLS) && defined (USE_TLS)
#define BID_THREAD __thread
#endif
#endif
--- gcc/libgcc/config/t-tls.tls 2007-07-05 07:16:21.000000000 -0700
+++ gcc/libgcc/config/t-tls 2007-07-05 07:16:21.000000000 -0700
@@ -0,0 +1,2 @@
+# Use thread-local storage
+gcc_compile_bare += -DUSE_TLS
--- gcc/libgcc/configure.ac.tls 2007-07-05 07:16:20.000000000 -0700
+++ gcc/libgcc/configure.ac 2007-07-05 13:59:54.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.
+AS_CHECK_TLS
+set_have_as_tls
+if test "$enable_tls $have_as_tls" = "yes yes"; then
+ set_have_as_tls="-DHAVE_AS_TLS"
+fi
+AC_SUBST(set_have_as_tls)
+
# Conditionalize the makefile for this target machine.
tmake_file_=
for f in ${tmake_file}
More information about the Gcc-patches
mailing list