<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Sep 14, 2016 at 4:10 PM, Reid Kleckner <span dir="ltr"><<a href="mailto:rnk@google.com" target="_blank">rnk@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><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></blockquote><div><br></div><div>Thanks for the quick fix! </div><div><br></div><div>--kcc </div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5"><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-pr<wbr>oject?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/Te<wbr>stCases/Linux/auto_memory_prof<wbr>ile_test.cc<br>
Modified:<br>
    compiler-rt/trunk/lib/sanitize<wbr>r_common/sanitizer_allocator_<wbr>interface.h<br>
    compiler-rt/trunk/lib/sanitize<wbr>r_common/sanitizer_common_<wbr>libcdep.cc<br>
    compiler-rt/trunk/lib/sanitize<wbr>r_common/sanitizer_flags.inc<br>
<br>
Modified: compiler-rt/trunk/lib/sanitize<wbr>r_common/sanitizer_allocator_<wbr>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-pr<wbr>oject/compiler-rt/trunk/lib/sa<wbr>nitizer_common/sanitizer_alloc<wbr>ator_interface.h?rev=281546&<wbr>r1=281545&r2=281546&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- compiler-rt/trunk/lib/sanitize<wbr>r_common/sanitizer_allocator_<wbr>interface.h (original)<br>
+++ compiler-rt/trunk/lib/sanitize<wbr>r_common/sanitizer_allocator_<wbr>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_profi<wbr>le(int top_percent);<br>
 }  // extern "C"<br>
<br>
 #endif  // SANITIZER_ALLOCATOR_INTERFACE_<wbr>H<br>
<br>
Modified: compiler-rt/trunk/lib/sanitize<wbr>r_common/sanitizer_common_<wbr>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-pr<wbr>oject/compiler-rt/trunk/lib/sa<wbr>nitizer_common/sanitizer_commo<wbr>n_libcdep.cc?rev=281546&r1=<wbr>281545&r2=281546&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- compiler-rt/trunk/lib/sanitize<wbr>r_common/sanitizer_common_<wbr>libcdep.cc (original)<br>
+++ compiler-rt/trunk/lib/sanitize<wbr>r_common/sanitizer_common_<wbr>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_interface<wbr>.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_limit<wbr>_mb;<br>
   uptr soft_rss_limit_mb = common_flags()->soft_rss_limit<wbr>_mb;<br>
+  bool heap_profile = common_flags()->heap_profile;<br>
   bool allocator_release_to_os = common_flags()->allocator_rele<wbr>ase_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_profi<wbr>le = 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_profi<wbr>le * 1.1) {<br>
+      Printf("\n\nHEAP PROFILE at RSS %zdMb\n", current_rss_mb);<br>
+      __sanitizer_print_memory_profi<wbr>le(90);<br>
+      rss_during_last_reported_profi<wbr>le = 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_lim<wbr>it_mb &&<br>
       !common_flags()->soft_rss_lim<wbr>it_mb &&<br>
-      !common_flags()->allocator_rel<wbr>ease_to_os) return;<br>
+      !common_flags()->allocator_rel<wbr>ease_to_os &&<br>
+      !common_flags()->heap_profile) return;<br>
   if (!&real_pthread_create) return;  // Can't spawn the thread anyway.<br>
   internal_start_thread(Backgro<wbr>undThread, nullptr);<br>
 #endif<br>
<br>
Modified: compiler-rt/trunk/lib/sanitize<wbr>r_common/sanitizer_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-pr<wbr>oject/compiler-rt/trunk/lib/sa<wbr>nitizer_common/sanitizer_flags<wbr>.inc?rev=281546&r1=281545&r2=<wbr>281546&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- compiler-rt/trunk/lib/sanitize<wbr>r_common/sanitizer_flags.inc (original)<br>
+++ compiler-rt/trunk/lib/sanitize<wbr>r_common/sanitizer_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/Te<wbr>stCases/Linux/auto_memory_prof<wbr>ile_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-pr<wbr>oject/compiler-rt/trunk/test/<wbr>asan/TestCases/Linux/auto_<wbr>memory_profile_test.cc?rev=<wbr>281546&view=auto</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- compiler-rt/trunk/test/asan/Te<wbr>stCases/Linux/auto_memory_prof<wbr>ile_test.cc (added)<br>
+++ compiler-rt/trunk/test/asan/Te<wbr>stCases/Linux/auto_memory_prof<wbr>ile_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_de<wbr>fs.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" target="_blank">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>
</div></div></blockquote></div><br></div></div>