SPRAB89A September 2011 – March 2014
In the Static Executable TLS model, the function __c6xabi_get_tp() is called to get the thread pointer value of the current thread. If a thread library is used, it is responsible for providing this function.
The thread library knows the address of the TLS block for the threads it creates. However, the main thread is not created by the thread library, so the thread library needs a standard way to find the address of the main thread’s TLS block. As mentioned previously, the static linker defines the symbol __TI_TLS MAIN_THREAD_BASE for this purpose.
The TI RTS provides the following definition for the __c6xabi_get_tp() function:
extern __attribute__((weak)) far const void * __TI_TLS_MAIN_THREAD_Base;
__attribute__((weak)) void * __c6xabi_get_tp(void)
{
return &__TI_TLS_MAIN_THREAD_Base;
}
This function is defined as "weak" so that a strong definition from the thread library will be used if one is present.
Let us consider the unlikely case in which a user declares thread-local variables but does not include the thread library. Obviously they cannot create any new threads. But the main thread should work and the main thread’s thread-local variables should be accessible. In such cases, the previously mentioned RTS function is linked in and provides access to the main thread’s TLS.