Skip to content

Commit c2a1481

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 166cb9c commit c2a1481

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

bolt/lib/Passes/PointerAuthCFIAnalyzer.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,18 @@ 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. For C compilers, see "
146+
"-fasynchronous-unwind-tables.\n";
147+
141148
return Error::success();
142149
}
143150

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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: BOLT-WARNING: PointerAuthCFIAnalyzer only supports asynchronous
19+
// CHECK-SAME: unwind tables. For C compilers, see -fasynchronous-unwind-tables.
20+
21+
#include <cstdio>
22+
#include <stdexcept>
23+
24+
void foo() { throw std::runtime_error("Exception from foo()."); }
25+
26+
int main() {
27+
try {
28+
foo();
29+
} catch (const std::exception &e) {
30+
printf("Exception caught: %s\n", e.what());
31+
}
32+
return 0;
33+
}

0 commit comments

Comments
 (0)