Skip to content

[NFC][tsan] Move SkipInternalFrames into sanitizer_common #77146

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

Conversation

vitalybuka
Copy link
Collaborator

No description provided.

@llvmbot
Copy link
Member

llvmbot commented Jan 5, 2024

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

Author: Vitaly Buka (vitalybuka)

Changes

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

3 Files Affected:

  • (modified) compiler-rt/lib/sanitizer_common/sanitizer_common.h (+3)
  • (modified) compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_report.cpp (+20)
  • (modified) compiler-rt/lib/tsan/rtl/tsan_report.cpp (+2-15)
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common.h b/compiler-rt/lib/sanitizer_common/sanitizer_common.h
index 6b327a4aa16f0b..7d9d61de8b6175 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_common.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_common.h
@@ -32,6 +32,7 @@ struct AddressInfo;
 struct BufferedStackTrace;
 struct SignalContext;
 struct StackTrace;
+struct SymbolizedStack;
 
 // Constants.
 const uptr kWordSize = SANITIZER_WORDSIZE / 8;
@@ -393,6 +394,8 @@ void ReportErrorSummary(const char *error_type, const AddressInfo &info,
 // Same as above, but obtains AddressInfo by symbolizing top stack trace frame.
 void ReportErrorSummary(const char *error_type, const StackTrace *trace,
                         const char *alt_tool_name = nullptr);
+// Skips frames which we consider internal and not usefull to the users.
+SymbolizedStack *SkipInternalFrames(SymbolizedStack *frames);
 
 void ReportMmapWriteExec(int prot, int mflags);
 
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_report.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_report.cpp
index 3e4417ae3f57e5..ec60dd3e0d6620 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_report.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_report.cpp
@@ -28,6 +28,26 @@
 namespace __sanitizer {
 
 #if !SANITIZER_GO
+
+static bool FrameIsInternal(const SymbolizedStack *frame) {
+  if (!frame)
+    return true;
+  const char *file = frame->info.file;
+  const char *module = frame->info.module;
+  if (file && (internal_strstr(file, "/compiler-rt/lib/")))
+    return true;
+  if (module && (internal_strstr(module, "libclang_rt.")))
+    return true;
+  return false;
+}
+
+SymbolizedStack *SkipInternalFrames(SymbolizedStack *frames) {
+  for (SymbolizedStack *f = frames; f; f = f->next)
+    if (!FrameIsInternal(f))
+      return f;
+  return nullptr;
+}
+
 void ReportErrorSummary(const char *error_type, const AddressInfo &info,
                         const char *alt_tool_name) {
   if (!common_flags()->print_summary) return;
diff --git a/compiler-rt/lib/tsan/rtl/tsan_report.cpp b/compiler-rt/lib/tsan/rtl/tsan_report.cpp
index c6b764bd891752..b1cee7ac8cbf83 100644
--- a/compiler-rt/lib/tsan/rtl/tsan_report.cpp
+++ b/compiler-rt/lib/tsan/rtl/tsan_report.cpp
@@ -273,22 +273,9 @@ static ReportStack *ChooseSummaryStack(const ReportDesc *rep) {
   return 0;
 }
 
-static bool FrameIsInternal(const SymbolizedStack *frame) {
-  if (!frame)
-    return true;
-  const char *file = frame->info.file;
-  const char *module = frame->info.module;
-  if (file && (internal_strstr(file, "/compiler-rt/lib/")))
-    return true;
-  if (module && (internal_strstr(module, "libclang_rt.")))
-    return true;
-  return false;
-}
-
 static SymbolizedStack *SkipTsanInternalFrames(SymbolizedStack *frames) {
-  for (SymbolizedStack *f = frames; f; f = f->next)
-    if (!FrameIsInternal(f))
-      return f;
+  if (SymbolizedStack *f = SkipInternalFrames(frames))
+    return f;
   return frames;  // Fallback to the top frame.
 }
 

Created using spr 1.3.4

[skip ci]
Created using spr 1.3.4
@vitalybuka vitalybuka changed the base branch from users/vitalybuka/spr/main.nfctsan-move-skipinternalframes-into-sanitizer_common to main January 6, 2024 00:19
Created using spr 1.3.4
@vitalybuka vitalybuka merged commit 2652243 into main Jan 6, 2024
@vitalybuka vitalybuka deleted the users/vitalybuka/spr/nfctsan-move-skipinternalframes-into-sanitizer_common branch January 6, 2024 00:53
justinfargnoli pushed a commit to justinfargnoli/llvm-project that referenced this pull request Jan 28, 2024
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.

3 participants