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;