[PATCH] D55887: Add support for background thread on NetBSD in ASan

Kamil Rytarowski via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 19 05:53:42 PST 2018


krytarowski created this revision.
krytarowski added reviewers: vitalybuka, joerg.
krytarowski added a project: Sanitizers.
Herald added subscribers: llvm-commits, fedor.sergeev, kubamracek.

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.


Repository:
  rL LLVM

https://reviews.llvm.org/D55887

Files:
  lib/asan/asan_rtl.cc
  lib/sanitizer_common/sanitizer_common_libcdep.cc
  test/sanitizer_common/TestCases/Linux/hard_rss_limit_mb_test.cc
  test/sanitizer_common/TestCases/hard_rss_limit_mb_test.cc


Index: test/sanitizer_common/TestCases/hard_rss_limit_mb_test.cc
===================================================================
--- test/sanitizer_common/TestCases/hard_rss_limit_mb_test.cc
+++ 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 <string.h>
 #include <stdio.h>
 #include <unistd.h>
Index: lib/sanitizer_common/sanitizer_common_libcdep.cc
===================================================================
--- lib/sanitizer_common/sanitizer_common_libcdep.cc
+++ lib/sanitizer_common/sanitizer_common_libcdep.cc
@@ -25,7 +25,7 @@
   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 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 &&
Index: lib/asan/asan_rtl.cc
===================================================================
--- lib/asan/asan_rtl.cc
+++ lib/asan/asan_rtl.cc
@@ -383,6 +383,13 @@
           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 @@
   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;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D55887.178872.patch
Type: text/x-patch
Size: 2224 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181219/4c58613d/attachment.bin>


More information about the llvm-commits mailing list