From 11514ea58f35b64bbe295881aa8f30606889fe32 Mon Sep 17 00:00:00 2001 From: Dan Blackwell Date: Tue, 15 Jul 2025 11:09:38 +0100 Subject: [PATCH 1/2] [compiler-rt][sanitizer-common] Use os_log for DriverKit as os_log_error is undefined --- .../lib/sanitizer_common/sanitizer_mac.cpp | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp index bb71af5ad8b6a..bdee590bbd298 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp +++ b/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp @@ -837,22 +837,29 @@ void LogMessageOnPrintf(const char *str) { void LogFullErrorReport(const char *buffer) { # if !SANITIZER_GO - // Log with os_log_error. This will make it into the crash log. +# if SANITIZER_DRIVERKIT +# define SANITIZER_OS_LOG os_log +# else +# define SANITIZER_OS_LOG os_log_error +# endif + + // Log with os_log.*. This will make it into the crash log. if (internal_strncmp(SanitizerToolName, "AddressSanitizer", sizeof("AddressSanitizer") - 1) == 0) - os_log_error(OS_LOG_DEFAULT, "Address Sanitizer reported a failure."); + SANITIZER_OS_LOG(OS_LOG_DEFAULT, "Address Sanitizer reported a failure."); else if (internal_strncmp(SanitizerToolName, "UndefinedBehaviorSanitizer", sizeof("UndefinedBehaviorSanitizer") - 1) == 0) - os_log_error(OS_LOG_DEFAULT, - "Undefined Behavior Sanitizer reported a failure."); + SANITIZER_OS_LOG(OS_LOG_DEFAULT, + "Undefined Behavior Sanitizer reported a failure."); else if (internal_strncmp(SanitizerToolName, "ThreadSanitizer", sizeof("ThreadSanitizer") - 1) == 0) - os_log_error(OS_LOG_DEFAULT, "Thread Sanitizer reported a failure."); + SANITIZER_OS_LOG(OS_LOG_DEFAULT, "Thread Sanitizer reported a failure."); else - os_log_error(OS_LOG_DEFAULT, "Sanitizer tool reported a failure."); + SANITIZER_OS_LOG(OS_LOG_DEFAULT, "Sanitizer tool reported a failure."); if (common_flags()->log_to_syslog) - os_log_error(OS_LOG_DEFAULT, "Consult syslog for more information."); + SANITIZER_OS_LOG(OS_LOG_DEFAULT, "Consult syslog for more information."); +# undef SANITIZER_OS_LOG // Log to syslog. // The logging on OS X may call pthread_create so we need the threading From 496cc35c1413310e1a7f706c658720e9922cc948 Mon Sep 17 00:00:00 2001 From: Dan Blackwell Date: Wed, 16 Jul 2025 11:58:34 +0100 Subject: [PATCH 2/2] Replace another instance of os_log_error --- .../lib/sanitizer_common/sanitizer_mac.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp index bdee590bbd298..546a37428c2c3 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp +++ b/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp @@ -769,11 +769,17 @@ void internal_join_thread(void *th) { pthread_join((pthread_t)th, 0); } static Mutex syslog_lock; # endif +# if SANITIZER_DRIVERKIT +# define SANITIZER_OS_LOG os_log +# else +# define SANITIZER_OS_LOG os_log_error +# endif + 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); + SANITIZER_OS_LOG(OS_LOG_DEFAULT, "%{public}s", s); } else { #pragma clang diagnostic push // as_log is deprecated. @@ -837,12 +843,6 @@ void LogMessageOnPrintf(const char *str) { void LogFullErrorReport(const char *buffer) { # if !SANITIZER_GO -# if SANITIZER_DRIVERKIT -# define SANITIZER_OS_LOG os_log -# else -# define SANITIZER_OS_LOG os_log_error -# endif - // Log with os_log.*. This will make it into the crash log. if (internal_strncmp(SanitizerToolName, "AddressSanitizer", sizeof("AddressSanitizer") - 1) == 0) @@ -859,7 +859,6 @@ void LogFullErrorReport(const char *buffer) { if (common_flags()->log_to_syslog) SANITIZER_OS_LOG(OS_LOG_DEFAULT, "Consult syslog for more information."); -# undef SANITIZER_OS_LOG // Log to syslog. // The logging on OS X may call pthread_create so we need the threading