Uh oh!
There was an error while loading. Please reload this page.
set has_thread_local=true for android - #96317
Conversation
rust-highfive
commented
Apr 22, 2022
Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
|
rust-highfive
commented
Apr 22, 2022
(rust-highfive has picked a reviewer for you, use r? to override) |
rust-highfive
commented
Apr 22, 2022
|
Mark-Simulacrum
commented
Apr 24, 2022
We'll definitely want to remove the merge commit (please rebase it away). Otherwise, this seems OK in general but I don't have sufficient context here. r? @Amanieu since you merged the compiler-builtins PR. |
Amanieu
commented
Apr 25, 2022
LGTM! In general we should prefer using LLVM-backed TLS where possible since it can be optimized better. @bors r+ |
bors
commented
Apr 25, 2022
📌 Commit 73abc78 has been approved by |
set has_thread_local=true for android It seems that llvm uses emulated tls on android by default since [this commit](https://reviews.llvm.org/D42999). Which uses a `pthread_key` to emulate various tls objects at runtime([code](https://github.com/llvm-mirror/compiler-rt/blob/master/lib/builtins/emutls.c)). I've built a demo with a custom android target setting `has_thread_local=true` and a slightly modified `std` as what this PR does, and it works fine. The generated function symbol `__emutls_get_address` would link to an implementation in `libgcc.a` , which is also [required by std](https://github.com/rust-lang/rust/blob/master/library/unwind/build.rs#L18) for now. By enable `has_thread_local`, we can reduce the number of `pthread_key`s used by rust libraries on android, which are quite limited resources(128 per process). I've been investgating some crashes caused by unable to create more pthread_key in our project with about 80 `pthread_key`s used by rust part. cc rust-lang#96145 [rust-lang/compiler-builtins#458](rust-lang/compiler-builtins#458)
set has_thread_local=true for android It seems that llvm uses emulated tls on android by default since [this commit](https://reviews.llvm.org/D42999). Which uses a `pthread_key` to emulate various tls objects at runtime([code](https://github.com/llvm-mirror/compiler-rt/blob/master/lib/builtins/emutls.c)). I've built a demo with a custom android target setting `has_thread_local=true` and a slightly modified `std` as what this PR does, and it works fine. The generated function symbol `__emutls_get_address` would link to an implementation in `libgcc.a` , which is also [required by std](https://github.com/rust-lang/rust/blob/master/library/unwind/build.rs#L18) for now. By enable `has_thread_local`, we can reduce the number of `pthread_key`s used by rust libraries on android, which are quite limited resources(128 per process). I've been investgating some crashes caused by unable to create more pthread_key in our project with about 80 `pthread_key`s used by rust part. cc rust-lang#96145 [rust-lang/compiler-builtins#458](rust-lang/compiler-builtins#458)
GuillaumeGomez
commented
Apr 25, 2022
From #96380 (comment): @bors: r- |
bors
commented
May 6, 2022
☔ The latest upstream changes (presumably #96510) made this pull request unmergeable. Please resolve the merge conflicts. |
JohnCSimon
commented
May 22, 2022
ping from triage: FYI: when a PR is ready for review, send a message containing |
JohnCSimon
commented
Jun 19, 2022
Use emulated TLS for android This is a reopen of rust-lang#96317 . many android devices still only use 128 pthread keys, so using emutls can be helpful. r? `@Amanieu`
Use emulated TLS for android This is a reopen of rust-lang#96317 . many android devices still only use 128 pthread keys, so using emutls can be helpful. r? `@Amanieu`
Use emulated TLS for android This is a reopen of rust-lang#96317 . many android devices still only use 128 pthread keys, so using emutls can be helpful. r? `@Amanieu`
Use emulated TLS for android This is a reopen of rust-lang#96317 . many android devices still only use 128 pthread keys, so using emutls can be helpful. r? `@Amanieu`
Add emulated TLS support This is a reopen of rust-lang#96317 . many android devices still only use 128 pthread keys, so using emutls can be helpful. Currently LLVM uses emutls by default for some targets (such as android, openbsd), but rust does not use it, because `has_thread_local` is false. This commit has some changes to allow users to enable emutls: 1. add `-Zhas-thread-local` flag to specify that std uses `#[thread_local]` instead of pthread key. 2. when using emutls, decorate symbol names to find thread local symbol correctly. 3. change `-Zforce-emulated-tls` to `-Ztls-model=emulated` to explicitly specify whether to generate emutls. r? `@Amanieu`
Add emulated TLS support This is a reopen of rust-lang/rust#96317 . many android devices still only use 128 pthread keys, so using emutls can be helpful. Currently LLVM uses emutls by default for some targets (such as android, openbsd), but rust does not use it, because `has_thread_local` is false. This commit has some changes to allow users to enable emutls: 1. add `-Zhas-thread-local` flag to specify that std uses `#[thread_local]` instead of pthread key. 2. when using emutls, decorate symbol names to find thread local symbol correctly. 3. change `-Zforce-emulated-tls` to `-Ztls-model=emulated` to explicitly specify whether to generate emutls. r? `@Amanieu`
Add emulated TLS support This is a reopen of rust-lang/rust#96317 . many android devices still only use 128 pthread keys, so using emutls can be helpful. Currently LLVM uses emutls by default for some targets (such as android, openbsd), but rust does not use it, because `has_thread_local` is false. This commit has some changes to allow users to enable emutls: 1. add `-Zhas-thread-local` flag to specify that std uses `#[thread_local]` instead of pthread key. 2. when using emutls, decorate symbol names to find thread local symbol correctly. 3. change `-Zforce-emulated-tls` to `-Ztls-model=emulated` to explicitly specify whether to generate emutls. r? `@Amanieu`
Add emulated TLS support This is a reopen of rust-lang/rust#96317 . many android devices still only use 128 pthread keys, so using emutls can be helpful. Currently LLVM uses emutls by default for some targets (such as android, openbsd), but rust does not use it, because `has_thread_local` is false. This commit has some changes to allow users to enable emutls: 1. add `-Zhas-thread-local` flag to specify that std uses `#[thread_local]` instead of pthread key. 2. when using emutls, decorate symbol names to find thread local symbol correctly. 3. change `-Zforce-emulated-tls` to `-Ztls-model=emulated` to explicitly specify whether to generate emutls. r? `@Amanieu`
Add emulated TLS support This is a reopen of rust-lang/rust#96317 . many android devices still only use 128 pthread keys, so using emutls can be helpful. Currently LLVM uses emutls by default for some targets (such as android, openbsd), but rust does not use it, because `has_thread_local` is false. This commit has some changes to allow users to enable emutls: 1. add `-Zhas-thread-local` flag to specify that std uses `#[thread_local]` instead of pthread key. 2. when using emutls, decorate symbol names to find thread local symbol correctly. 3. change `-Zforce-emulated-tls` to `-Ztls-model=emulated` to explicitly specify whether to generate emutls. r? `@Amanieu`
It seems that llvm uses emulated tls on android by default since this commit. Which uses a
pthread_keyto emulate various tls objects at runtime(code).I've built a demo with a custom android target setting
has_thread_local=trueand a slightly modifiedstdas what this PR does, and it works fine. The generated function symbol__emutls_get_addresswould link to an implementation inlibgcc.a, which is also required by std for now.By enable
has_thread_local, we can reduce the number ofpthread_keys used by rust libraries on android, which are quite limited resources(128 per process). I've been investgating some crashes caused by unable to create more pthread_key in our project with about 80pthread_keys used by rust part.cc #96145rust-lang/compiler-builtins#458