Skip to content

Commit 039567b

Browse files
araliszadanliew-apple
authored andcommitted
[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
1 parent 8d4cd2d commit 039567b

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ extern "C" {
6262
#include <mach/mach_time.h>
6363
#include <mach/vm_statistics.h>
6464
#include <malloc/malloc.h>
65+
#include <os/log.h>
6566
#include <pthread.h>
6667
#include <sched.h>
6768
#include <signal.h>
@@ -770,7 +771,11 @@ static BlockingMutex syslog_lock(LINKER_INITIALIZED);
770771
void WriteOneLineToSyslog(const char *s) {
771772
#if !SANITIZER_GO
772773
syslog_lock.CheckLocked();
773-
asl_log(nullptr, nullptr, ASL_LEVEL_ERR, "%s", s);
774+
if (GetMacosAlignedVersion() >= MacosVersion(10, 12)) {
775+
os_log_error(OS_LOG_DEFAULT, "%{public}s", s);
776+
} else {
777+
asl_log(nullptr, nullptr, ASL_LEVEL_ERR, "%s", s);
778+
}
774779
#endif
775780
}
776781

0 commit comments

Comments
 (0)