diff --git a/compiler-rt/lib/scudo/standalone/allocator_config.h b/compiler-rt/lib/scudo/standalone/allocator_config.h --- a/compiler-rt/lib/scudo/standalone/allocator_config.h +++ b/compiler-rt/lib/scudo/standalone/allocator_config.h @@ -60,7 +60,7 @@ struct DefaultConfig { using SizeClassMap = DefaultSizeClassMap; - static const bool MaySupportMemoryTagging = false; + static const bool MaySupportMemoryTagging = true; #if SCUDO_CAN_USE_PRIMARY64 typedef SizeClassAllocator64 Primary; @@ -87,7 +87,6 @@ template using TSDRegistryT = TSDRegistryExT; // Exclusive }; - struct AndroidConfig { using SizeClassMap = AndroidSizeClassMap; static const bool MaySupportMemoryTagging = true; diff --git a/compiler-rt/lib/scudo/standalone/tests/scudo_unit_test_main.cpp b/compiler-rt/lib/scudo/standalone/tests/scudo_unit_test_main.cpp --- a/compiler-rt/lib/scudo/standalone/tests/scudo_unit_test_main.cpp +++ b/compiler-rt/lib/scudo/standalone/tests/scudo_unit_test_main.cpp @@ -17,12 +17,28 @@ #define DEALLOC_TYPE_MISMATCH "true" #endif +static void EnableMemoryTaggingIfSupported() { + if (!scudo::archSupportsMemoryTagging()) + return; + static bool Done = []() { + if (!scudo::systemDetectsMemoryTagFaultsTestOnly()) + scudo::enableSystemMemoryTaggingTestOnly(); + return true; + }(); + (void)Done; +} + // This allows us to turn on/off a Quarantine for specific tests. The Quarantine // parameters are on the low end, to avoid having to loop excessively in some // tests. bool UseQuarantine = true; extern "C" __attribute__((visibility("default"))) const char * __scudo_default_options() { + // Wrappers tests initialize global allocator early, before the main(). We + // need to have Memory Tagging enabled before that happeng or allocator will + // dissable the feature at all. This code is called by Allocator::init() early + // enough to achieve that. + EnableMemoryTaggingIfSupported(); if (!UseQuarantine) return "dealloc_type_mismatch=" DEALLOC_TYPE_MISMATCH; return "quarantine_size_kb=256:thread_local_quarantine_size_kb=128:" @@ -34,8 +50,7 @@ // for Fuchsia builds. #if !SCUDO_FUCHSIA int main(int argc, char **argv) { - if (scudo::archSupportsMemoryTagging()) - scudo::enableSystemMemoryTaggingTestOnly(); + EnableMemoryTaggingIfSupported(); testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } diff --git a/compiler-rt/lib/scudo/standalone/tests/wrappers_cpp_test.cpp b/compiler-rt/lib/scudo/standalone/tests/wrappers_cpp_test.cpp --- a/compiler-rt/lib/scudo/standalone/tests/wrappers_cpp_test.cpp +++ b/compiler-rt/lib/scudo/standalone/tests/wrappers_cpp_test.cpp @@ -6,6 +6,7 @@ // //===----------------------------------------------------------------------===// +#include "memtag.h" #include "tests/scudo_unit_test.h" #include @@ -107,6 +108,11 @@ } TEST(ScudoWrappersCppTest, ThreadedNew) { +#if !SCUDO_ANDROID + // TODO: Investigate why libc sometimes crashes with tag missmatch in + // __pthread_clockjoin_ex. + scudo::ScopedDisableMemoryTagChecks NoTags; +#endif Ready = false; std::thread Threads[32]; for (size_t I = 0U; I < sizeof(Threads) / sizeof(Threads[0]); I++)