-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[sanitizer] Remove GetCurrentThread nullness checks from Allocate #102828
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
[sanitizer] Remove GetCurrentThread nullness checks from Allocate #102828
Conversation
Created using spr 1.3.5-bogner
@llvm/pr-subscribers-compiler-rt-sanitizer Author: Fangrui Song (MaskRay) ChangesThe Make this change for asan/msan and possibly extend the change to other Full diff: https://github.com/llvm/llvm-project/pull/102828.diff 2 Files Affected:
diff --git a/compiler-rt/lib/asan/asan_allocator.cpp b/compiler-rt/lib/asan/asan_allocator.cpp
index 9e66f77217ec6b..e041861edaf0b7 100644
--- a/compiler-rt/lib/asan/asan_allocator.cpp
+++ b/compiler-rt/lib/asan/asan_allocator.cpp
@@ -576,15 +576,8 @@ struct Allocator {
}
AsanThread *t = GetCurrentThread();
- void *allocated;
- if (t) {
- AllocatorCache *cache = GetAllocatorCache(&t->malloc_storage());
- allocated = allocator.Allocate(cache, needed_size, 8);
- } else {
- SpinMutexLock l(&fallback_mutex);
- AllocatorCache *cache = &fallback_allocator_cache;
- allocated = allocator.Allocate(cache, needed_size, 8);
- }
+ void *allocated = allocator.Allocate(
+ GetAllocatorCache(&t->malloc_storage()), needed_size, 8);
if (UNLIKELY(!allocated)) {
SetAllocatorOutOfMemory();
if (AllocatorMayReturnNull())
diff --git a/compiler-rt/lib/msan/msan_allocator.cpp b/compiler-rt/lib/msan/msan_allocator.cpp
index d7d4967c949859..f478b9979f2daa 100644
--- a/compiler-rt/lib/msan/msan_allocator.cpp
+++ b/compiler-rt/lib/msan/msan_allocator.cpp
@@ -199,15 +199,8 @@ static void *MsanAllocate(BufferedStackTrace *stack, uptr size, uptr alignment,
ReportRssLimitExceeded(stack);
}
MsanThread *t = GetCurrentThread();
- void *allocated;
- if (t) {
- AllocatorCache *cache = GetAllocatorCache(&t->malloc_storage());
- allocated = allocator.Allocate(cache, size, alignment);
- } else {
- SpinMutexLock l(&fallback_mutex);
- AllocatorCache *cache = &fallback_allocator_cache;
- allocated = allocator.Allocate(cache, size, alignment);
- }
+ void *allocated = allocator.Allocate(GetAllocatorCache(&t->malloc_storage()),
+ size, alignment);
if (UNLIKELY(!allocated)) {
SetAllocatorOutOfMemory();
if (AllocatorMayReturnNull())
|
With static runtime. With dynamic runtime, with late activation, it's not guaranteed, I guess? |
I've checked |
wondering if it's initialized if threads are created by direct calls of |
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.
Have you tried to run out large set of internal tests?
Created using spr 1.3.5-bogner
Finished the large set of tests. The results (with a lot of noise) look good |
This breaks Darwin bots: https://green.lab.llvm.org/job/llvm.org/job/clang-stage1-RA/1753/
Maybe revert? |
This also break Darwin ASAN bots for bootstrapping itself. I will revert for now. |
Reverted: |
macOS uses the dynamic runtime and |
The nullness check is unreachable.
*Allocate
functions must be called after*_current_thread
is set.set.
clone
, static TLS is either reused orset to a new value (CLONE_SETTLS).
Make this change for asan/msan and possibly extend the change to other
sanitizers. (asan supports many platforms and I am not 100% certain that
all platforms have the property.)