The tls_model attribute (IBM extension)

The tls_model attribute allows source-level control for the thread-local storage model used for a given variable. The tls_model attribute must specify one of local-exec, initial-exec, local-dynamic, or global-dynamic access method, which overrides the -qtls option for that variable. For example:
__thread int i __attribute__((tls_model("local-exec")));

The tls_model attribute allows the linker to check that the correct thread model has been used to build the application or shared library. The linker/loader behavior is as follows:

Table 1. Link time/runtime behavior for thread access models
Access method Link-time diagnostic Runtime diagnostic
local-exec Fails if referenced symbol is imported. Fails if module is not the main program. Fails if referenced symbol is imported (but the linker should have detected the error already).
initial-exec None. dlopen()/load() fails if referenced symbol is not in the module loaded at execution time.
local-dynamic Fails if referenced symbol is imported. Fails if referenced symbol is imported (but the linker should have detected the error already).
global-dynamic None. None.