Index: compiler-rt/trunk/lib/asan/asan_report.cc =================================================================== --- compiler-rt/trunk/lib/asan/asan_report.cc +++ compiler-rt/trunk/lib/asan/asan_report.cc @@ -696,9 +696,6 @@ error_message_buffer, kErrorMessageBufferSize); } - // Remove color sequences since logs cannot print them. - RemoveANSIEscapeSequencesFromString(buffer_copy.data()); - LogFullErrorReport(buffer_copy.data()); if (error_report_callback) { Index: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h =================================================================== --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h @@ -665,17 +665,17 @@ #if SANITIZER_LINUX || SANITIZER_MAC void WriteOneLineToSyslog(const char *s); +void LogMessageOnPrintf(const char *str); #else INLINE void WriteOneLineToSyslog(const char *s) {} +INLINE void LogMessageOnPrintf(const char *str) {} #endif #if SANITIZER_LINUX // Initialize Android logging. Any writes before this are silently lost. void AndroidLogInit(); -bool ShouldLogAfterPrintf(); #else INLINE void AndroidLogInit() {} -INLINE bool ShouldLogAfterPrintf() { return false; } #endif #if SANITIZER_ANDROID Index: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_libcdep.cc =================================================================== --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_libcdep.cc +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_libcdep.cc @@ -125,9 +125,6 @@ char *p = msg_copy.data(); char *q; - // Remove color sequences since syslogs cannot print them. - RemoveANSIEscapeSequencesFromString(p); - // Print one line at a time. // syslog, at least on Android, has an implicit message length limit. do { Index: compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux_libcdep.cc =================================================================== --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux_libcdep.cc +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux_libcdep.cc @@ -524,13 +524,13 @@ atomic_store(&android_log_initialized, 1, memory_order_release); } -bool ShouldLogAfterPrintf() { +static bool ShouldLogAfterPrintf() { return atomic_load(&android_log_initialized, memory_order_acquire); } #else void AndroidLogInit() {} -bool ShouldLogAfterPrintf() { return true; } +static bool ShouldLogAfterPrintf() { return true; } #endif // SANITIZER_ANDROID void WriteOneLineToSyslog(const char *s) { @@ -541,6 +541,11 @@ #endif } +void LogMessageOnPrintf(const char *str) { + if (common_flags()->log_to_syslog && ShouldLogAfterPrintf()) + WriteToSyslog(str); +} + #endif // SANITIZER_LINUX } // namespace __sanitizer Index: compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.h =================================================================== --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.h +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.h @@ -44,9 +44,11 @@ &__crashreporter_info_buff__[0]; asm(".desc ___crashreporter_info__, 0x10"); } // extern "C" +static BlockingMutex crashreporter_info_mutex(LINKER_INITIALIZED); -INLINE void CRSetCrashLogMessage(const char *msg) { - internal_strlcpy(__crashreporter_info_buff__, msg, +INLINE void CRAppendCrashLogMessage(const char *msg) { + BlockingMutexLock l(&crashreporter_info_mutex); + internal_strlcat(__crashreporter_info_buff__, msg, sizeof(__crashreporter_info_buff__)); } #endif // SANITIZER_MAC Index: compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc =================================================================== --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc @@ -430,6 +430,12 @@ asl_log(nullptr, nullptr, ASL_LEVEL_ERR, "%s", s); } +void LogMessageOnPrintf(const char *str) { + // Log all printf output to CrashLog. + if (common_flags()->abort_on_error) + CRAppendCrashLogMessage(str); +} + void LogFullErrorReport(const char *buffer) { // Log with os_trace. This will make it into the crash log. #if SANITIZER_OS_TRACE @@ -463,9 +469,7 @@ if (common_flags()->log_to_syslog) WriteToSyslog(buffer); - // Log to CrashLog. - if (common_flags()->abort_on_error) - CRSetCrashLogMessage(buffer); + // The report is added to CrashLog as part of logging all of Printf output. } void GetPcSpBp(void *context, uptr *pc, uptr *sp, uptr *bp) { Index: compiler-rt/trunk/lib/sanitizer_common/sanitizer_printf.cc =================================================================== --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_printf.cc +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_printf.cc @@ -278,9 +278,12 @@ # undef CHECK_NEEDED_LENGTH } RawWrite(buffer); - if (common_flags()->log_to_syslog && ShouldLogAfterPrintf()) - WriteToSyslog(buffer); + + // Remove color sequences from the message. + RemoveANSIEscapeSequencesFromString(buffer); CallPrintfAndReportCallback(buffer); + LogMessageOnPrintf(buffer); + // If we had mapped any memory, clean up. if (buffer != local_buffer) UnmapOrDie((void *)buffer, buffer_size);