Skip to content

Commit 9059903

Browse files
committed
[ubsan] support print_module_map flag in standalone mode
Currently, `print_module_map` is only respected for ubsan if it is ran in tandem with asan. This patch adds support for this flag in standalone mode. I copied the pattern used to implement this for asan. Also added a common `print_module_map` lit test for Darwin only. Since the print messages are different per platform, we need to write a regex test to cover them. This test is coming in a separate patch rdar://56135732 Reviewed By: vitalybuka, vsk, delcypher Differential Revision: https://reviews.llvm.org/D97746
1 parent 1540646 commit 9059903

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

compiler-rt/lib/ubsan/ubsan_diag.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,10 @@ ScopedReport::ScopedReport(ReportOptions Opts, Location SummaryLoc,
388388
ScopedReport::~ScopedReport() {
389389
MaybePrintStackTrace(Opts.pc, Opts.bp);
390390
MaybeReportErrorSummary(SummaryLoc, Type);
391+
392+
if (common_flags()->print_module_map >= 2)
393+
DumpProcessMap();
394+
391395
if (flags()->halt_on_error)
392396
Die();
393397
}

compiler-rt/lib/ubsan/ubsan_init.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ static void CommonInit() {
3333
InitializeSuppressions();
3434
}
3535

36+
static void UbsanDie() {
37+
if (common_flags()->print_module_map >= 1)
38+
DumpProcessMap();
39+
}
40+
3641
static void CommonStandaloneInit() {
3742
SanitizerToolName = GetSanititizerToolName();
3843
CacheBinaryName();
@@ -42,6 +47,10 @@ static void CommonStandaloneInit() {
4247
AndroidLogInit();
4348
InitializeCoverage(common_flags()->coverage, common_flags()->coverage_dir);
4449
CommonInit();
50+
51+
// Only add die callback when running in standalone mode to avoid printing
52+
// the same information from multiple sanitizers' output
53+
AddDieCallback(UbsanDie);
4554
Symbolizer::LateInitialize();
4655
}
4756

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Checks that module map does not print at 0, prints once after aborting with 1,
2+
// and prints once before and after aborting with 2
3+
4+
// RUN: %clangxx -DUSING_%tool_name %s -o %t -w
5+
6+
// RUN: %env_tool_opts="print_module_map=0" not %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK,CHECK-MM0
7+
// RUN: %env_tool_opts="print_module_map=1" not %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK,CHECK-MM1
8+
// RUN: %env_tool_opts="print_module_map=2" not %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK,CHECK-MM2
9+
10+
// tsan support pending rdar://67747473
11+
// XFAIL: tsan
12+
13+
// FIXME: Add linux support.
14+
// XFAIL: msan && linux
15+
16+
// FIXME: Add lsan support.
17+
// XFAIL: lsan
18+
19+
int global;
20+
21+
int main() {
22+
#if defined(USING_ubsan)
23+
int value = 5;
24+
int computation = value / 0; // Division by zero.
25+
#else
26+
volatile int *a = new int[100];
27+
delete[] a;
28+
global = a[0]; // use-after-free: triggers ASan/TSan report.
29+
#endif
30+
return 0;
31+
}
32+
33+
// CHECK: SUMMARY:
34+
// CHECK-MM0-NOT: Process module map:
35+
// CHECK-MM1-NOT: Process module map:
36+
// CHECK-MM2: Process module map:
37+
// CHECK: ABORTING
38+
// CHECK-MM0-NOT: Process module map:
39+
// CHECK-MM1-NEXT: Process module map:
40+
// CHECK-MM2-NEXT: Process module map:

0 commit comments

Comments
 (0)