You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
.2+| 62-191 .2+| *Reserved* .2+| - | .2+| Reserved for future standard use
457
+
.2+| 62 .2+| TLSDESC_HI20 .2+| Static | _U-Type_ .2+| High 20 bits of a 32-bit PC-relative offset into a TLS descriptor entry, `%tlsdesc_hi(symbol)`
458
+
<| S + A - P
459
+
.2+| 63 .2+| TLSDESC_LOAD_LO12 .2+| Static | _I-Type_ .2+| Low 12 bits of a 32-bit PC-relative offset into a TLS descriptor entry, `%tlsdesc_load_lo(address of %tlsdesc_hi)`, the addend must be 0
460
+
<| S - P
461
+
.2+| 64 .2+| TLSDESC_ADD_LO12 .2+| Static | _I-Type_ .2+| Low 12 bits of a 32-bit PC-relative offset into a TLS descriptor entry, `%tlsdesc_add_lo(address of %tlsdesc_hi)`, the addend must be 0
462
+
<| S - P
463
+
.2+| 65 .2+| TLSDESC_CALL .2+| Static | .2+| Annotate call to TLS descriptor resolver function, `%tlsdesc_call(address of %tlsdesc_hi)`, for relaxation purposes only
464
+
<|
465
+
.2+| 66-191 .2+| *Reserved* .2+| - | .2+| Reserved for future standard use
456
466
<|
457
467
.2+| 192-255 .2+| *Reserved* .2+| - | .2+| Reserved for nonstandard ABI extensions
458
468
<|
@@ -805,7 +815,7 @@ thread local storage models:
805
815
806
816
[[tls-model]]
807
817
.TLS models
808
-
[cols="1,2,3"]
818
+
[cols="1,2"]
809
819
[width=70%]
810
820
|===
811
821
| Mnemonic | Model
@@ -941,6 +951,55 @@ typedef struct
941
951
} tls_index;
942
952
----
943
953
954
+
==== TLS Descriptors
955
+
956
+
TLS Descriptors (TLSDESC) are an alternative implementation of the Global Dynamic model
957
+
that allows the dynamic linker to achieve performance close to that
958
+
of Initial Exec when the library was not loaded dynamically with `dlopen`.
959
+
960
+
The linker reserves a consecutive pair of pointer-sized entry in the GOT for each `TLSDESC`
961
+
relocation. At runtime, the dynamic linker fills in the TLS descriptor entry as defined below:
962
+
963
+
[,c]
964
+
----
965
+
typedef struct
966
+
{
967
+
unsigned long (*entry)(tls_descriptor *);
968
+
unsigned long arg;
969
+
} tls_descriptor;
970
+
----
971
+
972
+
Upon accessing the thread local variable, the `entry` function is called with the address
973
+
of `tls_descriptor` containing it, returning `<address of thread local variable> - tp`.
974
+
975
+
The TLS descriptor `entry` is called with a special calling convention, specified as follows:
976
+
977
+
- `a0` is used to pass the argument and return value.
978
+
- `t0` is used as the link register.
979
+
- Any other registers are callee-saved. This includes any vector registers when the vector extension is supported.
980
+
981
+
Example assembler load and store of a thread local variable `i` using the `%tlsdesc_hi`, `%tlsdesc_load_lo`, `%tlsdesc_add_lo` and `%tlsdesc_call`
982
+
assembler functions. The emitted relocations are in the comments.
`tX` and `tY` in the example may be replaced with any combination of two general purpose registers.
994
+
995
+
The `%tlsdesc_call` assembler function does not return a value and is used purely
996
+
to associate the `R_RISCV_TLSDESC_CALL` relocation with the `jalr` instruction.
997
+
998
+
The linker can use the relocations to recognize the sequence and to perform relaxations. To ensure correctness, only the following changes to the sequence are allowed:
999
+
1000
+
- Instructions outside the sequence that do not clobber the registers used within the sequence may be inserted in-between the instructions of the sequence (known as instruction scheduling).
1001
+
- Instructions in the sequence with no data dependency may be reordered. In the preceding example, the only instructions that can be reordered are `lw` and `addi`.
Description:: This relaxation can relax a sequence loading the address of a thread-local symbol reference into a thread-pointer-relative instruction sequence.
1717
+
1718
+
Condition::
1719
+
1720
+
- Short form only: Offset between thread-pointer and thread-local symbol is within +-2KiB.
1721
+
- Linker output is an executable.
1722
+
- Target symbol is non-preemptible.
1723
+
1724
+
Relaxation::
1725
+
1726
+
- Instruction associated with `R_RISCV_TLSDESC_HI20` or `R_RISCV_TLSDESC_LOAD_LO12_I` can be removed.
1727
+
- Instruction associated with `R_RISCV_TLSDESC_ADD_LO12_I` can be replaced with the high TP-relative offset of symbol (long form) or be removed (short form).
1728
+
- Instruction associated with `R_RISCV_TLSDESC_CALL` can be replaced with the low TP-relative offset of symbol.
1729
+
1730
+
Example::
1731
+
+
1732
+
--
1733
+
Relaxation candidate (`tX` and `tY` can be any combination of two general purpose registers):
0 commit comments