<div dir="ltr">Windows doesn't actually support weak symbols that resolve to 0 if they aren't present. It supports symbols that resolve to some default real symbol if no other definition is found. See lib/asan/asan_win.cc for how we deal with the existing uses of weak symbols. This means I can't fix this in a way that is semantically equivalent.<div><br></div><div>I'll do the quick fix for now, but you should think about other ways that users can provide optional sanitizer hooks that are less platform dependent.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Sep 14, 2016 at 3:00 PM, Kostya Serebryany via llvm-commits <span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: kcc<br>
Date: Wed Sep 14 17:00:58 2016<br>
New Revision: 281546<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=281546&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project?rev=281546&view=rev</a><br>
Log:<br>
[asan] add heap_profile=1 to asan to periodically print the heap profile. So far this is a very basic heap-profile functionality<br>
<br>
Added:<br>
    compiler-rt/trunk/test/asan/<wbr>TestCases/Linux/auto_memory_<wbr>profile_test.cc<br>
Modified:<br>
    compiler-rt/trunk/lib/<wbr>sanitizer_common/sanitizer_<wbr>allocator_interface.h<br>
    compiler-rt/trunk/lib/<wbr>sanitizer_common/sanitizer_<wbr>common_libcdep.cc<br>
    compiler-rt/trunk/lib/<wbr>sanitizer_common/sanitizer_<wbr>flags.inc<br>
<br>
Modified: compiler-rt/trunk/lib/<wbr>sanitizer_common/sanitizer_<wbr>allocator_interface.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator_interface.h?rev=281546&r1=281545&r2=281546&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/compiler-rt/trunk/lib/<wbr>sanitizer_common/sanitizer_<wbr>allocator_interface.h?rev=<wbr>281546&r1=281545&r2=281546&<wbr>view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- compiler-rt/trunk/lib/<wbr>sanitizer_common/sanitizer_<wbr>allocator_interface.h (original)<br>
+++ compiler-rt/trunk/lib/<wbr>sanitizer_common/sanitizer_<wbr>allocator_interface.h Wed Sep 14 17:00:58 2016<br>
@@ -37,6 +37,10 @@ SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_<br>
     /* OPTIONAL */ void __sanitizer_malloc_hook(void *ptr, uptr size);<br>
 SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE<br>
     /* OPTIONAL */ void __sanitizer_free_hook(void *ptr);<br>
+<br>
+<br>
+SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE<br>
+    void __sanitizer_print_memory_<wbr>profile(int top_percent);<br>
 }  // extern "C"<br>
<br>
 #endif  // SANITIZER_ALLOCATOR_INTERFACE_<wbr>H<br>
<br>
Modified: compiler-rt/trunk/lib/<wbr>sanitizer_common/sanitizer_<wbr>common_libcdep.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_libcdep.cc?rev=281546&r1=281545&r2=281546&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/compiler-rt/trunk/lib/<wbr>sanitizer_common/sanitizer_<wbr>common_libcdep.cc?rev=281546&<wbr>r1=281545&r2=281546&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- compiler-rt/trunk/lib/<wbr>sanitizer_common/sanitizer_<wbr>common_libcdep.cc (original)<br>
+++ compiler-rt/trunk/lib/<wbr>sanitizer_common/sanitizer_<wbr>common_libcdep.cc Wed Sep 14 17:00:58 2016<br>
@@ -13,6 +13,7 @@<br>
<br>
 #include "sanitizer_common.h"<br>
<br>
+#include "sanitizer_allocator_<wbr>interface.h"<br>
 #include "sanitizer_flags.h"<br>
 #include "sanitizer_stackdepot.h"<br>
 #include "sanitizer_stacktrace.h"<br>
@@ -78,10 +79,12 @@ void SetAllocatorReleaseToOSCallbac<wbr>k(All<br>
 void BackgroundThread(void *arg) {<br>
   uptr hard_rss_limit_mb = common_flags()->hard_rss_<wbr>limit_mb;<br>
   uptr soft_rss_limit_mb = common_flags()->soft_rss_<wbr>limit_mb;<br>
+  bool heap_profile = common_flags()->heap_profile;<br>
   bool allocator_release_to_os = common_flags()->allocator_<wbr>release_to_os;<br>
   uptr prev_reported_rss = 0;<br>
   uptr prev_reported_stack_depot_size = 0;<br>
   bool reached_soft_rss_limit = false;<br>
+  uptr rss_during_last_reported_<wbr>profile = 0;<br>
   while (true) {<br>
     SleepForMillis(100);<br>
     uptr current_rss_mb = GetRSS() >> 20;<br>
@@ -124,6 +127,12 @@ void BackgroundThread(void *arg) {<br>
       }<br>
     }<br>
     if (allocator_release_to_os && ReleseCallback) ReleseCallback();<br>
+    if (heap_profile &&<br>
+        current_rss_mb > rss_during_last_reported_<wbr>profile * 1.1) {<br>
+      Printf("\n\nHEAP PROFILE at RSS %zdMb\n", current_rss_mb);<br>
+      __sanitizer_print_memory_<wbr>profile(90);<br>
+      rss_during_last_reported_<wbr>profile = current_rss_mb;<br>
+    }<br>
   }<br>
 }<br>
