SPRAB89A September 2011 – March 2014
The default code generation for TLS should work for both static executables and bare-metal dynamic linking. For static executables, generate the following addressing using TPR addressing:
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
The code generated by default for bare-metal dynamic linking can assume that all modules are initially loaded. This means the offset of thread-local variables is a dynamic link time constant as shown in Figure 7-3. Hence the TPR addressing can be used. The only difference is that in the bare-metal dynamic linking case, a 64-bit TCB is needed to make the code compatible with any future support for dlopen(). In the case of static executables, the TCB is not present. Still the TPR addressing can be used for both models. The static linker will use a TCB size of zero for a static executable and a 64-bit TCB size for bare-metal dynamic linking.
As mentioned earlier, the initially loaded modules are placed consecutively, and the executable’s TLS block comes after the TCB. In this case, the variables in the executable can be accessed using static link time constant offsets from the TP. The variables defined in the dynamic libraries can be accessed using dynamic link time constant offsets from the TP.
When this addressing is generated the modules are marked DF_STATIC_TLS.
When building a dynamic executable, the static linker resolves the TPR relocations for symbols defined in the executable (own data) to the TP offset. If the symbol is imported, the relocation is copied to the dynamic relocation table to be resolved by the dynamic loader. When building a dynamic library, the TPR relocations are copied to the dynamic relocation table.
The thread-local access in bare-metal can result in dynamic relocations in a code segment. This means the resulting module is not truly PIC (position independent code). The TI compiler supports bare-metal PIC with the --gen_pic option. When this option is used, TPR offsets should be accessed from GOT entry to generate position independent code.