Skip to content

[compiler-rt][rtsan] Improve error message wording to match ASan style #107620

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
merged 2 commits into from
Sep 10, 2024

Conversation

cjappl
Copy link
Contributor

@cjappl cjappl commented Sep 6, 2024

New error messages look like:

==4866==ERROR: RealtimeSanitizer: unsafe-library-call
Intercepted call to real-time unsafe function `malloc` in real-time context!
    #0 0x000100c838c4 in malloc rtsan_interceptors.cpp:310
    #1 0x000195bd7bd0 in operator new(unsigned long)+0x1c (libc++abi.dylib:arm64+0x16bd0)
    #2 0x5b12800100703f30  (<unknown module>)
    #3 0x000100703f70 in main main.cpp:23
    #4 0x0001958960dc  (<unknown module>)
    #5 0x4669fffffffffffc  (<unknown module>)

The main changes:

  • We now use Report instead of fprintf to kick off the error message. This puts the ==PID== in the front of the message.
  • We are having a first line be "greppable and semi-structured" in that it is: ==PID==ERROR: RealtimeSanitizer: specific-reason-code - again matching asan.
  • The next line is a human readable reason describing the issue Intercepted call to real-time unsafe function fname in real-time context!
  • Then the stack trace (we have removed the words "Stack trace:"

The current version looks like this, for reference:

Real-time violation: intercepted call to real-time unsafe function `malloc` in real-time context! Stack trace:
    #0 0x6106dc6253c8 in malloc
...

@cjappl
Copy link
Contributor Author

cjappl commented Sep 6, 2024

CC for review @davidtrevelyan

@llvmbot
Copy link
Member

llvmbot commented Sep 6, 2024

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

Author: Chris Apple (cjappl)

Changes

New error messages look like:

==4866==ERROR: RealtimeSanitizer: unsafe-library-call
Intercepted call to real-time unsafe function `malloc` in real-time context!
    #<!-- -->0 0x000100c838c4 in malloc rtsan_interceptors.cpp:310
    #<!-- -->1 0x000195bd7bd0 in operator new(unsigned long)+0x1c (libc++abi.dylib:arm64+0x16bd0)
    #<!-- -->2 0x5b12800100703f30  (&lt;unknown module&gt;)
    #<!-- -->3 0x000100703f70 in main main.cpp:23
    #<!-- -->4 0x0001958960dc  (&lt;unknown module&gt;)
    #<!-- -->5 0x4669fffffffffffc  (&lt;unknown module&gt;)

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

3 Files Affected:

  • (modified) compiler-rt/lib/rtsan/rtsan_context.cpp (+5-4)
  • (modified) compiler-rt/lib/rtsan/tests/rtsan_test_utilities.h (+4-3)
  • (modified) compiler-rt/test/rtsan/basic.cpp (+2-1)
diff --git a/compiler-rt/lib/rtsan/rtsan_context.cpp b/compiler-rt/lib/rtsan/rtsan_context.cpp
index a49b70360babbd..8609394fa222fc 100644
--- a/compiler-rt/lib/rtsan/rtsan_context.cpp
+++ b/compiler-rt/lib/rtsan/rtsan_context.cpp
@@ -95,10 +95,11 @@ void __rtsan::PrintDiagnostics(const char *intercepted_function_name, uptr pc,
                                uptr bp) {
   ScopedErrorReportLock l;
 
-  fprintf(stderr,
-          "Real-time violation: intercepted call to real-time unsafe function "
-          "`%s` in real-time context! Stack trace:\n",
-          intercepted_function_name);
+  Report("ERROR: RealtimeSanitizer: unsafe-library-call\n");
+  Printf("Intercepted call to real-time unsafe function "
+         "`%s` in real-time context!\n",
+         intercepted_function_name);
+
   __rtsan::PrintStackTrace(pc, bp);
 }
 
diff --git a/compiler-rt/lib/rtsan/tests/rtsan_test_utilities.h b/compiler-rt/lib/rtsan/tests/rtsan_test_utilities.h
index 6ca09cf6570940..4ba4fc5e530864 100644
--- a/compiler-rt/lib/rtsan/tests/rtsan_test_utilities.h
+++ b/compiler-rt/lib/rtsan/tests/rtsan_test_utilities.h
@@ -30,9 +30,10 @@ void ExpectRealtimeDeath(Function &&Func,
 
   auto GetExpectedErrorSubstring = [&]() -> std::string {
     return intercepted_method_name != nullptr
-               ? "Real-time violation: intercepted call to real-time unsafe "
-                 "function `" +
-                     std::string(intercepted_method_name) + "`"
+               ? ".*==ERROR: RealtimeSanitizer: unsafe-library-call.*"
+                 "Intercepted call to real-time unsafe function `" +
+                     std::string(intercepted_method_name) +
+                     "` in real-time context!"
                : "";
   };
 
diff --git a/compiler-rt/test/rtsan/basic.cpp b/compiler-rt/test/rtsan/basic.cpp
index c7cbfcda31562e..4edf32336720f8 100644
--- a/compiler-rt/test/rtsan/basic.cpp
+++ b/compiler-rt/test/rtsan/basic.cpp
@@ -16,6 +16,7 @@ void violation() [[clang::nonblocking]] {
 int main() {
   violation();
   return 0;
-  // CHECK: Real-time violation: intercepted call to real-time unsafe function `malloc` in real-time context! Stack trace:
+  // CHECK: ==ERROR: RealtimeSanitizer: unsafe-library-call
+  // CHECK-NEXT: Intercepted call to real-time unsafe function `malloc` in real-time context!
   // CHECK-NEXT: {{.*malloc*}}
 }

@cjappl cjappl force-pushed the better_error_messages branch from 5f38bff to b175e8a Compare September 6, 2024 18:49
@cjappl cjappl force-pushed the better_error_messages branch from b175e8a to 7d45166 Compare September 9, 2024 21:09
Copy link
Contributor

@fmayer fmayer left a comment

Choose a reason for hiding this comment

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

FWIW, lgtm

@cjappl cjappl merged commit 5a2071b into llvm:main Sep 10, 2024
5 of 6 checks passed
@cjappl cjappl deleted the better_error_messages branch September 10, 2024 21:20
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.

4 participants