-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[android] Use emulated thread-local storage for API 28 and earlier #77883
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
Merged
+27
−0
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#include "shims/SwiftStdint.h" | ||
|
||
static inline __swift_uint32_t _swift_stdlib_gettid() { | ||
static __thread __swift_uint32_t tid = 0; | ||
|
||
return tid; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// RUN: %target-swift-frontend -Xcc -femulated-tls %s -S -import-objc-header %S/Inputs/tls.h | %FileCheck %s --check-prefix=EMUTLS --check-prefix=EMUTLS-%target-os | ||
// RUN: %target-swift-frontend -Xcc -fno-emulated-tls %s -S -import-objc-header %S/Inputs/tls.h | %FileCheck %s --check-prefix=NOEMUTLS | ||
|
||
_swift_stdlib_gettid() | ||
|
||
// EMUTLS: __emutls_v._swift_stdlib_gettid.tid | ||
// EMUTLS-linux-android: __emutls_get_address | ||
// EMUTLS-linux-gnu: __emutls_get_address | ||
// EMUTLS-macosx: __emutls_get_address | ||
// EMUTLS-openbsd: __emutls_get_address | ||
// EMUTLS-windows-msvc: __emutls_get_address | ||
// EMUTLS-wasi-NOT: __emutls_get_address | ||
|
||
// NOEMUTLS-NOT: __emutls_v._swift_stdlib_gettid.tid | ||
// NOEMUTLS-NOT: __emutls_get_address |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Hmm, why is this negated for WASI? Perhaps we should warn about the ignored setting?
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 honestly didn't want to deal with WASI at all, but was forced to because the linux CI builds it and runs these tests for it too.
My understanding is that the initial
__emutls_v._swift_stdlib_gettid.tid
symbol is swapped in because the LLVM codegen pass runs on all platforms, but it doesn't have__emutls_get_address
in compiler-rt, like the other platforms do, so it doesn't call that function. I could've simply disabled this test for WASI instead, but I figured it was worth checking the__emutls_v._swift_stdlib_gettid.tid
symbol at least on all platforms.This is just an artifact of the current CI and WASI support, I don't think it's worth addressing in the test.
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.
Ah, okay, its just that the call is something else? That seems reasonable enough then. Perhaps an issue to track restoring this would be good.
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 don't know: I just did what I had to do to get the test to pass, as the CI was forcing me to address WASI but I'm not that familiar with it, didn't know if it even had threads yet. Looking at the relevant LLVM source now, the
LowerToTLSEmulatedModel()
method that inserts the__emutls_get_address
call is not invoked for the WASM target, as it is for several other architectures. It appears that WASI threads is still in the standardization phase, so the implementation may still be in flux.@kateinoigakukun, could you let us know if this might be a useful flag for WASM one day and if this test is okay for now?
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.
All WebAssembly targets currently have proper TLS support (assuming dynamic linking is only for Emscripten, not with WASI), so the lowering does not implement emulation at all and silently ignores the option today as you mentioned. The thread representation model in Wasm is still unstable but I don't expect we need the emulation in the future, so it's fine as is now.