From d976128d579c3d2bcd2819a57d547b4dfdd66409 Mon Sep 17 00:00:00 2001 From: Charles Munger Date: Mon, 22 Jun 2026 20:45:29 -0700 Subject: [PATCH] Fix tsan/asan/hwasan/etc failures on Android Some people run their benchmarks with sanitizers, and they should not spuriously fail. Asan and other sanitizer allocators return 0 for all mallopt calls, so the previous code was causing teh BM_CHECK to trigger. --- src/benchmark.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/benchmark.cc b/src/benchmark.cc index c7baa103d9..22a395d2a3 100644 --- a/src/benchmark.cc +++ b/src/benchmark.cc @@ -996,7 +996,9 @@ void Initialize(int* argc, char** argv, void (*HelperPrintf)()) { // Android 12 (API level 31) introduced zeroing of allocated memory in bionic // as a hardening feature; however, this is not enabled for apps. if (__builtin_available(android 31, *)) { - BM_CHECK_EQ(mallopt(M_BIONIC_ZERO_INIT, 0), 1); + // Not asserting on the return value, as sanitizers interpose the allocator + // and always return 0 + (void)mallopt(M_BIONIC_ZERO_INIT, 0); } // The default configuration of bionic is to return pages to the OS as soon @@ -1004,7 +1006,7 @@ void Initialize(int* argc, char** argv, void (*HelperPrintf)()) { // delay before returning memory to avoid excessive faulting on repeated // allocation and deallocation, which is common in repeated benchmark runs. if (__builtin_available(android 27, *)) { - BM_CHECK_EQ(mallopt(M_DECAY_TIME, 1), 1); + (void)mallopt(M_DECAY_TIME, 1); } #endif internal::HelperPrintf = HelperPrintf;