summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVitaly Buka <vitalybuka@google.com>2023-12-21 16:03:06 -0800
committerGitHub <noreply@github.com>2023-12-21 16:03:06 -0800
commit7c3b67d2038cfb48a80299089f6a1308eee1df7f (patch)
tree3993f7a44f81a8aba7c709748262a1dfe45deb37
parent38eea57e69a8a01e38e8dbc38614043a4553acb1 (diff)
[hwasan] Respect strip_path_prefix printing locals (#76132)
-rw-r--r--compiler-rt/lib/hwasan/hwasan_report.cpp10
-rw-r--r--compiler-rt/test/hwasan/TestCases/strip_path_prefix.c27
2 files changed, 35 insertions, 2 deletions
diff --git a/compiler-rt/lib/hwasan/hwasan_report.cpp b/compiler-rt/lib/hwasan/hwasan_report.cpp
index bbe89112e4db..e9dd919d4149 100644
--- a/compiler-rt/lib/hwasan/hwasan_report.cpp
+++ b/compiler-rt/lib/hwasan/hwasan_report.cpp
@@ -205,6 +205,7 @@ static void PrintStackAllocations(const StackAllocationsRingBuffer *sa,
tag_t addr_tag, uptr untagged_addr) {
uptr frames = Min((uptr)flags()->stack_history_size, sa->size());
bool found_local = false;
+ InternalScopedString location;
for (uptr i = 0; i < frames; i++) {
const uptr *record_addr = &(*sa)[i];
uptr record = *record_addr;
@@ -236,8 +237,13 @@ static void PrintStackAllocations(const StackAllocationsRingBuffer *sa,
Printf("\nPotentially referenced stack objects:\n");
found_local = true;
}
- Printf(" %s in %s %s:%d\n", local.name, local.function_name,
- local.decl_file, local.decl_line);
+ StackTracePrinter::GetOrInit()->RenderSourceLocation(
+ &location, local.decl_file, local.decl_line, /* column= */ 0,
+ common_flags()->symbolize_vs_style,
+ common_flags()->strip_path_prefix);
+ Printf(" %s in %s %s\n", local.name, local.function_name,
+ location.data());
+ location.clear();
}
frame.Clear();
}
diff --git a/compiler-rt/test/hwasan/TestCases/strip_path_prefix.c b/compiler-rt/test/hwasan/TestCases/strip_path_prefix.c
new file mode 100644
index 000000000000..5844749a6d97
--- /dev/null
+++ b/compiler-rt/test/hwasan/TestCases/strip_path_prefix.c
@@ -0,0 +1,27 @@
+// RUN: %clang_hwasan -O0 %s -o %t && %env_hwasan_opts=strip_path_prefix='"%S/"' not %run %t 2>&1 | FileCheck %s
+
+// Stack histories currently are not recorded on x86.
+// XFAIL: target=x86_64{{.*}}
+
+#include <assert.h>
+#include <sanitizer/hwasan_interface.h>
+#include <stdio.h>
+
+int t;
+
+__attribute__((noinline)) char *buggy() {
+ char *volatile p;
+ char zzz = {};
+ char yyy = {};
+ p = t ? &yyy : &zzz;
+ return p;
+}
+
+int main() {
+ char *p = buggy();
+ return *p;
+ // CHECK: READ of size 1 at
+ // CHECK: #0 {{.*}} in main strip_path_prefix.c:[[@LINE-2]]
+ // CHECK: Potentially referenced stack objects:
+ // CHECK: zzz in buggy strip_path_prefix.c:[[@LINE-12]]
+}