-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[BOLT][PAC] Warn about synchronous unwind tables #165227
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
base: users/bgergely0/bolt-rename-pac-cfi-passes
Are you sure you want to change the base?
[BOLT][PAC] Warn about synchronous unwind tables #165227
Conversation
|
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
This stack of pull requests is managed by Graphite. Learn more about stacking. |
|
@llvm/pr-subscribers-bolt Author: Gergely Bálint (bgergely0) ChangesBOLT currently ignores functions with synchronous PAuth DWARF info. See also: #165215 Full diff: https://github.com/llvm/llvm-project/pull/165227.diff 2 Files Affected:
diff --git a/bolt/lib/Passes/PointerAuthCFIAnalyzer.cpp b/bolt/lib/Passes/PointerAuthCFIAnalyzer.cpp
index 2fc5a2fda086a..6bcb5a6bd1801 100644
--- a/bolt/lib/Passes/PointerAuthCFIAnalyzer.cpp
+++ b/bolt/lib/Passes/PointerAuthCFIAnalyzer.cpp
@@ -130,11 +130,17 @@ Error PointerAuthCFIAnalyzer::runOnFunctions(BinaryContext &BC) {
ParallelUtilities::runOnEachFunction(
BC, ParallelUtilities::SchedulingPolicy::SP_INST_LINEAR, WorkFun,
SkipPredicate, "PointerAuthCFIAnalyzer");
+
+ float IgnoredPercent = (100.0 * FunctionsIgnored) / Total;
BC.outs() << "BOLT-INFO: PointerAuthCFIAnalyzer ran on " << Total
<< " functions. Ignored " << FunctionsIgnored << " functions "
- << format("(%.2lf%%)", (100.0 * FunctionsIgnored) / Total)
+ << format("(%.2lf%%)", IgnoredPercent)
<< " because of CFI inconsistencies\n";
+ if (IgnoredPercent >= 10.0)
+ BC.outs() << "BOLT-WARNING: PointerAuthCFIAnalyzer only supports "
+ "asynchronous unwind tables.\n";
+
return Error::success();
}
diff --git a/bolt/test/runtime/AArch64/pacret-synchronous-unwind.cpp b/bolt/test/runtime/AArch64/pacret-synchronous-unwind.cpp
new file mode 100644
index 0000000000000..e90882833323d
--- /dev/null
+++ b/bolt/test/runtime/AArch64/pacret-synchronous-unwind.cpp
@@ -0,0 +1,32 @@
+// Test to demonstrate that functions compiled with synchronous unwind tables
+// are ignored by the PointerAuthCFIAnalyzer.
+// Exception handling is needed to have _any_ unwind tables, otherwise the
+// PointerAuthCFIAnalyzer does not run on these functions, so it does not ignore
+// any function.
+//
+// REQUIRES: system-linux,bolt-runtime
+//
+// RUN: %clangxx --target=aarch64-unknown-linux-gnu \
+// RUN: -mbranch-protection=pac-ret \
+// RUN: -fno-asynchronous-unwind-tables \
+// RUN: %s -o %t.exe -Wl,-q
+// RUN: llvm-bolt %t.exe -o %t.bolt | FileCheck %s --check-prefix=CHECK
+//
+// CHECK: PointerAuthCFIAnalyzer ran on 3 functions. Ignored
+// CHECK-NOT: 0 functions (0.00%) because of CFI inconsistencies
+// CHECK-SAME: 1 functions (33.33%) because of CFI inconsistencies
+// CHECK-NEXT: PointerAuthCFIAnalyzer only supports asynchronous unwind tables
+
+#include <cstdio>
+#include <stdexcept>
+
+void foo() { throw std::runtime_error("Exception from foo()."); }
+
+int main() {
+ try {
+ foo();
+ } catch (const std::exception &e) {
+ printf("Exception caught: %s\n", e.what());
+ }
+ return 0;
+}
|
|
Looks like the code formatting bot is broken, but the patch is formatted locally. |
|
As an input binary with sync unwind tables generates many warnings, it made sense to add the verbosity checking in this PR as well. |
a05ee35 to
66365dd
Compare
dd41705 to
bd53804
Compare
66365dd to
e6791c1
Compare
bd53804 to
ae91e45
Compare
e6791c1 to
3d0b614
Compare
45beba7 to
5a72973
Compare
b716be0 to
46d7fee
Compare
5a72973 to
554aaec
Compare
46d7fee to
c12cf77
Compare
|
As the related issue states:
I think the double-digit territory is a good boundary to start emitting this warning. After all, we don't check/don't know if this is the reason for the errors, but the higher the percentage the more likely that this is the issue. Low-percentage issues can be from older compiler versions emitting CFIs incorrectly (as I've seen while testing the work). So the 10% is a "magic constant" and is up for discussion, I think it is a reasonable value to start emitting warnings. |
|
Sounds good. So BOLT doesnt know whether inconsistencies are due to sync/async unwind tables, but instead makes an assumption to help the user? Could you summarise this with a comment in code around the point you emit the warning? Since you are on this, should it handle cases like the below? (we've started seeing these recently)
|
35e6cdd to
291486a
Compare
c08f8ba to
d7dc554
Compare
291486a to
451be48
Compare
|
Added the comment about the 10% threshold, and made sure we don't print anything if the pass did zero work. |
451be48 to
c334a9c
Compare
d1ebe85 to
352b942
Compare
352b942 to
b892645
Compare
1959952 to
73f4bef
Compare
b892645 to
e25002a
Compare
4aa24bf to
867d3ee
Compare
e25002a to
ee00757
Compare
867d3ee to
166cb9c
Compare
ee00757 to
4b220b3
Compare
166cb9c to
1d61245
Compare
93ceb02 to
fff7be1
Compare
1d61245 to
6c3f064
Compare
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
- makes sure we do not divide by zero, to calculate the % of ignored functions.
6c3f064 to
2713157
Compare
fff7be1 to
28b3151
Compare

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