bytecodealliance / bytecodealliance/wasmtime
Support TLS in cranelift_jit
- Dominant language
- Rust
- Stars
- 18.6k
- Forks
- 1.8k
- Avg merge
- 1d 18h
- Merged PRs (30d)
- 126
Description
#### Feature
See issue title.
#### Benefit
Required by cg_clif's jit mode.
#### Implementation
Give every defined jit tls variable a globally unique id using a global atomic counter. Next define a single native TLS variable inside `cranelift_jit`. This TLS variable points to a vec of pointers indexed by the previously mentioned globally unique id. Require the elf_tls_gd tls model and forward `__tls_get_addr` to a function of cranelift_jit that looks up the tls variable address using the native tls variable and initializes the tls variable if necessary.
This implementation method doesn't allow importing native tls variables, supporting native tls requires support from libc and rust never exports tls variables directly anyway. `thread_local!` wraps it in a function call.
#### Alternatives
Add a bunch of special cases in cg_clif to use a different tls declaration method when in jit mode and implement this proposal in cg_clif itself. This increases complexity and reduces reusability.
Contributor guide
Assessment
This issue has not been assessed yet.