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]

Re: Fall back to a link test for TLS in target libraries


On Wed, Nov 08, 2006 at 04:09:43PM -0500, Daniel Jacobowitz wrote:
> 2006-11-08  Daniel Jacobowitz  <dan@codesourcery.com>
> 
> 	* tls.m4 (GCC_CHECK_TLS): Fall back to a link test.
> 
> Index: config/tls.m4
> ===================================================================
> --- config/tls.m4	(revision 118333)
> +++ config/tls.m4	(working copy)
> @@ -13,7 +13,8 @@ AC_DEFUN([GCC_CHECK_TLS], [
>  		    [have_tls=yes], [have_tls=no], [])
>        LDFLAGS="$save_LDFLAGS"],
>        [have_tls=no],
> -      [AC_COMPILE_IFELSE([__thread int foo;], [have_tls=yes], [have_tls=no])]
> +      [AC_LINK_IFELSE([__thread int a; int b; int main() { return a = b; }],
> +	[have_tls=yes], [have_tls=no])]
>      )])
>    if test "$enable_tls $have_tls" = "yes yes"; then
>      AC_DEFINE(HAVE_TLS, 1,

This isn't sufficient, I'm afraid you need to link a shared library
rather than an executable.  Because, at least for most targets __thread
uses in the executable will be local-exec (no matter what you declared
them as because of linker TLS optimizations), which doesn't need any
function calls.  If you link a shared library and make sure it doesn't have
undefined symbols, then you should be safe.  An extra complication is that
older glibcs didn't have ld.so in libc.so linker script and __tls_get_addr
is in glibc exported from ld.so.

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]