From 646c130a18d1cbe8ace850ffb4bc1e65cb5cd666 Mon Sep 17 00:00:00 2001 From: Kamil Rytarowski Date: Sat, 29 Dec 2018 00:32:07 +0000 Subject: [PATCH] Add support for background thread on NetBSD in ASan Summary: Change the point of calling MaybeStartBackgroudThread() from AsanInitInternal() that is too early on NetBSD to a constructor (with aid of C++11 lambda construct). Enable the code for background thread as is for NetBSD. Rename test/sanitizer_common/TestCases/Linux/hard_rss_limit_mb_test.cc to test/sanitizer_common/TestCases/hard_rss_limit_mb_test.cc and allow runs on NetBSD. This tests passes correctly. Reviewers: vitalybuka, joerg, eugenis Reviewed By: eugenis Subscribers: eugenis, kubamracek, fedor.sergeev, llvm-commits, mgorny, #sanitizers Tags: #sanitizers Differential Revision: https://reviews.llvm.org/D55887 llvm-svn: 350139 --- compiler-rt/lib/asan/asan_rtl.cc | 10 +++++++--- .../lib/sanitizer_common/sanitizer_common_libcdep.cc | 4 ++-- .../TestCases/{Linux => }/hard_rss_limit_mb_test.cc | 2 ++ 3 files changed, 11 insertions(+), 5 deletions(-) rename compiler-rt/test/sanitizer_common/TestCases/{Linux => }/hard_rss_limit_mb_test.cc (97%) diff --git a/compiler-rt/lib/asan/asan_rtl.cc b/compiler-rt/lib/asan/asan_rtl.cc index 0ecbcd594875..2a790e851f19 100644 --- a/compiler-rt/lib/asan/asan_rtl.cc +++ b/compiler-rt/lib/asan/asan_rtl.cc @@ -383,6 +383,13 @@ void PrintAddressSpaceLayout() { kHighShadowBeg > kMidMemEnd); } +static bool UNUSED __local_asan_dyninit = [] { + MaybeStartBackgroudThread(); + SetSoftRssLimitExceededCallback(AsanSoftRssLimitExceededCallback); + + return false; +}(); + static void AsanInitInternal() { if (LIKELY(asan_inited)) return; SanitizerToolName = "AddressSanitizer"; @@ -457,9 +464,6 @@ static void AsanInitInternal() { allocator_options.SetFrom(flags(), common_flags()); InitializeAllocator(allocator_options); - MaybeStartBackgroudThread(); - SetSoftRssLimitExceededCallback(AsanSoftRssLimitExceededCallback); - // On Linux AsanThread::ThreadStart() calls malloc() that's why asan_inited // should be set to 1 prior to initializing the threads. asan_inited = 1; diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_libcdep.cc b/compiler-rt/lib/sanitizer_common/sanitizer_common_libcdep.cc index ab42b216771e..1c0995b2d27b 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_common_libcdep.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_libcdep.cc @@ -25,7 +25,7 @@ void SetSoftRssLimitExceededCallback(void (*Callback)(bool exceeded)) { SoftRssLimitExceededCallback = Callback; } -#if SANITIZER_LINUX && !SANITIZER_GO +#if (SANITIZER_LINUX || SANITIZER_NETBSD) && !SANITIZER_GO // Weak default implementation for when sanitizer_stackdepot is not linked in. SANITIZER_WEAK_ATTRIBUTE StackDepotStats *StackDepotGetStats() { return nullptr; @@ -114,7 +114,7 @@ void WriteToSyslog(const char *msg) { } void MaybeStartBackgroudThread() { -#if SANITIZER_LINUX && \ +#if (SANITIZER_LINUX || SANITIZER_NETBSD) && \ !SANITIZER_GO // Need to implement/test on other platforms. // Start the background thread if one of the rss limits is given. if (!common_flags()->hard_rss_limit_mb && diff --git a/compiler-rt/test/sanitizer_common/TestCases/Linux/hard_rss_limit_mb_test.cc b/compiler-rt/test/sanitizer_common/TestCases/hard_rss_limit_mb_test.cc similarity index 97% rename from compiler-rt/test/sanitizer_common/TestCases/Linux/hard_rss_limit_mb_test.cc rename to compiler-rt/test/sanitizer_common/TestCases/hard_rss_limit_mb_test.cc index 3013a3c3fd7d..302a84180d87 100644 --- a/compiler-rt/test/sanitizer_common/TestCases/Linux/hard_rss_limit_mb_test.cc +++ b/compiler-rt/test/sanitizer_common/TestCases/hard_rss_limit_mb_test.cc @@ -19,6 +19,8 @@ // https://github.com/google/sanitizers/issues/981 // UNSUPPORTED: android-26 +// UNSUPPORTED: freebsd, solaris, darwin + #include #include #include