<div dir="ltr">This was reverted in <span style="font-size:12.8px">r252076. While I'm not exactly sure what caused these issues on Mac buildbot, I've also observed several self-deadlocks caused by this change.</span><div><span style="font-size:12.8px">Essentially, they are caused by </span><span style="font-size:12.8px">AppendToErrorMessageBuffer function, which now takes a lock, but can be re-entrant:</span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">* AppendToErrorMessageBuffer is called and takes a lock</span><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">* </span><span style="font-size:12.8px">AppendToErrorMessageBuffer tries to allocate error message buffer and calls MmapOrDie()</span></div><div><span style="font-size:12.8px">* MmapOrDie() fails, because memory limit is exceeded, and calls Report() to report that</span></div><div><span style="font-size:12.8px">* Report calls </span><span style="font-size:12.8px">AppendToErrorMessageBuffer, which attempts to take a lock, and hangs.</span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">The same will happen if CHECK() call in </span><span style="font-size:12.8px">AppendToErrorMessageBuffer fails. Sadly, I can't suggest a good solution for that: probably</span></div><div><span style="font-size:12.8px">you just need to try harder to make sure the function will never be called recursively: use RAW_CHECK instead of CHECK and</span></div><div><span style="font-size:12.8px">call (some variation of) MmapOrDieQuietly(), which will just call RawWrite()+Die() on failure.</span></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Oct 28, 2015 at 4:18 PM, Anna Zaks 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: zaks<br>
Date: Wed Oct 28 18:18:44 2015<br>
New Revision: 251577<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=251577&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=251577&view=rev</a><br>
Log:<br>
Reapply: [asan] On OS X, log reports to syslog and os_trace<br>
<br>
        When ASan currently detects a bug, by default it will only print out the text<br>
        of the report to stderr. This patch changes this behavior and writes the full<br>
        text of the report to syslog before we terminate the process. It also calls<br>
        os_trace (Activity Tracing available on OS X and iOS) with a message saying<br>
        that the report is available in syslog. This is useful, because this message<br>
        will be shown in the crash log.<br>
<br>
        For this to work, the patch makes sure we store the full report into<br>
        error_message_buffer unconditionally, and it also strips out ANSI escape<br>
        sequences from the report (they are used when producing colored reports).<br>
<br>
        I've initially tried to log to syslog during printing, which is done on Android<br>
        right now. The advantage is that if we crash during error reporting or the<br>
        produced error does not go through ScopedInErrorReport, we would still get a<br>
        (partial) message in the syslog. However, that solution is very problematic on<br>
        OS X. One issue is that the logging routine uses GCD, which may spawn a new<br>
        thread on its behalf. In many cases, the reporting logic locks threadRegistry,<br>
        which leads to deadlocks.<br>
<br>
        Reviewed at <a href="http://reviews.llvm.org/D13452" rel="noreferrer" target="_blank">http://reviews.llvm.org/D13452</a><br>
<br>
        (In addition, add sanitizer_common_libcdep.cc to buildgo.sh to avoid<br>
         build failures on Linux.)<br>
<br>
Modified:<br>
    compiler-rt/trunk/lib/asan/asan_report.cc<br>
    compiler-rt/trunk/lib/asan/tests/asan_test_main.cc<br>
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc<br>
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h<br>
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_libcdep.cc<br>
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_nolibc.cc<br>
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.inc<br>
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux_libcdep.cc<br>
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc<br>
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_printf.cc<br>
    compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_common_test.cc<br>
    compiler-rt/trunk/lib/tsan/go/buildgo.sh<br>
    compiler-rt/trunk/test/asan/lit.cfg<br>
    compiler-rt/trunk/test/ubsan/lit.common.cfg<br>
