x64: Initial Executable (IE)
This code sequence implements the IE
model described in Thread-Local Storage Access Models.
Table 16-20 x64: Initial Executable, Thread-Local Variable Access Codes
Code Sequence |
Initial Relocations |
Symbol |
0x00 movq %fs:0, %rax 0x09 addq x@gottpoff(%rip), %rax # %rax - contains address of TLS variable |
<none> R_AMD64_GOTTPOFF |
x |
→ |
Outstanding Relocations |
Symbol |
GOT[n] |
R_AMD64_TPOFF64 |
x |
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 currently loaded modules. The offset is written in the GOT
entry and is later loaded by the addq
instruction.
To load the contents of x
, rather than the address of x
, the following sequence is available.
Table 16-21 x64: Initial Executable, Thread-Local Variable Access Codes II
Code Sequence |
Initial Relocations |
Symbol |
0x00 movq x@gottpoff(%rip), %rax 0x07 movq %fs:(%rax), %rax # %rax - contains contents of TLS variable |
R_AMD64_GOTTPOFF <none> |
x |
→ |
Outstanding Relocations |
Symbol |
GOT[n] |
R_AMD64_TPOFF64 |
x |