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]

PATCH: Check TLS for libgcc


I'd like to check if I can use TLS in libgcc. However, target feature
checking in lingcc can't use any run-time check since we can't use
gcc to create executable, which requires libgcc yet to be built.

There is GCC_CHECK_TLS in config/tls.m4. For native build, it will
do run-time check. For cross build, it will only compile-time check.
That means we can only use GCC_CHECK_TLS in libgcc for cross compile.

Luckily, we can use GCC_CHECK_TLS for the native compiler of the
native target.  Even if the build compiler doesn't support TLS, it
won't be a problem.  The stage 2 and stage 3 libgcc will have proper
TLS support if the stage 2 and stage 3 compilers do supprot TLS at
run-time. During stage 3, the compiler checked by GCC_CHECK_TLS in
gcc in this case is the stage 2 compiler, which should have the
identical features as the stage 3 compiler, which will be used to
compile stage 3 libgcc. So libgcc can use auto-host.h in gcc to check
if TLS can be used for the native compiler of the native target.

GCC_CHECK_TLS will define HAVE_TLS if TLS is supported and may undefine
HAVE_TLS if no check is done. That means HAVE_TLS may be undefined in
auto-host.h in gcc for cross compile. We can't check TLS support
in gcc for cross compile since wrong compiler will be checked. So we
have to define USE_TLS in libgcc for cross compile if TLS is supported.
We will check both  USE_TLS and HAVE_TLS to see if TLS can be used in
libgcc.

This patch implements this approach. OK to install?

Thanks.


H.J.
---
gcc/

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

	* configure.ac Use GCC_CHECK_TLS for native compiler of the
	native target.

	* aclocal.m4: Regenerated.
	* config.in: Likewise.
	* configure: Regenerated.

libgcc/

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

	* Makefile.in (gcc_compile_bare): Add @use_tls@.

	* configure.ac: Include ../config/enable.m4 and
	../config/tls.m4.  Use GCC_CHECK_TLS for cross compiler and
	substitute use_tls.
	* configure: Regenerated.

--- gcc/gcc/aclocal.m4.tls	2007-06-14 05:12:44.000000000 -0700
+++ gcc/gcc/aclocal.m4	2007-06-14 22:19:38.000000000 -0700
@@ -94,6 +94,7 @@ fi
 
 m4_include([../config/acx.m4])
 m4_include([../config/codeset.m4])
+m4_include([../config/enable.m4])
 m4_include([../config/gettext-sister.m4])
 m4_include([../config/iconv.m4])
 m4_include([../config/lcmessage.m4])
@@ -101,5 +102,6 @@ m4_include([../config/lib-ld.m4])
 m4_include([../config/lib-link.m4])
 m4_include([../config/lib-prefix.m4])
 m4_include([../config/progtest.m4])
+m4_include([../config/tls.m4])
 m4_include([../config/warnings.m4])
 m4_include([acinclude.m4])
--- gcc/gcc/config.in.tls	2007-06-14 16:18:21.000000000 -0700
+++ gcc/gcc/config.in	2007-06-15 05:42:32.000000000 -0700
@@ -1211,6 +1208,9 @@
 #endif
 
 
+/* Define to 1 if the target supports thread-local storage. */
+#undef HAVE_TLS
+
 /* Define to 1 if you have the <unistd.h> header file. */
 #ifndef USED_FOR_TARGET
 #undef HAVE_UNISTD_H
--- gcc/gcc/configure.ac.tls	2007-06-14 16:17:55.000000000 -0700
+++ gcc/gcc/configure.ac	2007-06-15 05:42:19.000000000 -0700
@@ -3419,6 +3420,18 @@ zlibinc=
 AC_SUBST(zlibdir)
 AC_SUBST(zlibinc)
 
+# Check if we can really use thread-local storage.  We can only check
+# it with the native compiler for the native target since we want to
+# know if our target will support thread-local storage, not the build
+# machine.
+if test x$build = x$target && test x$host = x$target; then
+  if test x$enable_tls = x; then
+    enable_tls=$set_have_as_tls
+  fi
+  GCC_TARGET_TEMPLATE(HAVE_TLS)
+  GCC_CHECK_TLS
+fi
+
 dnl Very limited version of automake's enable-maintainer-mode
 
 AC_MSG_CHECKING([whether to enable maintainer-specific portions of Makefiles])
--- gcc/libgcc/Makefile.in.tls	2007-06-14 22:19:38.000000000 -0700
+++ gcc/libgcc/Makefile.in	2007-06-14 22:19:38.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) @use_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/configure.ac.tls	2007-06-14 22:19:38.000000000 -0700
+++ gcc/libgcc/configure.ac	2007-06-14 22:19:38.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,23 @@ else
 fi
 AC_SUBST(vis_hide)
 
+# See if we support thread-local storage.  We can only test it for
+# cross build sicne it requires run-time test with the newly built
+# gcc, which can't be used to build executable due to that libgcc
+# is yet to be built here.  For native build, we will check it in gcc.
+# We define USE_TLS instead of HAVE_TLS as GCC_CHECK_TLS does since
+# HAVE_TLS may be undefined in gcc when building a cross compiler.
+# We need to check both USE_TLS and HAVE_TLS to see if TLS can be
+# used in libgcc.
+use_tls=
+if test "$build" != "$host"; then
+  GCC_CHECK_TLS
+  if test "$enable_tls $use_tls" = "yes yes"; then
+    use_tls="-DUSE_TLS"
+  fi
+fi
+AC_SUBST(use_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]