[compiler-rt] [compiler-rt] Replace deprecated os_trace calls on mac (PR #138908)
Dan Blackwell via llvm-commits
llvm-commits at lists.llvm.org
Tue May 13 07:50:09 PDT 2025
https://github.com/DanBlackwell updated https://github.com/llvm/llvm-project/pull/138908
>From 598eb65471ca9a43f0023c8e38964e6ece408f83 Mon Sep 17 00:00:00 2001
From: Dan Blackwell <dan_blackwell at apple.com>
Date: Wed, 7 May 2025 16:10:59 +0100
Subject: [PATCH 1/5] [compiler-rt] Replace deprecated os_trace calls on mac
---
.../lib/sanitizer_common/sanitizer_mac.cpp | 44 +++++++++----------
1 file changed, 20 insertions(+), 24 deletions(-)
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp
index 0b8a75391136d..f02f78c4e19b4 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp
@@ -844,30 +844,26 @@ void LogMessageOnPrintf(const char *str) {
void LogFullErrorReport(const char *buffer) {
#if !SANITIZER_GO
- // Log with os_trace. This will make it into the crash log.
-#if SANITIZER_OS_TRACE
-#pragma clang diagnostic push
-// os_trace is deprecated.
-#pragma clang diagnostic ignored "-Wdeprecated-declarations"
- if (GetMacosAlignedVersion() >= MacosVersion(10, 10)) {
- // os_trace requires the message (format parameter) to be a string literal.
- if (internal_strncmp(SanitizerToolName, "AddressSanitizer",
- sizeof("AddressSanitizer") - 1) == 0)
- os_trace("Address Sanitizer reported a failure.");
- else if (internal_strncmp(SanitizerToolName, "UndefinedBehaviorSanitizer",
- sizeof("UndefinedBehaviorSanitizer") - 1) == 0)
- os_trace("Undefined Behavior Sanitizer reported a failure.");
- else if (internal_strncmp(SanitizerToolName, "ThreadSanitizer",
- sizeof("ThreadSanitizer") - 1) == 0)
- os_trace("Thread Sanitizer reported a failure.");
- else
- os_trace("Sanitizer tool reported a failure.");
-
- if (common_flags()->log_to_syslog)
- os_trace("Consult syslog for more information.");
- }
-#pragma clang diagnostic pop
-#endif
+# if SANITIZER_OS_TRACE
+ // Log with os_log_error. This will make it into the crash log.
+ if (GetMacosAlignedVersion() >= MacosVersion(10, 10)) {
+ if (internal_strncmp(SanitizerToolName, "AddressSanitizer",
+ sizeof("AddressSanitizer") - 1) == 0)
+ os_log_error(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.");
+ else if (internal_strncmp(SanitizerToolName, "ThreadSanitizer",
+ sizeof("ThreadSanitizer") - 1) == 0)
+ os_log_error(OS_LOG_DEFAULT, "Thread Sanitizer reported a failure.");
+ else
+ os_log_error(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.");
+ }
+# endif // SANITIZER_OS_TRACE
// Log to syslog.
// The logging on OS X may call pthread_create so we need the threading
>From 86bb81f216ab99552cd208296032462a6b6e8c51 Mon Sep 17 00:00:00 2001
From: Dan Blackwell <dan_blackwell at apple.com>
Date: Fri, 9 May 2025 11:59:30 +0100
Subject: [PATCH 2/5] Updated 10.10 to 10.12 for min version
---
compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp
index f02f78c4e19b4..c1a4d5ac39527 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp
@@ -846,7 +846,7 @@ void LogFullErrorReport(const char *buffer) {
#if !SANITIZER_GO
# if SANITIZER_OS_TRACE
// Log with os_log_error. This will make it into the crash log.
- if (GetMacosAlignedVersion() >= MacosVersion(10, 10)) {
+ if (GetMacosAlignedVersion() >= MacosVersion(10, 12)) {
if (internal_strncmp(SanitizerToolName, "AddressSanitizer",
sizeof("AddressSanitizer") - 1) == 0)
os_log_error(OS_LOG_DEFAULT, "Address Sanitizer reported a failure.");
>From 42ccb48ccfefd2c9515a79265e89828bdb68d3a8 Mon Sep 17 00:00:00 2001
From: Dan Blackwell <dan_blackwell at apple.com>
Date: Fri, 9 May 2025 14:10:10 +0100
Subject: [PATCH 3/5] Formatting fix
---
.../lib/sanitizer_common/sanitizer_mac.cpp | 40 +++++++++----------
1 file changed, 20 insertions(+), 20 deletions(-)
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp
index c1a4d5ac39527..d9ff0c961e4ba 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp
@@ -844,26 +844,26 @@ void LogMessageOnPrintf(const char *str) {
void LogFullErrorReport(const char *buffer) {
#if !SANITIZER_GO
-# if SANITIZER_OS_TRACE
- // Log with os_log_error. This will make it into the crash log.
- if (GetMacosAlignedVersion() >= MacosVersion(10, 12)) {
- if (internal_strncmp(SanitizerToolName, "AddressSanitizer",
- sizeof("AddressSanitizer") - 1) == 0)
- os_log_error(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.");
- else if (internal_strncmp(SanitizerToolName, "ThreadSanitizer",
- sizeof("ThreadSanitizer") - 1) == 0)
- os_log_error(OS_LOG_DEFAULT, "Thread Sanitizer reported a failure.");
- else
- os_log_error(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.");
- }
-# endif // SANITIZER_OS_TRACE
+# if SANITIZER_OS_TRACE
+ // Log with os_log_error. This will make it into the crash log.
+ if (GetMacosAlignedVersion() >= MacosVersion(10, 12)) {
+ if (internal_strncmp(SanitizerToolName, "AddressSanitizer",
+ sizeof("AddressSanitizer") - 1) == 0)
+ os_log_error(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.");
+ else if (internal_strncmp(SanitizerToolName, "ThreadSanitizer",
+ sizeof("ThreadSanitizer") - 1) == 0)
+ os_log_error(OS_LOG_DEFAULT, "Thread Sanitizer reported a failure.");
+ else
+ os_log_error(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.");
+ }
+# endif // SANITIZER_OS_TRACE
// Log to syslog.
// The logging on OS X may call pthread_create so we need the threading
>From 96dc7b08e016a5ffae091f16964f30fb859c7c69 Mon Sep 17 00:00:00 2001
From: Dan Blackwell <dan_blackwell at apple.com>
Date: Tue, 13 May 2025 15:44:44 +0100
Subject: [PATCH 4/5] Addressed review comments
---
compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp | 11 -----------
1 file changed, 11 deletions(-)
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp
index d9ff0c961e4ba..00928c53ba44c 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp
@@ -38,13 +38,6 @@
extern char **environ;
# endif
-# if defined(__has_include) && __has_include(<os/trace.h>)
-# define SANITIZER_OS_TRACE 1
-# include <os/trace.h>
-# else
-# define SANITIZER_OS_TRACE 0
-# endif
-
// Integrate with CrashReporter library if available
# if defined(__has_include) && __has_include(<CrashReporterClient.h>)
# define HAVE_CRASHREPORTERCLIENT_H 1
@@ -844,9 +837,7 @@ void LogMessageOnPrintf(const char *str) {
void LogFullErrorReport(const char *buffer) {
#if !SANITIZER_GO
-# if SANITIZER_OS_TRACE
// Log with os_log_error. This will make it into the crash log.
- if (GetMacosAlignedVersion() >= MacosVersion(10, 12)) {
if (internal_strncmp(SanitizerToolName, "AddressSanitizer",
sizeof("AddressSanitizer") - 1) == 0)
os_log_error(OS_LOG_DEFAULT, "Address Sanitizer reported a failure.");
@@ -862,8 +853,6 @@ void LogFullErrorReport(const char *buffer) {
if (common_flags()->log_to_syslog)
os_log_error(OS_LOG_DEFAULT, "Consult syslog for more information.");
- }
-# endif // SANITIZER_OS_TRACE
// Log to syslog.
// The logging on OS X may call pthread_create so we need the threading
>From 38b774996a71f5c110f274cefc46617a9dd36aec Mon Sep 17 00:00:00 2001
From: Dan Blackwell <dan_blackwell at apple.com>
Date: Tue, 13 May 2025 15:48:22 +0100
Subject: [PATCH 5/5] Formatting fixes
---
.../lib/sanitizer_common/sanitizer_mac.cpp | 34 +++++++++----------
1 file changed, 17 insertions(+), 17 deletions(-)
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp
index 00928c53ba44c..bb71af5ad8b6a 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp
@@ -836,23 +836,23 @@ void LogMessageOnPrintf(const char *str) {
}
void LogFullErrorReport(const char *buffer) {
-#if !SANITIZER_GO
+# if !SANITIZER_GO
// Log with os_log_error. 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.");
- else if (internal_strncmp(SanitizerToolName, "UndefinedBehaviorSanitizer",
- sizeof("UndefinedBehaviorSanitizer") - 1) == 0)
- os_log_error(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.");
- else
- os_log_error(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.");
+ if (internal_strncmp(SanitizerToolName, "AddressSanitizer",
+ sizeof("AddressSanitizer") - 1) == 0)
+ os_log_error(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.");
+ else if (internal_strncmp(SanitizerToolName, "ThreadSanitizer",
+ sizeof("ThreadSanitizer") - 1) == 0)
+ os_log_error(OS_LOG_DEFAULT, "Thread Sanitizer reported a failure.");
+ else
+ os_log_error(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.");
// Log to syslog.
// The logging on OS X may call pthread_create so we need the threading
@@ -866,7 +866,7 @@ void LogFullErrorReport(const char *buffer) {
WriteToSyslog(buffer);
// The report is added to CrashLog as part of logging all of Printf output.
-#endif
+# endif // !SANITIZER_GO
}
SignalContext::WriteFlag SignalContext::GetWriteFlag() const {
More information about the llvm-commits
mailing list