SPRAB89A September 2011 – March 2014
This is an optimization of the Initial Exec model. When the program’s initial TLS image (normally called the static TLS image) is created, the TLS block is always placed at a known offset from the thread pointer. Normally this is the Thread Control Block (TCB) plus the TLS Block Base offset. Hence the executable’s own thread-local variable has a thread pointer relative offset that is a static link time constant. In this case, thread-local variables can be accessed using an inline constant offset; a GOT entry is not needed. Objects using this access model cannot be used to build a dynamic library.
CALLP __c6xabi_get_tp() ; Returns TP in A4. Can be CSEed.
MVK $TPR_byte(x), A5 ; reloc R_C6000_TPR_U15_B
LDB *A4[A5], A4 ; A4 contains the value of thread-local char x
MVK $TPR_hword(y), A5 ; reloc R_C6000_TPR_U15_H
LDH *A4[A5], A4 ; A4 contains the value of thread-local short y
MVK $TPR_word(z), A5 ; reloc R_C6000_TPR_U15_W
LDW *A4[A5], A4 ; A4 contains the value of thread-local int z
MVK $TPR_dword(l), A5 ; reloc R_C6000_TPR_U15_D
LDDW *A4[A5], A7:A6 ; A7:A6 contains the value of thread-local long long l
The TPR_U15 relocations encode 15-bit unsigned TPR offsets (offset from the address to which the TP points) for near TPR addressing. They are scaled according to the access width. The previous addressing can access a TLS block of size 32 KB. This specification limits the size of the total static TLS to 32 KB, because this limit is expected to be sufficient for most use cases. Hence the far TPR address is not defined. Far TBR addressing may be defined, but doing so would use up 8 new relocations, and it is better to conserve the limited number of relocations (256) ELF allows.