-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[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
c12cf77 to
2b0fe49
Compare
554aaec to
7a94a35
Compare
2b0fe49 to
f2f3e86
Compare
7a94a35 to
61e2f72
Compare
f2f3e86 to
77a0b64
Compare
f32f711 to
2164b39
Compare
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
2164b39 to
503fbba
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
503fbba to
8583399
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you elaborate how the >=10% threshold for the warning was chosen (instead of emiting it in all cases)? Maybe some of these details might also fit in the design doc too , where you talk about inconsistencies.
|
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)
|

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