Skip to content

Commit 60e3583

Browse files
charlesmungerCharles Munger
authored andcommitted
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.
1 parent ab9383b commit 60e3583

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

src/benchmark.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -913,15 +913,17 @@ void Initialize(int* argc, char** argv, void (*HelperPrintf)()) {
913913
// Android 12 (API level 31) introduced zeroing of allocated memory in bionic
914914
// as a hardening feature; however, this is not enabled for apps.
915915
if (__builtin_available(android 31, *)) {
916-
BM_CHECK_EQ(mallopt(M_BIONIC_ZERO_INIT, 0), 1);
916+
// Not asserting on the return value, as sanitizers interpose the allocator
917+
// and always return 0
918+
(void)mallopt(M_BIONIC_ZERO_INIT, 0);
917919
}
918920

919921
// The default configuration of bionic is to return pages to the OS as soon
920922
// as they are freed. But application processes are configured to run with a
921923
// delay before returning memory to avoid excessive faulting on repeated
922924
// allocation and deallocation, which is common in repeated benchmark runs.
923925
if (__builtin_available(android 27, *)) {
924-
BM_CHECK_EQ(mallopt(M_DECAY_TIME, 1), 1);
926+
(void)mallopt(M_DECAY_TIME, 1);
925927
}
926928
#endif
927929
internal::HelperPrintf = HelperPrintf;

0 commit comments

Comments
 (0)