public inbox for java-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Improve TLS link test for cross-compiling
@ 2009-07-02 20:11 Joseph S. Myers
  2009-07-02 19:47 ` Andrew Pinski
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Joseph S. Myers @ 2009-07-02 20:11 UTC (permalink / raw)
  To: gcc-patches, libstdc++, java-patches

When cross-compiling, GCC_CHECK_TLS uses a link-time test for TLS
support.  However, code built for an executable, or linked into an
executable, can link OK when libc in fact lacks TLS support, even if
code linked into a shared library would not, because of the different
TLS access models and linker optimizations used in the different
cases.

This patch adds an additional link-time test for linking with -shared 
-Wl,--no-undefined in this case: if linking a non-TLS file with those 
options succeeds (so, in particular, they are appropriate options for the 
target in question), but linking TLS code with them fails, then TLS is not 
supported.  Tested with no regressions with cross to i686-pc-linux-gnu 
using a sysroot with pre-TLS libc.  OK to commit?

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

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

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

	* configure: Regenerate.

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

	* configure: Regenerate.

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

	* configure: Regenerate.

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

	* configure: Regenerate.

Index: config/tls.m4
===================================================================
--- config/tls.m4	(revision 149177)
+++ config/tls.m4	(working copy)
@@ -66,7 +66,18 @@
       [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"
+	  LDFLAGS="-shared -Wl,--no-undefined $LDFLAGS"
+	  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

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2009-07-17 16:15 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-07-02 20:11 Improve TLS link test for cross-compiling Joseph S. Myers
2009-07-02 19:47 ` Andrew Pinski
2009-07-02 19:58   ` Joseph S. Myers
2009-07-03 11:20   ` Dave Korn
2009-07-14 16:09 ` Ping " Joseph S. Myers
2009-07-14 18:56   ` Paolo Bonzini
2009-07-14 20:15     ` Joseph S. Myers
2009-07-17  0:19     ` Joseph S. Myers
2009-07-17 13:31       ` H.J. Lu
2009-07-17 16:15         ` Joseph S. Myers
2009-07-17 15:16           ` Paolo Bonzini
2009-07-17 13:58 ` H.J. Lu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).