-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Add emulated TLS support #117873
Add emulated TLS support #117873
Conversation
These commits modify compiler targets. |
I realize |
I still can't get it to work. LLVM add
|
You'll need to make changes to the symbol handling code in compiler/rustc_codegen_ssa/src/back/symbol_export.rs to add the emutls prefix. I think you can handle this in You'll want to add a field to the target spec to explicitly indicate that a target uses emulated TLS. At the moment I believe this only applies to Android and OpenHarmony (ohos) targets. |
This comment has been minimized.
This comment has been minimized.
I see that I tried modifying |
This comment has been minimized.
This comment has been minimized.
It might be worth renaming that target spec option to |
This comment has been minimized.
This comment has been minimized.
These commits modify compiler targets. |
LGTM. Let me quickly double-check with the Android target maintainers: @chriswailes @maurer @mgeisler |
Android hasn't required emutls since android Q (released in Sept 2019). Using emulated TLS has a number of negative effects around While the upstream clang isn't yet using it by default, we do have several places it is turned on in a regular Android build. We haven't turned it on globally mostly due to legacy vendor toolchains and builds which do not use I agree that enabling this for targeting SDK revisions before Q could be nice, but I would like an option equivalent to I'm also pinging people internally who know more about the status of migrating clang to use tl;dr:
|
I agree with add a Enjoy your holiday! |
Another option is to turn off |
For a command-line option, you could extend the existing |
a9d9cd1
to
5079b3b
Compare
Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt Some changes occurred in compiler/rustc_codegen_gcc cc @antoyo |
Looks like a failed rebase? |
|
5079b3b
to
9baad2a
Compare
@@ -120,6 +120,7 @@ fn to_llvm_tls_model(tls_model: TlsModel) -> llvm::ThreadLocalMode { | |||
TlsModel::LocalDynamic => llvm::ThreadLocalMode::LocalDynamic, | |||
TlsModel::InitialExec => llvm::ThreadLocalMode::InitialExec, | |||
TlsModel::LocalExec => llvm::ThreadLocalMode::LocalExec, | |||
TlsModel::EmulatedTls => llvm::ThreadLocalMode::GeneralDynamic, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried mapping to NotThreadLocal
, but this causes LLVM to not generate thread local symbol.
@@ -20,6 +20,8 @@ loaded at program startup. | |||
The TLS data must not be in a library loaded after startup (via `dlopen`). | |||
- `local-exec` - model usable only if the TLS data is defined directly in the executable, | |||
but not in a shared library, and is accessed only from that executable. | |||
- `emulated-tls` - Uses thread-specific data keys to implement emulated TLS. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I took this quote from @MaskRay 's post. ❤️
@thomcc proposal cancelled. |
b906b7d
to
a754920
Compare
This comment has been minimized.
This comment has been minimized.
a754920
to
10dfab7
Compare
Can we go ahead and merge this? :) @Amanieu |
The first comment (description) can use a better description. I was confused even if I have done a lot of clang driver work and know TLS pretty well... |
10dfab7
to
cc16abe
Compare
I've added a commit message to explain what this commit does. |
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.
cc16abe
to
e5b7689
Compare
Can you copy the commit message to the PR description? Github will include the PR description in the merge commit. r=me once the description is updated. |
@Amanieu done |
@bors r+ |
☀️ Test successful - checks-actions |
Finished benchmarking commit (608f324): comparison URL. Overall result: no relevant changes - no action needed@rustbot label: -perf-regression Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesThis benchmark run did not return any relevant results for this metric. Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 668.465s -> 670.776s (0.35%) |
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`
This is a reopen of #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:
-Zhas-thread-local
flag to specify that std uses#[thread_local]
instead of pthread key.-Zforce-emulated-tls
to-Ztls-model=emulated
to explicitly specify whether to generate emutls.r? @Amanieu