[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
This commit is contained in:
Emily Shi 2021-02-04 21:03:25 -08:00 committed by Dan Liew
parent 8d4cd2da1f
commit 039567b664

View File

@ -62,6 +62,7 @@ extern "C" {
#include <mach/mach_time.h>
#include <mach/vm_statistics.h>
#include <malloc/malloc.h>
#include <os/log.h>
#include <pthread.h>
#include <sched.h>
#include <signal.h>
@ -770,7 +771,11 @@ static BlockingMutex syslog_lock(LINKER_INITIALIZED);
void WriteOneLineToSyslog(const char *s) {
#if !SANITIZER_GO
syslog_lock.CheckLocked();
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
}