-
Notifications
You must be signed in to change notification settings - Fork 4.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
Enable TLS on linux/arm64 only for static resolver #104408
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -806,20 +806,31 @@ bool CanJITOptimizeTLSAccess() | |||||
#elif !defined(TARGET_OSX) && defined(TARGET_UNIX) && defined(TARGET_ARM64) | ||||||
// Optimization is enabled for linux/arm64 only for static resolver. | ||||||
// For static resolver, the TP offset is same for all threads. | ||||||
// For dynamic resolver, TP offset returned is that of a JIT thread and | ||||||
// will be different for the executing thread. | ||||||
// For dynamic resolver, TP offset returned is for the current thread and | ||||||
// will be different for the other threads. | ||||||
uint32_t* resolverAddress = reinterpret_cast<uint32_t*>(GetTLSResolverAddress()); | ||||||
if ( | ||||||
int ip = 0; | ||||||
if ((resolverAddress[ip] == 0xd503201f) || (resolverAddress[ip] == 0xd503241f)) | ||||||
{ | ||||||
// nop might not be present in older resolver, so skip it. | ||||||
jkotas marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
// nop or hint 32 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since "hint 32" is an instruction and I preferred having instruction in the comment, should I keep it as-is? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||
((resolverAddress[0] == 0xd503201f) || (resolverAddress[0] == 0xd503241f)) && | ||||||
ip++; | ||||||
} | ||||||
|
||||||
if ( | ||||||
// ldr x0, [x0, #8] | ||||||
(resolverAddress[1] == 0xf9400400) && | ||||||
(resolverAddress[ip] == 0xf9400400) && | ||||||
// ret | ||||||
(resolverAddress[2] == 0xd65f03c0) | ||||||
(resolverAddress[ip + 1] == 0xd65f03c0) | ||||||
) | ||||||
{ | ||||||
optimizeThreadStaticAccess = true; | ||||||
kunalspathak marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
} | ||||||
else | ||||||
{ | ||||||
_ASSERTE(false && "Unexpected code sequence."); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add a test that validates this fallback? I expect this question is going to be asked during servicing review. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make sense. What is the right way to add a test? Force dynamic resolver to kick in or something? Need to find out how to do that though. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rigth:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Interesting, my impression was using some kind of compiler flag or an attribute.
But even if I get it to use the dynamic resolver, the question would be how to check that the TLS optimization is disabled I suppose. I believe I will have to still write managed code containing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of this assert, you can add a debug-only config switch that says whether we expect dynamic or static resolver. If we come here and we do not the expected resolver, assert. I think it is good-enough for the test to be effective on checked build only. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The test should do some thread static accesses from multiple threads to make sure that they work. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
You can use disasm checks to do this too. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Seems like a reasonable feature. I would create a new environment variables that loads an arbitrary DLL early on. Once tht is in, I will update the host policy mechanism to use that. |
||||||
} | ||||||
#else | ||||||
optimizeThreadStaticAccess = true; | ||||||
kunalspathak marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
#if !defined(TARGET_OSX) && defined(TARGET_UNIX) && defined(TARGET_AMD64) | ||||||
|
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.
runtime/src/coreclr/jit/helperexpansion.cpp
Lines 970 to 974 in a7efcd9
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.
Yes, I thought about NativeAOT too, but realized that it might be always static resolver.
We can detect static/dynamic resolver for JITting on the fly, but for nativeaot, it might be tricky to know that information ahead of time. Possibly, we might have to embed that check in the generated code itself? But that might add an extra check for code for which we mostly get static resolver.
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.
For native AOT, we should generate the call to the resolver via indirection just like C/C++ compiler does when building dynamic libraries.