Skip to content

Commit 4a04fca

Browse files
authored
[compiler-rt][asan] Fix for flaky asan check (#88177)
This fixes #87324. We haven't been able to come up with a minimal reproducer but we can reliabely avoid this failure with the following fix. Prior to the GetGlobalLowLevelAllocator change, the old LowLevelAllocator aquired a lock associated with it preventing that specific allocator from being accessed at the same time by many threads. With the GetGlobalLowLevelAllocator change, I had accidentally replaced it but not taken into account the lock, so we can have a data race if the allocator is used at any point while a thread is being created. The global allocator can be used for flag parsing or registering asan globals.
1 parent f04452d commit 4a04fca

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

compiler-rt/lib/asan/asan_thread.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,15 @@ static ThreadRegistry *asan_thread_registry;
4444
static ThreadArgRetval *thread_data;
4545

4646
static Mutex mu_for_thread_context;
47+
// TODO(leonardchan@): It should be possible to make LowLevelAllocator
48+
// threadsafe and consolidate this one into the GlobalLoweLevelAllocator.
49+
// We should be able to do something similar to what's in
50+
// sanitizer_stack_store.cpp.
51+
static LowLevelAllocator allocator_for_thread_context;
4752

4853
static ThreadContextBase *GetAsanThreadContext(u32 tid) {
4954
Lock lock(&mu_for_thread_context);
50-
return new (GetGlobalLowLevelAllocator()) AsanThreadContext(tid);
55+
return new (allocator_for_thread_context) AsanThreadContext(tid);
5156
}
5257

5358
static void InitThreads() {

0 commit comments

Comments
 (0)