-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[compiler-rt] Replace deprecated os_trace calls on mac #138908
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
[compiler-rt] Replace deprecated os_trace calls on mac #138908
Conversation
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
@llvm/pr-subscribers-compiler-rt-sanitizer Author: Dan Blackwell (DanBlackwell) ChangesCurrently there are deprecation warnings suppressed for rdar://140295247 Full diff: https://github.com/llvm/llvm-project/pull/138908.diff 1 Files Affected:
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
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
#endif | ||
# if SANITIZER_OS_TRACE | ||
// Log with os_log_error. This will make it into the crash log. | ||
if (GetMacosAlignedVersion() >= MacosVersion(10, 10)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did we test this on 10.10? Is this the proper version for the new call?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've now bumped the check to 10.12, but also the minimum supported macOS for sanitizers looks to be 10.13 anyway:
set(DEFAULT_SANITIZER_MIN_OSX_VERSION 10.13) |
I think the right thing here may be to find out when the deprecation occurred and call the new calls after that version, but maintain the os_trace calls for the older versions. |
You can test this locally with the following command:git-clang-format --diff HEAD~1 HEAD --extensions cpp -- compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp View the diff from clang-format here.diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp
index c1a4d5ac3..d9ff0c961 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
|
As noted, it seems that these new
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good cleanup, thanks!
I have a few nits.
// os_trace requires the message (format parameter) to be a string literal. | ||
# if SANITIZER_OS_TRACE | ||
// Log with os_log_error. This will make it into the crash log. | ||
if (GetMacosAlignedVersion() >= MacosVersion(10, 12)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it seems that these new os_log_error calls are available in all supported macOS above the minimum version required for sanitizer support: ma
Could we completely omit the check then? No point in trying to preserve runtime compatibility with < macOS 10.13.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have removed the check now.
if (GetMacosAlignedVersion() >= MacosVersion(10, 10)) { | ||
// os_trace requires the message (format parameter) to be a string literal. | ||
# if SANITIZER_OS_TRACE | ||
// Log with os_log_error. This will make it into the crash log. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you haven't, please double-check this is still true with the new API.
Is there any difference in crash log format?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Behaviour seems identical - note that these changes only affect the single message that gets output on crash. The actual Asan crash report is unaffected.
#pragma clang diagnostic ignored "-Wdeprecated-declarations" | ||
if (GetMacosAlignedVersion() >= MacosVersion(10, 10)) { | ||
// os_trace requires the message (format parameter) to be a string literal. | ||
# if SANITIZER_OS_TRACE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can now also remove the SANITIZER_OS_TRACE
macro and #include <os/trace.h>
above.
This file already includes #include <os/log.h>
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Currently there are deprecation warnings suppressed for
os_trace
; this patch replaces all uses withos_log_error
.rdar://140295247