Skip to content

Commit 2b3856e

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 e6791c1 commit 2b3856e

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
@@ -133,11 +133,17 @@ Error PointerAuthCFIAnalyzer::runOnFunctions(BinaryContext &BC) {
133133
ParallelUtilities::runOnEachFunction(
134134
BC, ParallelUtilities::SchedulingPolicy::SP_INST_LINEAR, WorkFun,
135135
SkipPredicate, "PointerAuthCFIAnalyzer");
136+
137+
float IgnoredPercent = (100.0 * FunctionsIgnored) / Total;
136138
BC.outs() << "BOLT-INFO: PointerAuthCFIAnalyzer ran on " << Total
137139
<< " functions. Ignored " << FunctionsIgnored << " functions "
138-
<< format("(%.2lf%%)", (100.0 * FunctionsIgnored) / Total)
140+
<< format("(%.2lf%%)", IgnoredPercent)
139141
<< " because of CFI inconsistencies\n";
140142

143+
if (IgnoredPercent >= 10.0)
144+
BC.outs() << "BOLT-WARNING: PointerAuthCFIAnalyzer only supports "
145+
"asynchronous unwind tables.\n";
146+
141147
return Error::success();
142148
}
143149

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)