- The relocation specifier @got@tlsld in the first instruction causes
- the link editor to generate a tls_index data object in the GOT with a
- fixed 0 offset. The following code assumes that x1 is in the first 64 KB
- of the thread storage block. The x2 symbol is not within the first 64 KB
- but is within the first 2 GB, and x3 is outside the 2 GB area. To load
- the values of x1, x2, and x3 instead of their addresses, replace the
- latter part of
- with the following code
- sequence.
-
-
+ The relocation specifier @got@tlsld in the first instruction causes
+ the link editor to generate a tls_index data object in the GOT with a
+ fixed 0 offset. The following code assumes that x1 is in the first 64 KB
+ of the thread storage block. The x2 symbol is not within the first 64 KB
+ but is within the first 2 GB, and x3 is outside the 2 GB area. To load
+ the values of x1, x2, and x3 instead of their addresses, replace the
+ latter part of
+ with the following code
+ sequence.
+
+
+
+ Initial Exec TLS Model
+ Given the following code fragment, the relocation sequence in
+ is used for the Initial Exec
+ TLS Model:
+ extern __thread unsigned int x;
+&x;
+
+ The relocation specifier @got@tprel in the first instruction causes
+ the link editor to generate a GOT entry with a relocation that the
+ dynamic linker will replace with the offset for x relative to the thread
+ pointer. The relocation specifier x@tls tells the assembler to use an r13
+ form of the instruction. That is, add r9,r9,r13 in this case, and tag the
+ instruction with a relocation that indicates it belongs to a TLS
+ sequence. This relocation specifier can be used later by the link editor
+ when optimizing TLS code.
+
+ To read the contents of the variable instead of calculating its
+ address, the add r9, r9, x@tls instruction
+
+ in
+
+ might be replaced with lwzx r0, r9, x@tls.
+
+ The add r9, r9, x@tls@pcrel instruction in might likewise be replaced
+ with lwzx r0, r9, x@tls@pcrel.
+
+
+
+ Note that both the x@tls and x@tls@pcrel assembly forms are
+ annotated with R_PPC64_TLS relocations. To distinguish
+ between the two, the second of these has a field value
+ displaced by one byte from the beginning of the instruction.
+
+
+
+ Local Exec TLS Model
+ Given the following code fragment, three different relocation
+ sequences may be used, depending on the size of the offset to the
+ variable. The sequence in
+ handles offsets within 60 KB
+ relative to the end of the TCB (where r13 points 28 KB past the end of
+ the TCB, which is immediately before the first TLS block). The sequence
+ in
+ handles offsets past 60 KB and
+ less than 2 GB + 28 KB relative to the end of the TCB. The third sequence
+ is identical to the Initial Exec sequence shown in
+ .
+ static __thread unsigned int x;
+&x;
+ illustrates which sequence is
+ used.
+
+
+
+
+
+
+ TLS Link Editor Optimizations
+ In some cases, the link editor may be able to optimize TLS code
+ sequences, provided the compiler emits code sequences as
+ described.
+ The following TLS link editor transformations are provided as
+ optimizations to convert between specific TLS access models:
+
+
+ General Dynamic to Initial Exec
+
+
+ General Dynamic to Local Exec
+
+
+ Local Dynamic to Local Exec
+
+
+ Initial Exec to Local Exec
+
+
+
+ through describe TLS link editor
+ transformations using a TOC addressing model, and through describe TLS link editor
+ transformations using a PC-relative addressing model.
+
+
+ General Dynamic to Initial Exec (TOC)
+
+ The preceding code and global offset table entries are replaced by
+ the following code, which makes no reference to GOT entries. The GOT
+ entries in
+ can be removed from the GOT by
+ the linker when performing this code transformation.
+ To further optimize the code in
+ , a linker may reschedule the
+ sequence to exploit fusion by generating a sequence that may be fused
+ by Power processors:
+ nop
+addis r3, r13, x@tprel@ha
+addi r3, r3, x@tprel@l
+nop
+
+
+
+
+ Local Dynamic to Local Exec
+ (TOC)
+
+ Under this TLS linker optimization, the function call is replaced
+ with an equivalent code sequence. However, as shown in the following code
+ examples, the dtprel sequences are left unchanged.
+
+ The local symbol generated by the link editor points to the start
+ of the thread storage block plus 0x7000 bytes. In practice, a section
+ symbol with a suitable offset will be used.
+
+
+ Initial Exec to Local Exec
+ (TOC)
+
+ This transformation is only performed by the linker when the symbol
+ is within 2 GB + 28 KB of the thread pointer.
+
-
-
- Initial Exec TLS Model
- Given the following code fragment, the relocation sequence in
- is used for the Initial Exec
- TLS Model:
- extern __thread unsigned int x;
-&x;
-
- Initial Exec Initial Relocations
+ Other sizes and types of thread-local variables may use any of the
+ X-form indexed load or store instructions.
+
+ shows how to access the
+ contents of a variable using the X-form indexed load and store
+ instructions.
+
- The relocation specifier @got@tprel in the first instruction causes
- the link editor to generate a GOT entry with a relocation that the
- dynamic linker will replace with the offset for x relative to the thread
- pointer. The relocation specifier x@tls tells the assembler to use an r13
- form of the instruction. That is, add r9,r9,r13 in this case, and tag the
- instruction with a relocation that indicates it belongs to a TLS
- sequence. This relocation specifier can be used later by the link editor
- when optimizing TLS code.
- To read the contents of the variable instead of calculating its
- address, the add r9, r9, x@tls instruction might be replaced with lwzx
- r0, r9, x@tls.
-
-
- Local Exec TLS Model
- Given the following code fragment, three different relocation
- sequences may be used, depending on the size of the offset to the
- variable. The sequence in
- handles offsets within 60 KB
- relative to the end of the TCB (where r13 points 28 KB past the end of
- the TCB, which is immediately before the first TLS block). The sequence
- in
- handles offsets past 60 KB and
- less than 2 GB + 28 KB relative to the end of the TCB. The third sequence
- is identical to the Initial Exec sequence shown in
- .
- static __thread unsigned int x;
-&x;
- illustrates which sequence is
- used.
-
-
-
- Local Exec Initial Relocations (Sequence 1)
+ The preceding code and global offset table entries are replaced by
+ the following code and global offset table entries.
+
-
-
- TLS Link Editor Optimizations
- In some cases, the link editor may be able to optimize TLS code
- sequences, provided the compiler emits code sequences as
- described.
- The following TLS link editor transformations are provided as
- optimizations to convert between specific TLS access models:
-
-
- General Dynamic to Initial Exec
-
-
- General Dynamic to Local Exec
-
-
- Local Dynamic to Local Exec
-
-
- Initial Exec to Local Exec
-
-
-
- General Dynamic to Initial Exec
-
+
+ General Dynamic to Initial Exec (PC-Relative)
+ General-Dynamic-to-Local-Exec GOT Entry Relocations
+ (PC-Relative)
@@ -6801,7 +8685,7 @@ static __thread unsigned int x3;
the following code, which makes no reference to GOT entries. The GOT
entries in
can be removed from the GOT by
- the linker when performing this code transformation.
+ the linker when performing this code transformation.To further optimize the code in
, a linker may reschedule the
sequence to exploit fusion by generating a sequence that may be fused
@@ -6811,10 +8695,9 @@ addis r3, r13, x@tprel@ha
addi r3, r3, x@tprel@l
nop
-
-
- Local Dynamic to Local Exec
+
+ Local Dynamic to Local Exec (PC-Relative)Under this TLS linker optimization, the function call is replaced
with an equivalent code sequence. However, as shown in the following code
examples, the dtprel sequences are left unchanged.
-
-
- The preceding code and global offset table entries are replaced by
the following code and global offset table entries.
-
Local-Dynamic-to-Local-Exec Replacement Initial
- Relocations
+ Relocations (PC-Relative)
@@ -7335,9 +9215,9 @@ nop
The GOT[n] and GOT[n+1] entries can be removed by the linker after
the code transformation as shown in
.
-
+
Local-Dynamic-to-Local-Exec Replacement GOT Entry
- Relocations
+ Relocations (PC-Relative)
@@ -7380,11 +9260,10 @@ nop
of the thread storage block plus 0x7000 bytes. In practice, a section
symbol with a suitable offset will be used.
-
- Initial Exec to Local Exec
+
+ Initial Exec to Local Exec (PC-Relative)This transformation is only performed by the linker when the symbol
is within 2 GB + 28 KB of the thread pointer.
-
The preceding code and global offset table entries are replaced by
the following code and global offset table entries.
-
Initial-Exec-to-Local-Exec Replacement Initial
- Relocations
+ Relocations (PC-Relative)
@@ -7552,9 +9430,9 @@ nop
shows how to access the
contents of a variable using the X-form indexed load and store
instructions.
-
-