This is the mail archive of the binutils@sourceware.org mailing list for the binutils 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: TLS tpoff alignment question


On 22 May 2014 00:53, Alan Modra <amodra@gmail.com> wrote:
> 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..

Thanks for the explanation, that's really helpful!

-- 
Will Newton
Toolchain Working Group, Linaro


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