Skip to content

Commit 7c3b67d

Browse files
authored
[hwasan] Respect strip_path_prefix printing locals (#76132)
1 parent 38eea57 commit 7c3b67d

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

compiler-rt/lib/hwasan/hwasan_report.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ static void PrintStackAllocations(const StackAllocationsRingBuffer *sa,
205205
tag_t addr_tag, uptr untagged_addr) {
206206
uptr frames = Min((uptr)flags()->stack_history_size, sa->size());
207207
bool found_local = false;
208+
InternalScopedString location;
208209
for (uptr i = 0; i < frames; i++) {
209210
const uptr *record_addr = &(*sa)[i];
210211
uptr record = *record_addr;
@@ -236,8 +237,13 @@ static void PrintStackAllocations(const StackAllocationsRingBuffer *sa,
236237
Printf("\nPotentially referenced stack objects:\n");
237238
found_local = true;
238239
}
239-
Printf(" %s in %s %s:%d\n", local.name, local.function_name,
240-
local.decl_file, local.decl_line);
240+
StackTracePrinter::GetOrInit()->RenderSourceLocation(
241+
&location, local.decl_file, local.decl_line, /* column= */ 0,
242+
common_flags()->symbolize_vs_style,
243+
common_flags()->strip_path_prefix);
244+
Printf(" %s in %s %s\n", local.name, local.function_name,
245+
location.data());
246+
location.clear();
241247
}
242248
frame.Clear();
243249
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// RUN: %clang_hwasan -O0 %s -o %t && %env_hwasan_opts=strip_path_prefix='"%S/"' not %run %t 2>&1 | FileCheck %s
2+
3+
// Stack histories currently are not recorded on x86.
4+
// XFAIL: target=x86_64{{.*}}
5+
6+
#include <assert.h>
7+
#include <sanitizer/hwasan_interface.h>
8+
#include <stdio.h>
9+
10+
int t;
11+
12+
__attribute__((noinline)) char *buggy() {
13+
char *volatile p;
14+
char zzz = {};
15+
char yyy = {};
16+
p = t ? &yyy : &zzz;
17+
return p;
18+
}
19+
20+
int main() {
21+
char *p = buggy();
22+
return *p;
23+
// CHECK: READ of size 1 at
24+
// CHECK: #0 {{.*}} in main strip_path_prefix.c:[[@LINE-2]]
25+
// CHECK: Potentially referenced stack objects:
26+
// CHECK: zzz in buggy strip_path_prefix.c:[[@LINE-12]]
27+
}

0 commit comments

Comments
 (0)