<br>
@@ -151,7 +160,8 @@ void MaybeStartBackgroudThread() {<br>
   // Start the background thread if one of the rss limits is given.<br>
   if (!common_flags()->hard_rss_<wbr>limit_mb &&<br>
       !common_flags()->soft_rss_<wbr>limit_mb &&<br>
-      !common_flags()->allocator_<wbr>release_to_os) return;<br>
+      !common_flags()->allocator_<wbr>release_to_os &&<br>
+      !common_flags()->heap_profile) return;<br>
   if (!&real_pthread_create) return;  // Can't spawn the thread anyway.<br>
   internal_start_thread(<wbr>BackgroundThread, nullptr);<br>
 #endif<br>
<br>
Modified: compiler-rt/trunk/lib/<wbr>sanitizer_common/sanitizer_<wbr>flags.inc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.inc?rev=281546&r1=281545&r2=281546&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/compiler-rt/trunk/lib/<wbr>sanitizer_common/sanitizer_<wbr>flags.inc?rev=281546&r1=<wbr>281545&r2=281546&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- compiler-rt/trunk/lib/<wbr>sanitizer_common/sanitizer_<wbr>flags.inc (original)<br>
+++ compiler-rt/trunk/lib/<wbr>sanitizer_common/sanitizer_<wbr>flags.inc Wed Sep 14 17:00:58 2016<br>
@@ -118,6 +118,7 @@ COMMON_FLAG(uptr, soft_rss_limit_mb, 0,<br>
             " until the RSS goes below the soft limit."<br>
             " This limit does not affect memory allocations other than"<br>
             " malloc/new.")<br>
+COMMON_FLAG(bool, heap_profile, false, "Experimental heap profiler, asan-only")<br>
 COMMON_FLAG(bool, allocator_release_to_os, false,<br>
             "Experimental. If true, try to periodically release unused"<br>
             " memory to the OS.\n")<br>
<br>
Added: compiler-rt/trunk/test/asan/<wbr>TestCases/Linux/auto_memory_<wbr>profile_test.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Linux/auto_memory_profile_test.cc?rev=281546&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/compiler-rt/trunk/<wbr>test/asan/TestCases/Linux/<wbr>auto_memory_profile_test.cc?<wbr>rev=281546&view=auto</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- compiler-rt/trunk/test/asan/<wbr>TestCases/Linux/auto_memory_<wbr>profile_test.cc (added)<br>
+++ compiler-rt/trunk/test/asan/<wbr>TestCases/Linux/auto_memory_<wbr>profile_test.cc Wed Sep 14 17:00:58 2016<br>
@@ -0,0 +1,32 @@<br>
+// Tests heap_profile=1.<br>
+// Printing memory profiling only works in the configuration where we can<br>
+// detect leaks.<br>
+// REQUIRES: leak-detection<br>
+//<br>
+// RUN: %clangxx_asan %s -o %t<br>
+// RUN: %env_asan_opts=heap_profile=1 %run %t 2>&1 | FileCheck %s<br>
+#include <sanitizer/common_interface_<wbr>defs.h><br>
+<br>
+#include <stdio.h><br>
+#include <string.h><br>
+#include <unistd.h><br>
+<br>
+char *sink[1000];<br>
+<br>
+int main() {<br>
+<br>
+  for (int i = 0; i < 3; i++) {<br>
+    const size_t  kSize = 13000000;<br>
+    char *x = new char[kSize];<br>
+    memset(x, 0, kSize);<br>
+    sink[i] = x;<br>
+    sleep(1);<br>
+  }<br>
+}<br>
+<br>
+// CHECK: HEAP PROFILE at RSS<br>
+// CHECK: 13000000 byte(s)<br>
+// CHECK: HEAP PROFILE at RSS<br>
+// CHECK: 26000000 byte(s)<br>
+// CHECK: HEAP PROFILE at RSS<br>
+// CHECK: 39000000 byte(s)<br>
<br>
<br>
______________________________<wbr>_________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div>