Skip to content

[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

Merged

Conversation

DanBlackwell
Copy link
Contributor

Currently there are deprecation warnings suppressed for os_trace; this patch replaces all uses with os_log_error.

rdar://140295247

Copy link

github-actions bot commented May 7, 2025

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 @ followed by their GitHub username.

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.

@llvmbot
Copy link
Member

llvmbot commented May 7, 2025

@llvm/pr-subscribers-compiler-rt-sanitizer

Author: Dan Blackwell (DanBlackwell)

Changes

Currently there are deprecation warnings suppressed for os_trace; this patch replaces all uses with os_log_error.

rdar://140295247


Full diff: https://github.com/llvm/llvm-project/pull/138908.diff

1 Files Affected:

  • (modified) compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp (+20-24)
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

Copy link
Contributor

@wrotki wrotki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@thetruestblue thetruestblue requested review from yln and thetruestblue May 8, 2025 16:48
@thetruestblue
Copy link
Contributor

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.

Copy link

github-actions bot commented May 9, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

@DanBlackwell
Copy link
Contributor Author

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.

As noted, it seems that these new os_log_error calls are available in all supported macOS above the minimum version required for sanitizer support:

set(DEFAULT_SANITIZER_MIN_OSX_VERSION 10.13)
.

Copy link
Collaborator

@yln yln left a 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.

@yln yln assigned yln and DanBlackwell and unassigned yln May 12, 2025
@DanBlackwell DanBlackwell requested a review from yln May 13, 2025 14:51
@thetruestblue thetruestblue merged commit 4964d98 into llvm:main May 20, 2025
10 checks passed
Copy link

@DanBlackwell Congratulations on having your first Pull Request (PR) merged into the LLVM Project!

Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail here.

If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are working as expected, well done!

kostasalv pushed a commit to kostasalv/llvm-project that referenced this pull request May 21, 2025
Currently there are deprecation warnings suppressed for `os_trace`; this
patch replaces all uses with `os_log_error`.

rdar://140295247
sivan-shani pushed a commit to sivan-shani/llvm-project that referenced this pull request Jun 3, 2025
Currently there are deprecation warnings suppressed for `os_trace`; this
patch replaces all uses with `os_log_error`.

rdar://140295247
ajaden-codes pushed a commit to Jaddyen/llvm-project that referenced this pull request Jun 6, 2025
Currently there are deprecation warnings suppressed for `os_trace`; this
patch replaces all uses with `os_log_error`.

rdar://140295247
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants