SPRAB89A September 2011 – March 2014
The thread-local access code in the case of the static executable TLS model is the same as for the Linux Local Exec model (Section 7.6.1.4). In the case of a static executable, there is no Thread Control Block (TCB), so the TPR offset is the same as the TLS Block Base relative address.
Ideally we could generate TBR addressing for this case. However, the compiler options can be used to build using the bare-metal dynamic linking model, which requires a TCB. So, we generate TPR addressing for the static executable model as follows:
CALLP __c6xabi_get_tp() ; Returns TP in A4. Can be CSEed.
MVK $TPR_byte(x), B4 ; reloc R_C6000_TPR_U15_B
LDB *A4[B4], A4 ; A4 contains the value of thread-local char x
MVK $TPR_hword(y), B4 ; reloc R_C6000_TPR_U15_H
LDH *A4[B4], A4 ; A4 contains the value of thread-local short y
MVK $TPR_word(z), B4 ; reloc R_C6000_TPR_U15_W
LDW *A4[B4], A4 ; A4 contains the value of thread-local int z
MVK $TPR_dword(l), B4 ; reloc R_C6000_TPR_U15_D
LDDW *A4[B4], A7:A6 ; A4 contains the value of thread-local int l
The TPR relocations are resolved by the static linker with the offset of the variable in the executable’s TLS block. The far TPR relocations can be used if the TLS block is expected to be bigger than 32 KB.