Ping Re: Improve TLS link test for cross-compiling

Joseph S. Myers joseph@codesourcery.com
Fri Jul 17 00:19:00 GMT 2009


On Tue, 14 Jul 2009, Paolo Bonzini wrote:

> On 07/14/2009 05:41 PM, Joseph S. Myers wrote:
> > Ping.  This patch
> > <http://gcc.gnu.org/ml/gcc-patches/2009-07/msg00139.html>  is pending
> > review.
> 
> Are there any targets that support TLS but use anything but -shared to link a
> shared library, or that do not have -Wl,--no-undefined?  I'm thinking of
> Solaris with Sun as and ld especially.
> 
> Okay if you conditionalize setting the LDFLAGS on $host being *-*-linux*
> (don't know about uclinux?) and require AC_CANONICAL_HOST at the top of the
> file.

I have applied this patch with that condition added.

config:
2009-07-16  Joseph Myers  <joseph@codesourcery.com>

	* tls.m4 (GCC_CHECK_TLS): Also test TLS in a shared library when
	cross-compiling.

libgomp:
2009-07-16  Joseph Myers  <joseph@codesourcery.com>

	* configure: Regenerate.

libjava:
2009-07-16  Joseph Myers  <joseph@codesourcery.com>

	* configure: Regenerate.

libmudflap:
2009-07-16  Joseph Myers  <joseph@codesourcery.com>

	* configure: Regenerate.

libstdc++-v3:
2009-07-16  Joseph Myers  <joseph@codesourcery.com>

	* configure: Regenerate.

Index: config/tls.m4
===================================================================
--- config/tls.m4	(revision 149722)
+++ config/tls.m4	(working copy)
@@ -1,5 +1,6 @@
 dnl Check whether the target supports TLS.
 AC_DEFUN([GCC_CHECK_TLS], [
+  AC_REQUIRE([AC_CANONICAL_HOST])
   GCC_ENABLE(tls, yes, [], [Use thread-local storage])
   AC_CACHE_CHECK([whether the target supports thread-local storage],
 		 gcc_cv_have_tls, [
@@ -66,7 +67,24 @@
       [dnl This is the cross-compiling case. Assume libc supports TLS if the
        dnl binutils and the compiler do.
        AC_LINK_IFELSE([__thread int a; int b; int main() { return a = b; }],
-		      [gcc_cv_have_tls=yes], [gcc_cv_have_tls=no])
+	 [chktls_save_LDFLAGS="$LDFLAGS"
+	  dnl Shared library options may depend on the host; this check
+	  dnl is only known to be needed for GNU/Linux.
+	  case $host in
+	    *-*-linux*)
+	      LDFLAGS="-shared -Wl,--no-undefined $LDFLAGS"
+	      ;;
+	  esac
+	  chktls_save_CFLAGS="$CFLAGS"
+	  CFLAGS="-fPIC $CFLAGS"
+	  dnl If -shared works, test if TLS works in a shared library.
+	  AC_LINK_IFELSE([int f() { return 0; }],
+	    AC_LINK_IFELSE([__thread int a; int b; int f() { return a = b; }],
+	      [gcc_cv_have_tls=yes],
+	      [gcc_cv_have_tls=no]),
+	    [gcc_cv_have_tls=yes])
+	  CFLAGS="$chktls_save_CFLAGS"
+	  LDFLAGS="$chktls_save_LDFLAGS"], [gcc_cv_have_tls=no])
       ]
     )])
   if test "$enable_tls $gcc_cv_have_tls" = "yes yes"; then

-- 
Joseph S. Myers
joseph@codesourcery.com



More information about the Java-patches mailing list