From 039567b664b4e5fad2c6fac1d6f9a6345a15f2d8 Mon Sep 17 00:00:00 2001 From: Emily Shi Date: Thu, 4 Feb 2021 21:03:25 -0800 Subject: [PATCH] [Darwin] Switch to new logging api for sanitizers Switch to new logging api added in [[ https://developer.apple.com/documentation/os/os_log_error | macOS 10.12 ]] that is more memory safe and enables us to label the log messages in the future. Falls back to old API if ran on older OS versions. Commited by Dan Liew on behalf of Emily Shi. rdar://25181524 Reviewed By: delcypher, yln Differential Revision: https://reviews.llvm.org/D95977 --- compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp index 2b53d7d730d7..643755af818c 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp +++ b/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp @@ -62,6 +62,7 @@ extern "C" { #include #include #include +#include #include #include #include @@ -770,7 +771,11 @@ static BlockingMutex syslog_lock(LINKER_INITIALIZED); void WriteOneLineToSyslog(const char *s) { #if !SANITIZER_GO syslog_lock.CheckLocked(); - asl_log(nullptr, nullptr, ASL_LEVEL_ERR, "%s", s); + if (GetMacosAlignedVersion() >= MacosVersion(10, 12)) { + os_log_error(OS_LOG_DEFAULT, "%{public}s", s); + } else { + asl_log(nullptr, nullptr, ASL_LEVEL_ERR, "%s", s); + } #endif }