Improve TLS link test for cross-compiling
Joseph S. Myers
joseph@codesourcery.com
Thu Jul 2 20:11:00 GMT 2009
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
More information about the Java-patches
mailing list