Skip to content

Commit 43b2e4c

Browse files
committed
[BOLT][PAC] Warn about synchronous unwind tables
BOLT currently ignores functions with synchronous PAuth DWARF info. When more than 10% of functions get ignored for inconsistencies, we should emit a warning to only use asynchronous unwind tables. See also: #165215
1 parent a05ee35 commit 43b2e4c

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

bolt/lib/Passes/PointerAuthCFIAnalyzer.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,17 @@ Error PointerAuthCFIAnalyzer::runOnFunctions(BinaryContext &BC) {
130130
ParallelUtilities::runOnEachFunction(
131131
BC, ParallelUtilities::SchedulingPolicy::SP_INST_LINEAR, WorkFun,
132132
SkipPredicate, "PointerAuthCFIAnalyzer");
133+
134+
float IgnoredPercent = (100.0 * FunctionsIgnored) / Total;
133135
BC.outs() << "BOLT-INFO: PointerAuthCFIAnalyzer ran on " << Total
134136
<< " functions. Ignored " << FunctionsIgnored << " functions "
135-
<< format("(%.2lf%%)", (100.0 * FunctionsIgnored) / Total)
137+
<< format("(%.2lf%%)", IgnoredPercent)
136138
<< " because of CFI inconsistencies\n";
137139

140+
if (IgnoredPercent >= 10.0)
141+
BC.outs() << "BOLT-WARNING: PointerAuthCFIAnalyzer only supports "
142+
"asynchronous unwind tables.\n";
143+
138144
return Error::success();
139145
}
140146

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Test to demonstrate that functions compiled with synchronous unwind tables
2+
// are ignored by the PointerAuthCFIAnalyzer.
3+
// Exception handling is needed to have _any_ unwind tables, otherwise the
4+
// PointerAuthCFIAnalyzer does not run on these functions, so it does not ignore
5+
// any function.
6+
//
7+
// REQUIRES: system-linux,bolt-runtime
8+
//
9+
// RUN: %clangxx --target=aarch64-unknown-linux-gnu \
10+
// RUN: -mbranch-protection=pac-ret \
11+
// RUN: -fno-asynchronous-unwind-tables \
12+
// RUN: %s -o %t.exe -Wl,-q
13+
// RUN: llvm-bolt %t.exe -o %t.bolt | FileCheck %s --check-prefix=CHECK
14+
//
15+
// CHECK: PointerAuthCFIAnalyzer ran on 3 functions. Ignored
16+
// CHECK-NOT: 0 functions (0.00%) because of CFI inconsistencies
17+
// CHECK-SAME: 1 functions (33.33%) because of CFI inconsistencies
18+
// CHECK-NEXT: PointerAuthCFIAnalyzer only supports asynchronous unwind tables
19+
20+
#include <cstdio>
21+
#include <stdexcept>
22+
23+
void foo() { throw std::runtime_error("Exception from foo()."); }
24+
25+
int main() {
26+
try {
27+
foo();
28+
} catch (const std::exception &e) {
29+
printf("Exception caught: %s\n", e.what());
30+
}
31+
return 0;
32+
}

0 commit comments

Comments
 (0)