[compiler-rt] r251447 - [asan] On OS X, log reports to syslog and os_trace
H.J. Lu via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 27 15:24:42 PDT 2015
On Tue, Oct 27, 2015 at 1:13 PM, Anna Zaks via llvm-commits
<llvm-commits at lists.llvm.org> wrote:
> Author: zaks
> Date: Tue Oct 27 15:13:01 2015
> New Revision: 251447
>
> URL: http://llvm.org/viewvc/llvm-project?rev=251447&view=rev
> Log:
> [asan] On OS X, log reports to syslog and os_trace
>
> When ASan currently detects a bug, by default it will only print out the text
> of the report to stderr. This patch changes this behavior and writes the full
> text of the report to syslog before we terminate the process. It also calls
> os_trace (Activity Tracing available on OS X and iOS) with a message saying
> that the report is available in syslog. This is useful, because this message
> will be shown in the crash log.
>
> For this to work, the patch makes sure we store the full report into
> error_message_buffer unconditionally, and it also strips out ANSI escape
> sequences from the report (they are used when producing colored reports).
>
> I've initially tried to log to syslog during printing, which is done on Android
> right now. The advantage is that if we crash during error reporting or the
> produced error does not go through ScopedInErrorReport, we would still get a
> (partial) message in the syslog. However, that solution is very problematic on
> OS X. One issue is that the logging routine uses GCD, which may spawn a new
> thread on its behalf. In many cases, the reporting logic locks threadRegistry,
> which leads to deadlocks.
>
> Reviewed at http://reviews.llvm.org/D13452
>
> Modified:
> compiler-rt/trunk/lib/asan/asan_report.cc
> compiler-rt/trunk/lib/asan/tests/asan_test_main.cc
> compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc
> compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
> compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_libcdep.cc
> compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.inc
> compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux_libcdep.cc
> compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc
> compiler-rt/trunk/lib/sanitizer_common/sanitizer_printf.cc
> compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_common_test.cc
> compiler-rt/trunk/test/asan/lit.cfg
> compiler-rt/trunk/test/ubsan/lit.common.cfg
>
...
> Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux_libcdep.cc
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux_libcdep.cc?rev=251447&r1=251446&r2=251447&view=diff
> ==============================================================================
> --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux_libcdep.cc (original)
> +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux_libcdep.cc Tue Oct 27 15:13:01 2015
> @@ -548,16 +548,16 @@ void AndroidLogInit() {
> atomic_store(&android_log_initialized, 1, memory_order_release);
> }
>
> -static bool IsSyslogAvailable() {
> +bool ShouldLogAfterPrintf() {
> return atomic_load(&android_log_initialized, memory_order_acquire);
> }
> #else
> void AndroidLogInit() {}
>
> -static bool IsSyslogAvailable() { return true; }
> +bool ShouldLogAfterPrintf() { return true; }
> #endif // SANITIZER_ANDROID
>
> -static void WriteOneLineToSyslog(const char *s) {
> +void WriteOneLineToSyslog(const char *s) {
> #if SANITIZER_ANDROID &&__ANDROID_API__ < 21
> __android_log_write(ANDROID_LOG_INFO, NULL, s);
> #else
> @@ -565,24 +565,6 @@ static void WriteOneLineToSyslog(const c
> #endif
> }
>
> -void WriteToSyslog(const char *buffer) {
> - if (!IsSyslogAvailable())
> - return;
> - char *copy = internal_strdup(buffer);
> - char *p = copy;
> - char *q;
> - // syslog, at least on Android, has an implicit message length limit.
> - // Print one line at a time.
> - do {
> - q = internal_strchr(p, '\n');
> - if (q)
> - *q = '\0';
> - WriteOneLineToSyslog(p);
> - if (q)
> - p = q + 1;
> - } while (q);
> - InternalFree(copy);
> -}
> #endif // SANITIZER_LINUX
It caused:
/tmp/gotsan.wmNri3GVMz/race_linux_amd64.syso: In function
`__sanitizer::SharedPrintfCode(bool, char const*, __va_list_tag*)':
gotsan.cc:(.text+0x4a85): undefined reference to
`__sanitizer::WriteToSyslog(char const*)'
collect2: error: ld returned 1 exit status
@
on Fedora 22.
--
H.J.
More information about the llvm-commits
mailing list