|
33 | 33 | // for new threads, and no one write to it at runtime. |
34 | 34 | // |
35 | 35 | // Now, let's think about how to access a TLV. We need to know the TLV's |
36 | | -// address to access it, and that can be done in various ways as follows: |
| 36 | +// address to access it which can be done in various ways as follows: |
37 | 37 | // |
38 | 38 | // 1. If we are creating an executable, we know the exact size of the TLS |
39 | 39 | // template image we are creating, and we know where the TP will be |
40 | 40 | // set to after the template is copied to the TLS block. Therefore, |
41 | | -// the TP-relative address of a TLV in the main executable can be |
42 | | -// computed at link-time. That means, computing a TLV's address can be |
43 | | -// as easy as `add %dst, %tp, <link-time constant>`. |
| 41 | +// the TP-relative address of a TLV in the main executable is known at |
| 42 | +// link-time. That means, computing a TLV's address can be as easy as |
| 43 | +// `add %dst, %tp, <link-time constant>`. |
44 | 44 | // |
45 | 45 | // 2. If we are creating a shared library, we don't excatly know where |
46 | | -// its TLS template image will be copied to relative to other files' |
47 | | -// TLS blocks, because we don't know how large is the main |
48 | | -// executable's and other libraries' TLS template images are. Only the |
49 | | -// runtime knows the exact TP-relative address. |
| 46 | +// its TLS template image will be copied to relative TP, because we |
| 47 | +// don't know how large is the main executable's and other libraries' |
| 48 | +// TLS template images are. Only the runtime knows the exact |
| 49 | +// TP-relative address. |
50 | 50 | // |
51 | 51 | // We can solve the problem with an indirection. Specifically, for |
52 | 52 | // each TLV whose TP-relative address is only known at process startup |
@@ -141,7 +141,9 @@ u64 get_tls_begin(Context<E> &ctx) { |
141 | 141 | } |
142 | 142 |
|
143 | 143 | // Returns the TP address which can be used for efficient TLV accesses in |
144 | | -// the main executable. |
| 144 | +// the main executable. TP at runtime refers to a per-process TLS block |
| 145 | +// whose address is not known at link-time. So the address returned from |
| 146 | +// this function is the TP if the TLS template image were a TLS block. |
145 | 147 | template <typename E> |
146 | 148 | u64 get_tp_addr(Context<E> &ctx) { |
147 | 149 | ElfPhdr<E> *phdr = get_tls_segment(ctx); |
@@ -172,14 +174,13 @@ u64 get_tp_addr(Context<E> &ctx) { |
172 | 174 | // TP. RISC-V load/store instructions usually take 12-bits signed |
173 | 175 | // immediates, so the beginning of TLV ± 2 KiB is accessible with a |
174 | 176 | // single load/store instruction. |
175 | | - if (is_riscv<E>) |
| 177 | + if constexpr (is_riscv<E>) |
176 | 178 | return phdr->p_vaddr; |
177 | 179 |
|
178 | 180 | unreachable(); |
179 | 181 | } |
180 | 182 |
|
181 | | -// Returns the address in the TLS template image when __tls_get_addr would |
182 | | -// be called with offset 0. |
| 183 | +// Returns the address when __tls_get_addr would be called with offset 0. |
183 | 184 | template <typename E> |
184 | 185 | u64 get_dtp_addr(Context<E> &ctx) { |
185 | 186 | ElfPhdr<E> *phdr = get_tls_segment(ctx); |
|
0 commit comments