Skip to content
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

[hwasan] Respect strip_path_prefix printing locals #76132

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]]
}