SPARC: Local Dynamic (LD)
This code sequence implements the LD
model described in Thread-Local Storage Access Models.
Table 16-3 SPARC: Local Dynamic Thread-Local Variable Access Codes
Code Sequence |
Initial Relocations |
Symbol |
# %l7 - initialized to GOT pointer 0x00 sethi %hi(@tmndx(x1)), %o0 0x04 add %o0, %lo(@tmndx(x1)), %o0 0x08 add %l7, %o0, %o0 0x0c call x@TLSPLT # %o0 - contains address of TLS block of current object 0x10 sethi %hi(@dtpoff(x1)), %l1 0x14 xor %l1, %lo(@dtpoff(x1)), %l1 0x18 add %o0, %l1, %l1 # %l1 - contains address of local TLS variable x1 0x20 sethi %hi(@dtpoff(x2)), %l2 0x24 xor %l2, %lo(@dtpoff(x2)), %l2 0x28 add %o0, %l2, %l2 # %l2 - contains address of local TLS variable x2 |
R_SPARC_TLS_LDM_HI22 R_SPARC_TLS_LDM_LO10 R_SPARC_TLS_LDM_ADD R_SPARC_TLS_LDM_CALL R_SPARC_TLS_LDO_HIX22 R_SPARC_TLS_LDO_LOX10 R_SPARC_TLS_LDO_ADD R_SPARC_TLS_LDO_HIX22 R_SPARC_TLS_LDO_LOX10 R_SPARC_TLS_LDO_ADD |
x1 x1 x1 x1 x1 x1 x1 x2 x2 x2 |
→ |
Outstanding Relocations: 32-bit |
Symbol |
GOT[n] GOT[n + 1] |
R_SPARC_TLS_DTPMOD32 <none> |
x1 |
→ |
Outstanding Relocations: 64-bit |
Symbol |
GOT[n] GOT[n + 1] |
R_SPARC_TLS_DTPMOD64 <none> |
x1 |
The first sethi
instruction and add
instruction generate R_SPARC_TLS_LDM_HI22
and R_SPARC_TLS_LDM_LO10
relocations respectively. These relocations instruct the link-editor to allocate space in the GOT
to hold a TLS_index
structure for the current object. The link-editor processes this relocation by substituting the GOT
-relative offset for the new GOT
entry.
The load object index is not known until runtime. Therefore, a R_SPARC_TLS_DTPMOD32
relocation is created, and the ti_tlsoffset
field of the TLS_index
structure is zero filled.
The second add
and the call
instruction are tagged with the R_SPARC_TLS_LDM_ADD
and R_SPARC_TLS_LDM_CALL
relocations respectively.
The following sethi
instruction and xor
instruction generate the R_SPARC_LDO_HIX22
and R_SPARC_TLS_LDO_LOX10
relocations, respectively. The TLS offset for each local symbol is known at link-edit time, therefore these values are filled in directly. The add
instruction is tagged with the R_SPARC_TLS_LDO_ADD
relocation.
When a procedure references more than one local symbol, the compiler generates code to obtain the base address of the TLS block once. This base address is then used to calculate the address of each symbol without a separate library call.
Note:
The register containing the TLS object address in theadd
instruction tagged by the R_SPARC_TLS_LDO_ADD
must be the first register in the instruction sequence. This requirement permits the link-editor to identify the register during a code transformation.