Skip to content

Commit

Permalink
[hwasan] Respect strip_path_prefix printing locals (#76132)
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalybuka committed Dec 22, 2023
1 parent 38eea57 commit 7c3b67d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
10 changes: 8 additions & 2 deletions compiler-rt/lib/hwasan/hwasan_report.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down
27 changes: 27 additions & 0 deletions compiler-rt/test/hwasan/TestCases/strip_path_prefix.c
Original file line number Diff line number Diff line change
@@ -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]]
}

0 comments on commit 7c3b67d

Please sign in to comment.