This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: TLS tpoff alignment question
- From: Alan Modra <amodra at gmail dot com>
- To: Will Newton <will dot newton at linaro dot org>
- Cc: "binutils at sourceware dot org" <binutils at sourceware dot org>
- Date: Thu, 22 May 2014 09:23:18 +0930
- Subject: Re: TLS tpoff alignment question
- Authentication-results: sourceware.org; auth=none
- References: <CANu=DmjAPCkXe8DK2QgpK+m_KuDV2hKeoqPEcLejp=n2WsZbMg at mail dot gmail dot com>
On Wed, May 21, 2014 at 10:59:41AM +0100, Will Newton wrote:
> Lots of bfd beckends have code similar to this, from aarch64, to
> handle TLS relocations:
Right, the ones that didn't learn from previous mistakes. :)
In this case, the "mistake" is to define the thread pointer as the
address of the TCB and allocate static TLS blocks after the TCB.
> static bfd_vma
> tpoff_base (struct bfd_link_info *info)
> {
> struct elf_link_hash_table *htab = elf_hash_table (info);
>
> /* If tls_sec is NULL, we should have signalled an error already. */
> if (htab->tls_sec == NULL)
> return 0;
>
> bfd_vma base = align_power ((bfd_vma) TCB_SIZE,
> htab->tls_sec->alignment_power);
> return htab->tls_sec->vma - base;
> }
The comment on the function says "address which should be subtracted".
So, you'll be calculating
STT_TLS_sym_val - tls_sec->vma + base
for the offset from the thread pointer to the tls sym.
The adjustment using align_power is necessary to keep the TLS blocks
aligned in memory. You'll have
____________________________ .. ______
| TCB | pad | static TLS |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. ~~~~~~
^ ^ ^
| | |
tp dtv1 dtvn
Now if tp was at the *end* of the TCB, as used by powerpc, then there
is no need for the "base" adjustment. It doesn't really save you
anything, just hides the pad-for-alignment in the run time TLS
support..
--
Alan Modra
Australia Development Lab, IBM