<br>
Modified: compiler-rt/trunk/lib/asan/asan_report.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_report.cc?rev=251577&r1=251576&r2=251577&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_report.cc?rev=251577&r1=251576&r2=251577&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/lib/asan/asan_report.cc (original)<br>
+++ compiler-rt/trunk/lib/asan/asan_report.cc Wed Oct 28 18:18:44 2015<br>
@@ -31,6 +31,7 @@ static void (*error_report_callback)(con<br>
 static char *error_message_buffer = nullptr;<br>
 static uptr error_message_buffer_pos = 0;<br>
 static uptr error_message_buffer_size = 0;<br>
+static BlockingMutex error_message_buf_mutex(LINKER_INITIALIZED);<br>
<br>
 struct ReportData {<br>
   uptr pc;<br>
@@ -46,16 +47,21 @@ static bool report_happened = false;<br>
 static ReportData report_data = {};<br>
<br>
 void AppendToErrorMessageBuffer(const char *buffer) {<br>
-  if (error_message_buffer) {<br>
-    uptr length = internal_strlen(buffer);<br>
-    CHECK_GE(error_message_buffer_size, error_message_buffer_pos);<br>
-    uptr remaining = error_message_buffer_size - error_message_buffer_pos;<br>
-    internal_strncpy(error_message_buffer + error_message_buffer_pos,<br>
-                     buffer, remaining);<br>
-    error_message_buffer[error_message_buffer_size - 1] = '\0';<br>
-    // FIXME: reallocate the buffer instead of truncating the message.<br>
-    error_message_buffer_pos += Min(remaining, length);<br>
+  BlockingMutexLock l(&error_message_buf_mutex);<br>
+  if (!error_message_buffer) {<br>
+    error_message_buffer_size = 1 << 16;<br>
+    error_message_buffer =<br>
+      (char*)MmapOrDie(error_message_buffer_size, __func__);<br>
+    error_message_buffer_pos = 0;<br>
   }<br>
+  uptr length = internal_strlen(buffer);<br>
+  CHECK_GE(error_message_buffer_size, error_message_buffer_pos);<br>
+  uptr remaining = error_message_buffer_size - error_message_buffer_pos;<br>
+  internal_strncpy(error_message_buffer + error_message_buffer_pos,<br>
+                   buffer, remaining);<br>
+  error_message_buffer[error_message_buffer_size - 1] = '\0';<br>
+  // FIXME: reallocate the buffer instead of truncating the message.<br>
+  error_message_buffer_pos += Min(remaining, length);<br>
 }<br>
<br>
 // ---------------------- Decorator ------------------------------ {{{1<br>
@@ -664,8 +670,13 @@ class ScopedInErrorReport {<br>
     // Print memory stats.<br>
     if (flags()->print_stats)<br>
       __asan_print_accumulated_stats();<br>
-    if (error_report_callback) {<br>
-      error_report_callback(error_message_buffer);<br>
+    {<br>
+      BlockingMutexLock l(&error_message_buf_mutex);<br>
+      LogFullErrorReport(error_message_buffer);<br>
+<br>
+      if (error_report_callback) {<br>
+        error_report_callback(error_message_buffer);<br>
+      }<br>
     }<br>
     Report("ABORTING\n");<br>
     Die();<br>
@@ -1061,13 +1072,8 @@ void __asan_report_error(uptr pc, uptr b<br>
 }<br>
<br>
 void NOINLINE __asan_set_error_report_callback(void (*callback)(const char*)) {<br>
+  BlockingMutexLock l(&error_message_buf_mutex);<br>
   error_report_callback = callback;<br>
-  if (callback) {<br>
-    error_message_buffer_size = 1 << 16;<br>
-    error_message_buffer =<br>
-        (char*)MmapOrDie(error_message_buffer_size, __func__);<br>
-    error_message_buffer_pos = 0;<br>
-  }<br>
 }<br>
<br>
 void __asan_describe_address(uptr addr) {<br>
<br>
Modified: compiler-rt/trunk/lib/asan/tests/asan_test_main.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/tests/asan_test_main.cc?rev=251577&r1=251576&r2=251577&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/tests/asan_test_main.cc?rev=251577&r1=251576&r2=251577&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/lib/asan/tests/asan_test_main.cc (original)<br>
+++ compiler-rt/trunk/lib/asan/tests/asan_test_main.cc Wed Oct 28 18:18:44 2015<br>
@@ -19,7 +19,8 @@ extern "C" const char* __asan_default_op<br>
 #if SANITIZER_MAC<br>
   // On Darwin, we default to `abort_on_error=1`, which would make tests run<br>
   // much slower. Let's override this and run lit tests with 'abort_on_error=0'.<br>
-  return "symbolize=false:abort_on_error=0";<br>
+  // Also, make sure we do not overwhelm the syslog while testing.<br>
+  return "symbolize=false:abort_on_error=0:log_to_syslog=0";<br>
 #else<br>
   return "symbolize=false";<br>
 #endif<br>
<br>
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc?rev=251577&r1=251576&r2=251577&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc?rev=251577&r1=251576&r2=251577&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc (original)<br>
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc Wed Oct 28 18:18:44 2015<br>
@@ -295,6 +295,40 @@ void ReportErrorSummary(const char *erro<br>
 }<br>
 #endif<br>
<br>
+// Removes the ANSI escape sequences from the input string (in-place).<br>
+void RemoveANSIEscapeSequencesFromString(char *str) {<br>
+  if (!str)<br>
+    return;<br>
+<br>
+  // We are going to remove the escape sequences in place.<br>
+  char *s = str;<br>
+  char *z = str;<br>
+  while (*s != '\0') {<br>
+    CHECK_GE(s, z);<br>
+    // Skip over ANSI escape sequences with pointer 's'.<br>
+    if (*s == '\033' && *(s + 1) == '[') {<br>
+      s = internal_strchrnul(s, 'm');<br>
+      if (*s == '\0') {<br>
+        break;<br>
+      }<br>
+      s++;<br>
+      continue;<br>
+    }<br>
+    // 's' now points at a character we want to keep. Copy over the buffer<br>
+    // content if the escape sequence has been perviously skipped andadvance<br>
+    // both pointers.<br>
+    if (s != z)<br>
+      *z = *s;<br>
+<br>
+    // If we have not seen an escape sequence, just advance both pointers.<br>
+    z++;<br>
+    s++;<br>
+  }<br>
+<br>
+  // Null terminate the string.<br>
+  *z = '\0';<br>
+}<br>
+<br>
 void LoadedModule::set(const char *module_name, uptr base_address) {<br>
   clear();<br>
   full_name_ = internal_strdup(module_name);<br>
<br>
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h?rev=251577&r1=251576&r2=251577&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h?rev=251577&r1=251576&r2=251577&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h (original)<br>
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h Wed Oct 28 18:18:44 2015<br>
@@ -162,6 +162,7 @@ void SetLowLevelAllocateCallback(LowLeve<br>
 // IO<br>
 void RawWrite(const char *buffer);<br>
 bool ColorizeReports();<br>
+void RemoveANSIEscapeSequencesFromString(char *buffer);<br>
 void Printf(const char *format, ...);<br>
 void Report(const char *format, ...);<br>
 void SetPrintfAndReportCallback(void (*callback)(const char *));<br>
@@ -648,13 +649,27 @@ enum AndroidApiLevel {<br>
   ANDROID_POST_LOLLIPOP = 23<br>
 };<br>
<br>
+void WriteToSyslog(const char *buffer);<br>
+<br>
+#if SANITIZER_MAC<br>
+void LogFullErrorReport(const char *error_message_buffer);<br>
+#else<br>
+INLINE void LogFullErrorReport(const char *error_message_buffer) {}<br>
+#endif<br>
+<br>
+#if SANITIZER_LINUX || SANITIZER_MAC<br>
+void WriteOneLineToSyslog(const char *s);<br>
+#else<br>
+INLINE void WriteOneLineToSyslog(const char *s) {}<br>
+#endif<br>
+<br>
 #if SANITIZER_LINUX<br>
 // Initialize Android logging. Any writes before this are silently lost.<br>
 void AndroidLogInit();<br>
-void WriteToSyslog(const char *buffer);<br>
+bool ShouldLogAfterPrintf();<br>
 #else<br>
 INLINE void AndroidLogInit() {}<br>
-INLINE void WriteToSyslog(const char *buffer) {}<br>
+INLINE bool ShouldLogAfterPrintf() { return false; }<br>
 #endif<br>
<br>
 #if SANITIZER_ANDROID<br>
<br>
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_libcdep.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_libcdep.cc?rev=251577&r1=251576&r2=251577&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_libcdep.cc?rev=251577&r1=251576&r2=251577&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_libcdep.cc (original)<br>
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_libcdep.cc Wed Oct 28 18:18:44 2015<br>
@@ -12,6 +12,7 @@<br>
 //===----------------------------------------------------------------------===//<br>
<br>
 #include "sanitizer_common.h"<br>
+#include "sanitizer_allocator_internal.h"<br>
 #include "sanitizer_flags.h"<br>
 #include "sanitizer_stackdepot.h"<br>
 #include "sanitizer_stacktrace.h"<br>
@@ -46,6 +47,7 @@ void SetSandboxingCallback(void (*f)())<br>
 }<br>
<br>
 void ReportErrorSummary(const char *error_type, StackTrace *stack) {<br>
+#if !SANITIZER_GO<br>
   if (!common_flags()->print_summary)<br>
     return;<br>
   if (stack->size == 0) {<br>
@@ -58,6 +60,7 @@ void ReportErrorSummary(const char *erro<br>
   SymbolizedStack *frame = Symbolizer::GetOrInit()->SymbolizePC(pc);<br>
   ReportErrorSummary(error_type, frame->info);<br>
   frame->ClearAll();<br>
+#endif<br>
 }<br>
<br>
 static void (*SoftRssLimitExceededCallback)(bool exceeded);<br>
@@ -116,8 +119,30 @@ void BackgroundThread(void *arg) {<br>
   }<br>
 }<br>
<br>
+void WriteToSyslog(const char *buffer) {<br>
+  char *copy = internal_strdup(buffer);<br>
+  char *p = copy;<br>
+  char *q;<br>
+<br>
+  // Remove color sequences since syslogs cannot print them.<br>
+  RemoveANSIEscapeSequencesFromString(copy);<br>
+<br>
+  // Print one line at a time.<br>
+  // syslog, at least on Android, has an implicit message length limit.<br>
+  do {<br>
+    q = internal_strchr(p, '\n');<br>
+    if (q)<br>
+      *q = '\0';<br>
+    WriteOneLineToSyslog(p);<br>
+    if (q)<br>
+      p = q + 1;<br>
+  } while (q);<br>
+  InternalFree(copy);<br>
+}<br>
+<br>
 void MaybeStartBackgroudThread() {<br>
-#if SANITIZER_LINUX  // Need to implement/test on other platforms.<br>
+#if SANITIZER_LINUX && \<br>
+    !SANITIZER_GO  // Need to implement/test on other platforms.<br>
   // Start the background thread if one of the rss limits is given.<br>
   if (!common_flags()->hard_rss_limit_mb &&<br>
       !common_flags()->soft_rss_limit_mb) return;<br>
<br>
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_nolibc.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_nolibc.cc?rev=251577&r1=251576&r2=251577&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_nolibc.cc?rev=251577&r1=251576&r2=251577&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_nolibc.cc (original)<br>
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_nolibc.cc Wed Oct 28 18:18:44 2015<br>
@@ -18,9 +18,9 @@<br>
 namespace __sanitizer {<br>
<br>
 #if SANITIZER_LINUX<br>
-void WriteToSyslog(const char *buffer) {}<br>
+bool ShouldLogAfterPrintf() { return false; }<br>
 #endif<br>
-<br>
+void WriteToSyslog(const char *buffer) {}<br>
 void Abort() { internal__exit(1); }<br>
<br>
 }  // namespace __sanitizer<br>
<br>
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.inc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.inc?rev=251577&r1=251576&r2=251577&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.inc?rev=251577&r1=251576&r2=251577&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.inc (original)<br>
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.inc Wed Oct 28 18:18:44 2015<br>
@@ -56,7 +56,7 @@ COMMON_FLAG(<br>
     "Mention name of executable when reporting error and "<br>
     "append executable name to logs (as in \"log_path.exe_name.pid\").")<br>
 COMMON_FLAG(<br>
-    bool, log_to_syslog, SANITIZER_ANDROID,<br>
+    bool, log_to_syslog, SANITIZER_ANDROID || SANITIZER_MAC,<br>
     "Write all sanitizer output to syslog in addition to other means of "<br>
     "logging.")<br>
 COMMON_FLAG(<br>
<br>
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux_libcdep.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux_libcdep.cc?rev=251577&r1=251576&r2=251577&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux_libcdep.cc?rev=251577&r1=251576&r2=251577&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux_libcdep.cc (original)<br>
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux_libcdep.cc Wed Oct 28 18:18:44 2015<br>
@@ -548,16 +548,16 @@ void AndroidLogInit() {<br>
   atomic_store(&android_log_initialized, 1, memory_order_release);<br>
 }<br>
<br>
-static bool IsSyslogAvailable() {<br>
+bool ShouldLogAfterPrintf() {<br>
   return atomic_load(&android_log_initialized, memory_order_acquire);<br>
 }<br>
 #else<br>
 void AndroidLogInit() {}<br>
<br>
-static bool IsSyslogAvailable() { return true; }<br>
+bool ShouldLogAfterPrintf() { return true; }<br>
 #endif  // SANITIZER_ANDROID<br>
<br>
-static void WriteOneLineToSyslog(const char *s) {<br>
+void WriteOneLineToSyslog(const char *s) {<br>
 #if SANITIZER_ANDROID &&__ANDROID_API__ < 21<br>
   __android_log_write(ANDROID_LOG_INFO, NULL, s);<br>
 #else<br>
@@ -565,24 +565,6 @@ static void WriteOneLineToSyslog(const c<br>
 #endif<br>
 }<br>
<br>
-void WriteToSyslog(const char *buffer) {<br>
-  if (!IsSyslogAvailable())<br>
-    return;<br>
-  char *copy = internal_strdup(buffer);<br>
-  char *p = copy;<br>
-  char *q;<br>
-  // syslog, at least on Android, has an implicit message length limit.<br>
-  // Print one line at a time.<br>
-  do {<br>
-    q = internal_strchr(p, '\n');<br>
-    if (q)<br>
-      *q = '\0';<br>
-    WriteOneLineToSyslog(p);<br>
-    if (q)<br>
-      p = q + 1;<br>
-  } while (q);<br>
-  InternalFree(copy);<br>
-}<br>
 #endif // SANITIZER_LINUX<br>
<br>
 } // namespace __sanitizer<br>
<br>
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc?rev=251577&r1=251576&r2=251577&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc?rev=251577&r1=251576&r2=251577&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc (original)<br>
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc Wed Oct 28 18:18:44 2015<br>
@@ -36,12 +36,14 @@<br>
 extern char **environ;<br>
 #endif<br>
<br>
+#include <asl.h><br>
 #include <errno.h><br>
 #include <fcntl.h><br>
 #include <libkern/OSAtomic.h><br>
 #include <mach-o/dyld.h><br>
 #include <mach/mach.h><br>
 #include <mach/vm_statistics.h><br>
+#include <os/trace.h><br>
 #include <pthread.h><br>
 #include <sched.h><br>
 #include <signal.h><br>
@@ -371,6 +373,45 @@ uptr GetRSS() {<br>
   return info.resident_size;<br>
 }<br>
<br>
+static BlockingMutex syslog_lock(LINKER_INITIALIZED);<br>
+<br>
+void WriteOneLineToSyslog(const char *s) {<br>
+  syslog_lock.CheckLocked();<br>
+  asl_log(nullptr, nullptr, ASL_LEVEL_ERR, "%s", s);<br>
+}<br>
+<br>
+void LogFullErrorReport(const char *buffer) {<br>
+  // Log with os_trace. This will make it into the crash log.<br>
+  if (GetMacosVersion() >= MACOS_VERSION_MAVERICKS) {<br>
+    // os_trace requires the message (format parameter) to be a string literal.<br>
+    if (internal_strncmp(SanitizerToolName, "AddressSanitizer",<br>
+                         sizeof("AddressSanitizer") - 1) == 0)<br>
+      os_trace("Address Sanitizer reported a failure.");<br>
+    else if (internal_strncmp(SanitizerToolName, "UndefinedBehaviorSanitizer",<br>
+                              sizeof("UndefinedBehaviorSanitizer") - 1) == 0)<br>
+      os_trace("Undefined Behavior Sanitizer reported a failure.");<br>
+    else if (internal_strncmp(SanitizerToolName, "ThreadSanitizer",<br>
+                              sizeof("ThreadSanitizer") - 1) == 0)<br>
+      os_trace("Thread Sanitizer reported a failure.");<br>
+    else<br>
+      os_trace("Sanitizer tool reported a failure.");<br>
+<br>
+    if (common_flags()->log_to_syslog)<br>
+      os_trace("Consult syslog for more information.");<br>
+  }<br>
+<br>
+  // Log to syslog.<br>
+  // The logging on OS X may call pthread_create so we need the threading<br>
+  // environment to be fully initialized. Also, this should never be called when<br>
+  // holding the thread registry lock since that may result in a deadlock. If<br>
+  // the reporting thread holds the thread registry mutex, and asl_log waits<br>
+  // for GCD to dispatch a new thread, the process will deadlock, because the<br>
+  // pthread_create wrapper needs to acquire the lock as well.<br>
+  BlockingMutexLock l(&syslog_lock);<br>
+  if (common_flags()->log_to_syslog)<br>
+    WriteToSyslog(buffer);<br>
+}<br>
+<br>
 void *internal_start_thread(void (*func)(void *arg), void *arg) { return 0; }<br>
 void internal_join_thread(void *th) { }<br>
<br>
<br>
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_printf.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_printf.cc?rev=251577&r1=251576&r2=251577&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_printf.cc?rev=251577&r1=251576&r2=251577&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_printf.cc (original)<br>
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_printf.cc Wed Oct 28 18:18:44 2015<br>
@@ -278,7 +278,7 @@ static void SharedPrintfCode(bool append<br>
 #   undef CHECK_NEEDED_LENGTH<br>
   }<br>
   RawWrite(buffer);<br>
-  if (common_flags()->log_to_syslog)<br>
+  if (common_flags()->log_to_syslog && ShouldLogAfterPrintf())<br>
     WriteToSyslog(buffer);<br>
   CallPrintfAndReportCallback(buffer);<br>
   // If we had mapped any memory, clean up.<br>
<br>
Modified: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_common_test.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_common_test.cc?rev=251577&r1=251576&r2=251577&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_common_test.cc?rev=251577&r1=251576&r2=251577&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_common_test.cc (original)<br>
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_common_test.cc Wed Oct 28 18:18:44 2015<br>
@@ -208,6 +208,30 @@ TEST(SanitizerCommon, StripPathPrefix) {<br>
   EXPECT_STREQ("file.h", StripPathPrefix("/usr/lib/./file.h", "/usr/lib/"));<br>
 }<br>
<br>
+TEST(SanitizerCommon, RemoveANSIEscapeSequencesFromString) {<br>
+  RemoveANSIEscapeSequencesFromString(nullptr);<br>
+  const char *buffs[22] = {<br>
+    "Default",                                "Default",<br>
+    "\033[95mLight magenta",                  "Light magenta",<br>
+    "\033[30mBlack\033[32mGreen\033[90mGray", "BlackGreenGray",<br>
+    "\033[106mLight cyan \033[107mWhite ",    "Light cyan White ",<br>
+    "\033[31mHello\033[0m World",             "Hello World",<br>
+    "\033[38;5;82mHello \033[38;5;198mWorld", "Hello World",<br>
+    "123[653456789012",                       "123[653456789012",<br>
+    "Normal \033[5mBlink \033[25mNormal",     "Normal Blink Normal",<br>
+    "\033[106m\033[107m",                     "",<br>
+    "",                                       "",<br>
+    " ",                                      " ",<br>
+  };<br>
+<br>
+  for (size_t i = 0; i < ARRAY_SIZE(buffs); i+=2) {<br>
+    char *buffer_copy = internal_strdup(buffs[i]);<br>
+    RemoveANSIEscapeSequencesFromString(buffer_copy);<br>
+    EXPECT_STREQ(buffer_copy, buffs[i+1]);<br>
+    InternalFree(buffer_copy);<br>
+  }<br>
+}<br>
+<br>
 TEST(SanitizerCommon, InternalScopedString) {<br>
   InternalScopedString str(10);<br>
   EXPECT_EQ(0U, str.length());<br>
<br>
Modified: compiler-rt/trunk/lib/tsan/go/buildgo.sh<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/go/buildgo.sh?rev=251577&r1=251576&r2=251577&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/go/buildgo.sh?rev=251577&r1=251576&r2=251577&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/lib/tsan/go/buildgo.sh (original)<br>
+++ compiler-rt/trunk/lib/tsan/go/buildgo.sh Wed Oct 28 18:18:44 2015<br>
@@ -20,6 +20,7 @@ SRCS="<br>
        ../rtl/tsan_sync.cc<br>
        ../../sanitizer_common/sanitizer_allocator.cc<br>
        ../../sanitizer_common/sanitizer_common.cc<br>
+       ../../sanitizer_common/sanitizer_common_libcdep.cc<br>
        ../../sanitizer_common/sanitizer_deadlock_detector2.cc<br>
        ../../sanitizer_common/sanitizer_flag_parser.cc<br>
        ../../sanitizer_common/sanitizer_flags.cc<br>
<br>
Modified: compiler-rt/trunk/test/asan/lit.cfg<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/lit.cfg?rev=251577&r1=251576&r2=251577&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/lit.cfg?rev=251577&r1=251576&r2=251577&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/asan/lit.cfg (original)<br>
+++ compiler-rt/trunk/test/asan/lit.cfg Wed Oct 28 18:18:44 2015<br>
@@ -34,7 +34,9 @@ default_asan_opts = ''<br>
 if config.host_os == 'Darwin':<br>
   # On Darwin, we default to `abort_on_error=1`, which would make tests run<br>
   # much slower. Let's override this and run lit tests with 'abort_on_error=0'.<br>
+  # Also, make sure we do not overwhelm the syslog while testing.<br>
   default_asan_opts = 'abort_on_error=0'<br>
+  default_asan_opts += ':log_to_syslog=0'<br>
 if default_asan_opts:<br>
   config.environment['ASAN_OPTIONS'] = default_asan_opts<br>
   default_asan_opts += ':'<br>
<br>
Modified: compiler-rt/trunk/test/ubsan/lit.common.cfg<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/ubsan/lit.common.cfg?rev=251577&r1=251576&r2=251577&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/ubsan/lit.common.cfg?rev=251577&r1=251576&r2=251577&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/ubsan/lit.common.cfg (original)<br>
+++ compiler-rt/trunk/test/ubsan/lit.common.cfg Wed Oct 28 18:18:44 2015<br>
@@ -42,6 +42,7 @@ if config.host_os == 'Darwin':<br>
   # On Darwin, we default to `abort_on_error=1`, which would make tests run<br>
   # much slower. Let's override this and run lit tests with 'abort_on_error=0'.<br>
   default_ubsan_opts += ['abort_on_error=0']<br>
+  default_ubsan_opts += ['log_to_syslog=0']<br>
 default_ubsan_opts_str = ':'.join(default_ubsan_opts)<br>
 if default_ubsan_opts_str:<br>
   config.environment['UBSAN_OPTIONS'] = default_ubsan_opts_str<br>
<br>
<br>
_______________________________________________<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/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr">Alexey Samsonov<br><a href="mailto:vonosmas@gmail.com" target="_blank">vonosmas@gmail.com</a></div></div>
</div>