-
Notifications
You must be signed in to change notification settings - Fork 13.4k
[sanitizer][Darwin] Define TlsSize on arm64 #133989
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
base: main
Are you sure you want to change the base?
Conversation
β With the latest revision this PR passed the C/C++ code formatter. |
@llvm/pr-subscribers-compiler-rt-sanitizer Author: Leonard Grey (speednoisemovement) ChangesFull diff: https://github.com/llvm/llvm-project/pull/133989.diff 1 Files Affected:
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp
index 0b8a75391136d..70d8cddc6e573 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp
@@ -558,16 +558,12 @@ uptr TlsBaseAddr() {
return segbase;
}
-// The size of the tls on darwin does not appear to be well documented,
-// however the vm memory map suggests that it is 1024 uptrs in size,
-// with a size of 0x2000 bytes on x86_64 and 0x1000 bytes on i386.
-uptr TlsSize() {
-#if defined(__x86_64__) || defined(__i386__)
- return 1024 * sizeof(uptr);
-#else
- return 0;
-#endif
-}
+// The size of the tls on darwin does not appear to be well documented.
+// but `pthread_s`'s `tsd` member (see libpthread/src/types_internal.h) is
+// defined as `_INTERNAL_POSIX_THREAD_KEYS_MAX +
+// `_INTERNAL_POSIX_THREAD_KEYS_END` (512 pointers on iPhone and 768 elsewhere).
+// Keep at 1024 for backwards compatibility.
+uptr TlsSize() { return 1024 * sizeof(uptr); }
void GetThreadStackAndTls(bool main, uptr *stk_begin, uptr *stk_end,
uptr *tls_begin, uptr *tls_end) {
|
@speednoisemovement Iβm pinging my colleagues to see if they have any concerns about this. |
// defined as `_INTERNAL_POSIX_THREAD_KEYS_MAX + | ||
// `_INTERNAL_POSIX_THREAD_KEYS_END` (512 pointers on iPhone and 768 elsewhere). | ||
// Keep at 1024 for backwards compatibility. | ||
uptr TlsSize() { return 1024 * sizeof(uptr); } |
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.
#if TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR
#define _EXTERNAL_POSIX_THREAD_KEYS_MAX 256
#define _INTERNAL_POSIX_THREAD_KEYS_MAX 256
#define _INTERNAL_POSIX_THREAD_KEYS_END 512
#else
#define _EXTERNAL_POSIX_THREAD_KEYS_MAX 512
#define _INTERNAL_POSIX_THREAD_KEYS_MAX 256
#define _INTERNAL_POSIX_THREAD_KEYS_END 768
#endif
void *tsd[_EXTERNAL_POSIX_THREAD_KEYS_MAX + _INTERNAL_POSIX_THREAD_KEYS_MAX];
https://github.com/apple-oss-distributions/libpthread/blob/libpthread-535/src/types_internal.h#L418
512 pointers on iPhone and 768 elsewhere
π
Currently we are returning 1024 on macOS/Intel or 0 elsewhere, both wrong! :/
@speednoisemovement, can you comment on the "why?", which problem is this solving?
TlsSize()
is used only in GetThreadStackAndTls()
. What is the nature of this function? Is the conservative answer to return a lower ("only touch this much") or upper ("at least poison this much") bound? Depending on that we should return 512
or 768
.
We could also sidestep this question and return the exact answer. Not too much worse since we are already hardcoding a value derived from an internal header in any case.
// Derived from:
// https://github.com/apple-oss-distributions/libpthread/blob/libpthread-535/src/types_internal.h#L418
uptr TlsSize() {
#if SANITIZER_IOS && !SANITIZER_IOSSIM
return 512 * sizeof(uptr);
#else
return 768 * sizeof(uptr);
#endif
}
β¬οΈ Voting for this if others don't have concerns.
This change has some consequences, it will cause a call to DontNeedShadowFor(thr->tls_addr, thr->tls_size) (than_rtl.cpp:222) to happen where it used to not happen, on arm64 . Perhaps those are harmless, but - why do you need this change to happen, is it a part of something bigger? Also, sanitizer_mac.cpp:244 : uptr GetTlsSize() { , which seems to return same thing and will be inconsistent with TlsSize(), perhaps it'll need some refactoring to decrease confusion potential. |
Thanks for reviewing! The motivation is to bring some parity for LSAN since anything that gets stashed in TSD is a false positive on arm64 right now. I'll look into |
No description provided.