This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH][BZ #16214] Fix TLS access on S390 with -march=z10
- From: "Carlos O'Donell" <carlos at redhat dot com>
- To: Siddhesh Poyarekar <siddhesh at redhat dot com>, libc-alpha at sourceware dot org
- Cc: Andreas Krebbel <krebbel at linux dot vnet dot ibm dot com>
- Date: Wed, 27 Nov 2013 00:44:54 -0500
- Subject: Re: [PATCH][BZ #16214] Fix TLS access on S390 with -march=z10
- Authentication-results: sourceware.org; auth=none
- References: <20131125055009 dot GK19834 at spoyarek dot pnq dot redhat dot com>
On 11/25/2013 12:50 AM, Siddhesh Poyarekar wrote:
> +# ifdef __s390x__
> +# define LOAD_R12(r12) asm ("lgr %0,%%r12" : "=r" (r12) ::)
> +# elif defined __s390__
> +# define LOAD_R12(r12) asm ("lr %0,%%r12" : "=r" (r12) ::)
> +# endif
> +
> # define GET_ADDR_OFFSET \
> (ti->ti_offset - (unsigned long) __builtin_thread_pointer ())
>
> +/* Subtract contents of r12 from __TI. We don't really care if this is the
> + GOT pointer. */
> # define __TLS_GET_ADDR(__ti) \
> - ({ extern char _GLOBAL_OFFSET_TABLE_[] attribute_hidden; \
> - (void *) __tls_get_offset ((char *) (__ti) - _GLOBAL_OFFSET_TABLE_) \
> - + (unsigned long) __builtin_thread_pointer (); })
> +({ \
> + unsigned long int r12; \
> + LOAD_R12 (r12); \
> + ((void *) __tls_get_offset ((unsigned long int) (__ti) - r12) \
> + + (unsigned long) __builtin_thread_pointer ()); \
> +})
Something was bothering me about doing it this way and then I remembered
that it can't be done this way because the compiler might change r12
at any point.
The compiler may change r12 between when we load it and when it gets
used by __tls_get_offset, this whole sequence has to be written in
assembly (as previously suggested by Jakub Jelinek).
Otherwise it is going to be fragile.
Cheers,
Carlos.