diff --git a/compiler-rt/lib/scudo/standalone/benchmarks/CMakeLists.txt b/compiler-rt/lib/scudo/standalone/benchmarks/CMakeLists.txt --- a/compiler-rt/lib/scudo/standalone/benchmarks/CMakeLists.txt +++ b/compiler-rt/lib/scudo/standalone/benchmarks/CMakeLists.txt @@ -18,4 +18,16 @@ $) set_property(TARGET ScudoBenchmarks.${arch} APPEND_STRING PROPERTY COMPILE_FLAGS "${SCUDO_BENCHMARK_CFLAGS}") + + if (COMPILER_RT_HAS_GWP_ASAN) + add_benchmark( + ScudoBenchmarksWithGwpAsan.${arch} malloc_benchmark.cpp + $ + $ + $ + $) + set_property( + TARGET ScudoBenchmarksWithGwpAsan.${arch} APPEND_STRING PROPERTY + COMPILE_FLAGS "${SCUDO_BENCHMARK_CFLAGS} -DGWP_ASAN_HOOKS") + endif() endforeach() diff --git a/compiler-rt/lib/scudo/standalone/benchmarks/malloc_benchmark.cpp b/compiler-rt/lib/scudo/standalone/benchmarks/malloc_benchmark.cpp --- a/compiler-rt/lib/scudo/standalone/benchmarks/malloc_benchmark.cpp +++ b/compiler-rt/lib/scudo/standalone/benchmarks/malloc_benchmark.cpp @@ -14,14 +14,20 @@ #include +void *CurrentAllocator; +template void PostInitCallback() { + reinterpret_cast *>(CurrentAllocator)->initGwpAsan(); +} + template static void BM_malloc_free(benchmark::State &State) { - using AllocatorT = scudo::Allocator; + using AllocatorT = scudo::Allocator>; auto Deleter = [](AllocatorT *A) { A->unmapTestOnly(); delete A; }; std::unique_ptr Allocator(new AllocatorT, Deleter); + CurrentAllocator = Allocator.get(); Allocator->reset(); const size_t NBytes = State.range(0); @@ -55,7 +61,7 @@ template static void BM_malloc_free_loop(benchmark::State &State) { - using AllocatorT = scudo::Allocator; + using AllocatorT = scudo::Allocator>; auto Deleter = [](AllocatorT *A) { A->unmapTestOnly(); delete A; @@ -66,7 +72,7 @@ const size_t NumIters = State.range(0); size_t PageSize = scudo::getPageSizeCached(); - void *Ptrs[NumIters]; + std::vector Ptrs(NumIters); for (auto _ : State) { size_t SizeLog2 = 0; diff --git a/compiler-rt/lib/scudo/standalone/combined.h b/compiler-rt/lib/scudo/standalone/combined.h --- a/compiler-rt/lib/scudo/standalone/combined.h +++ b/compiler-rt/lib/scudo/standalone/combined.h @@ -51,8 +51,7 @@ typedef typename Params::template TSDRegistryT TSDRegistryT; void callPostInitCallback() { - static pthread_once_t OnceControl = PTHREAD_ONCE_INIT; - pthread_once(&OnceControl, PostInitCallback); + pthread_once(&PostInitNonce, PostInitCallback); } struct QuarantineCallback { @@ -952,6 +951,7 @@ SecondaryT Secondary; QuarantineT Quarantine; TSDRegistryT TSDRegistry; + pthread_once_t PostInitNonce = PTHREAD_ONCE_INIT; #ifdef GWP_ASAN_HOOKS gwp_asan::GuardedPoolAllocator GuardedAlloc;