Linker and Libraries Guide

Thread-Local Storage

To permit association of separate copies of data allocated at compile-time with individual threads of execution, thread-local storage sections can be used to specify the size and initial contents of such data.

Sections of type SHF_TLS provide uninitialized and initialized thread-local storage. The uninitialized section, .tbss, is allocated immediately following any initialized sections, .tdata and .tdata1, subject to padding for proper alignment. The combined sections together form a TLS template that is used to allocate thread-local storage whenever a new thread is created.

The initialized portion of this template is called the TLS initialization image. All relocations generated as a result of initialized thread-local variables are applied to this template, so that the relocated values can be used when a new thread requires the initial values.

A PT_TLS program entry describes a TLS template, and has the following members:

Table 7-35 ELF PT_TLS program entry

Member 

Value 

p_offset

File offset of the TLS initialization image

p_vaddr

Virtual memory address of the TLS initialization image

p_paddr

Reserved 

p_filesz

Size of the TLS initialization image

p_memsz

Total size of the TLS template

p_flags

PF_R

p_align

Alignment of the TLS template