-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
set has_thread_local=true for android #96317
Conversation
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 has picked a reviewer for you, use r? to override) |
|
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. |
c6fce73
to
73abc78
Compare
LGTM! In general we should prefer using LLVM-backed TLS where possible since it can be optimized better. @bors r+ |
📌 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)
From #96380 (comment): @bors: r- |
☔ The latest upstream changes (presumably #96510) made this pull request unmergeable. Please resolve the merge conflicts. |
ping from triage: FYI: when a PR is ready for review, send a message containing |
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_key
to emulate various tls objects at runtime(code).I've built a demo with a custom android target setting
has_thread_local=true
and a slightly modifiedstd
as what this PR does, and it works fine. The generated function symbol__emutls_get_address
would 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_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 80pthread_key
s used by rust part.cc #96145 rust-lang/compiler-builtins#458