This code sequence implements the IE model described in Thread-Local Storage Access Models.
Table 8–20 x64: Initial Executable, Thread-Local Variable Access Codes
The R_AMD64_GOTTPOFF relocation for the symbol x requests the link-editor to generate a GOT entry and an associated R_AMD64_TPOFF64 relocation. The offset of the GOT entry relative to the end of the x@gottpoff(%rip) instruction, is then used by the instruction. The R_AMD64_TPOFF64 relocation uses the value of the symbol x that is determined from the presently loaded modules. The offset is written in the GOT entry and later loaded by the addq instruction.
To load the contents of x, rather than the address of x, the following sequence is available.
Table 8–21 x64: Initial Executable, Thread-Local Variable Access Codes II