using pre-TCB padding for static TLS

Alexandre Oliva aoliva@redhat.com
Wed Feb 9 11:02:00 GMT 2005


On Feb  7, 2005, Alexandre Oliva <aoliva@redhat.com> wrote:

>> The other novelty is that the offset from the (biased) TLS pointer to
>> the TLS block for the main executable, if there is one, is fixed by
>> the ABI, which makes the Local Exec model extremely efficient.

> This last bit, in turn, required a change to the TLS offset assignment
> that can benefit other ports.  The existing TLS offset assignment code
> assigns all offsets starting at zero, with the maximum alignment
> required by the static TLS blocks.  Only then does it take
> TLS_PRE_TCB_SIZE into account, rounding it up to the alignment of the
> static TLS block, leaving whatever padding required by this operation
> unused.

> The change introduced to enable the offset from the TCB to the
> executable TLS block to be constant enabled the pre-tcb size and
> alignment requirements to be taken into account early, such that we
> can use whatever padding they might require for TLS blocks.  This is
> particularly useful in case some TLS segment has a very large
> alignment requirement.

> Also, if a TLS segment has alignment requirements no stricter than
> those of the TCB, and the pre-TCB block has wider alignment
> requirements than the TCB, the current code will not obtain the
> correct alignment for the pre-TCB block.  This actually hits in
> current code, because the TCB often has 16-byte alignment, and the
> pre-TCB block is declared as requiring 32-byte alignment.

> The change to implement this fix was implemented by adding an argument
> to a function exported by ld.so to libpthread.so.  I'm not sure this
> is regarded as an ABI break, since it's an internal function.  It
> would be simple enough to introduce a separate entry point to obtain
> the same information, or version the function so as to make
> incompatibilities explicit.  Opinions?

This patch has the changes described above.  It introduces two new
macros to control the behavior of dl-tls: TLS_PRE_TCB_ALIGN (that
should probably be set for all DTV_AT_TP ports) and
TLS_FIXED_EXEC_TCB_OFFSET_P (that is only used on FR-V).  I could
probably split these out into a separate patch, but they're so small
and entangled with the current patch that I didn't think it was worth
the trouble.

It also introduces TLS_STATIC_RESERVED_SIZE, defined as an alias to
TLS_PRE_TCB_SIZE unless TLS_FIXED_EXEC_TCB_OFFSET_P, in which case the
offset may have to vary, and is thus defined as a macro.

_dl_get_tls_static_info() gets a new argument that libc uses to
communicate the amount of space reserved for the pre-tcb block, such
that nptl can take it into account when allocating space for the TLS
block.  I have a few backward-compatibility concerns regarding this
change, but since it's an internal function, I thought this might be
ok.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: glibc-use-pre-tcb-padding.patch
Type: text/x-patch
Size: 11004 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/libc-hacker/attachments/20050209/e1dfb2df/attachment.bin>
-------------- next part --------------

-- 
Alexandre Oliva             http://www.ic.unicamp.br/~oliva/
Red Hat Compiler Engineer   aoliva@{redhat.com, gcc.gnu.org}
Free Software Evangelist  oliva@{lsd.ic.unicamp.br, gnu.org}


More information about the Libc-hacker mailing list