[compiler-rt] d9b574c - [hwasan] Fix allocator_interface implementation

Vitaly Buka via llvm-commits llvm-commits at lists.llvm.org
Wed May 24 18:05:48 PDT 2023


Author: Vitaly Buka
Date: 2023-05-24T18:05:42-07:00
New Revision: d9b574c312c34ddc88dee7fdb7f55fe748839683

URL: https://github.com/llvm/llvm-project/commit/d9b574c312c34ddc88dee7fdb7f55fe748839683
DIFF: https://github.com/llvm/llvm-project/commit/d9b574c312c34ddc88dee7fdb7f55fe748839683.diff

LOG: [hwasan] Fix allocator_interface implementation

__sanitizer_get_current_allocated_bytes had as body, but allocator
caches were not registered to collect stats. It's done by
SizeClassAllocator64LocalCache::Init().

Reviewed By: thurston

Differential Revision: https://reviews.llvm.org/D151389

Added: 
    

Modified: 
    compiler-rt/lib/hwasan/hwasan_allocator.cpp
    compiler-rt/lib/hwasan/hwasan_allocator.h
    compiler-rt/lib/hwasan/hwasan_thread.cpp
    compiler-rt/test/sanitizer_common/TestCases/allocator_interface.cpp

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/hwasan/hwasan_allocator.cpp b/compiler-rt/lib/hwasan/hwasan_allocator.cpp
index b81f1e353af4..d3e826672630 100644
--- a/compiler-rt/lib/hwasan/hwasan_allocator.cpp
+++ b/compiler-rt/lib/hwasan/hwasan_allocator.cpp
@@ -149,8 +149,9 @@ void HwasanAllocatorInit() {
   atomic_store_relaxed(&hwasan_allocator_tagging_enabled,
                        !flags()->disable_allocator_tagging);
   SetAllocatorMayReturnNull(common_flags()->allocator_may_return_null);
-  allocator.Init(common_flags()->allocator_release_to_os_interval_ms,
-                 GetAliasRegionStart());
+  allocator.InitLinkerInitialized(
+      common_flags()->allocator_release_to_os_interval_ms,
+      GetAliasRegionStart());
   for (uptr i = 0; i < sizeof(tail_magic); i++)
     tail_magic[i] = GetCurrentThread()->GenerateRandomTag();
   if (common_flags()->max_allocation_size_mb) {
@@ -165,8 +166,11 @@ void HwasanAllocatorLock() { allocator.ForceLock(); }
 
 void HwasanAllocatorUnlock() { allocator.ForceUnlock(); }
 
+void AllocatorThreadStart(AllocatorCache *cache) { allocator.InitCache(cache); }
+
 void AllocatorThreadFinish(AllocatorCache *cache) {
   allocator.SwallowCache(cache);
+  allocator.DestroyCache(cache);
 }
 
 static uptr TaggedSize(uptr size) {

diff  --git a/compiler-rt/lib/hwasan/hwasan_allocator.h b/compiler-rt/lib/hwasan/hwasan_allocator.h
index 0168b49d9df7..efe253de1258 100644
--- a/compiler-rt/lib/hwasan/hwasan_allocator.h
+++ b/compiler-rt/lib/hwasan/hwasan_allocator.h
@@ -88,6 +88,7 @@ typedef SizeClassAllocator64<AP64> PrimaryAllocator;
 typedef CombinedAllocator<PrimaryAllocator> Allocator;
 typedef Allocator::AllocatorCache AllocatorCache;
 
+void AllocatorThreadStart(AllocatorCache *cache);
 void AllocatorThreadFinish(AllocatorCache *cache);
 
 class HwasanChunkView {

diff  --git a/compiler-rt/lib/hwasan/hwasan_thread.cpp b/compiler-rt/lib/hwasan/hwasan_thread.cpp
index b8a9d288e134..f5eb79f074f0 100644
--- a/compiler-rt/lib/hwasan/hwasan_thread.cpp
+++ b/compiler-rt/lib/hwasan/hwasan_thread.cpp
@@ -58,6 +58,7 @@ void Thread::Init(uptr stack_buffer_start, uptr stack_buffer_size,
 #endif
   InitStackAndTls(state);
   dtls_ = DTLS_Get();
+  AllocatorThreadStart(allocator_cache());
 }
 
 void Thread::InitStackRingBuffer(uptr stack_buffer_start,

diff  --git a/compiler-rt/test/sanitizer_common/TestCases/allocator_interface.cpp b/compiler-rt/test/sanitizer_common/TestCases/allocator_interface.cpp
index 9d98fca4d59e..c2f304418f86 100644
--- a/compiler-rt/test/sanitizer_common/TestCases/allocator_interface.cpp
+++ b/compiler-rt/test/sanitizer_common/TestCases/allocator_interface.cpp
@@ -4,9 +4,6 @@
 // No allocator.
 // UNSUPPORTED: ubsan
 
-// FIXME: implementation is incomplete.
-// XFAIL: hwasan
-
 #include <assert.h>
 #include <sanitizer/allocator_interface.h>
 #include <stdio.h>


        


More information about the llvm-commits mailing list