Skip to content

Conversation

@bgergely0
Copy link
Contributor

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

Copy link
Contributor Author

bgergely0 commented Oct 27, 2025

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.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@llvmbot
Copy link
Member

llvmbot commented Oct 27, 2025

@llvm/pr-subscribers-bolt

Author: Gergely Bálint (bgergely0)

Changes

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


Full diff: https://github.com/llvm/llvm-project/pull/165227.diff

2 Files Affected:

  • (modified) bolt/lib/Passes/PointerAuthCFIAnalyzer.cpp (+7-1)
  • (added) bolt/test/runtime/AArch64/pacret-synchronous-unwind.cpp (+32)
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;
+}

@bgergely0
Copy link
Contributor Author

Looks like the code formatting bot is broken, but the patch is formatted locally.

@bgergely0
Copy link
Contributor Author

As an input binary with sync unwind tables generates many warnings, it made sense to add the verbosity checking in this PR as well.

@bgergely0 bgergely0 force-pushed the users/bgergely0/bolt-rename-pac-cfi-passes branch from a05ee35 to 66365dd Compare October 28, 2025 11:52
@bgergely0 bgergely0 force-pushed the users/bgergely0/bolt-warn-on-sync-unw branch from dd41705 to bd53804 Compare October 28, 2025 11:53
@bgergely0 bgergely0 force-pushed the users/bgergely0/bolt-rename-pac-cfi-passes branch from 66365dd to e6791c1 Compare October 28, 2025 12:18
@bgergely0 bgergely0 force-pushed the users/bgergely0/bolt-warn-on-sync-unw branch from bd53804 to ae91e45 Compare October 28, 2025 12:18
@bgergely0 bgergely0 force-pushed the users/bgergely0/bolt-rename-pac-cfi-passes branch from e6791c1 to 3d0b614 Compare October 28, 2025 14:12
@bgergely0 bgergely0 force-pushed the users/bgergely0/bolt-warn-on-sync-unw branch 3 times, most recently from 45beba7 to 5a72973 Compare October 31, 2025 15:18
@bgergely0 bgergely0 force-pushed the users/bgergely0/bolt-rename-pac-cfi-passes branch from b716be0 to 46d7fee Compare October 31, 2025 15:18
@bgergely0 bgergely0 force-pushed the users/bgergely0/bolt-warn-on-sync-unw branch from 5a72973 to 554aaec Compare October 31, 2025 15:28
@bgergely0 bgergely0 force-pushed the users/bgergely0/bolt-rename-pac-cfi-passes branch from 46d7fee to c12cf77 Compare October 31, 2025 15:28
@bgergely0 bgergely0 marked this pull request as draft October 31, 2025 15:36
Copy link
Contributor Author

As the related issue states:

Example: when applying BOLT to llama.cpp, this is seen in the logs: Ignored 1633 functions (99.03%) because of CFI inconsistencies. The huge % of ignored functions makes BOLT useless in such cases.

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.

@paschalis-mpeis
Copy link
Member

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-INFO: MarkRAStates ran on 0 functions. Ignored 0 functions (nan%) because of CFI inconsistencies

@bgergely0 bgergely0 force-pushed the users/bgergely0/bolt-rename-pac-cfi-passes branch from 35e6cdd to 291486a Compare November 10, 2025 13:15
@bgergely0 bgergely0 force-pushed the users/bgergely0/bolt-warn-on-sync-unw branch 2 times, most recently from c08f8ba to d7dc554 Compare November 10, 2025 15:49
@bgergely0 bgergely0 force-pushed the users/bgergely0/bolt-rename-pac-cfi-passes branch from 291486a to 451be48 Compare November 10, 2025 15:49
Copy link
Contributor Author

Added the comment about the 10% threshold, and made sure we don't print anything if the pass did zero work.

@bgergely0 bgergely0 force-pushed the users/bgergely0/bolt-rename-pac-cfi-passes branch from 451be48 to c334a9c Compare November 12, 2025 14:44
@bgergely0 bgergely0 force-pushed the users/bgergely0/bolt-warn-on-sync-unw branch 3 times, most recently from d1ebe85 to 352b942 Compare November 17, 2025 10:15
@bgergely0 bgergely0 force-pushed the users/bgergely0/bolt-warn-on-sync-unw branch from 352b942 to b892645 Compare November 24, 2025 13:51
@bgergely0 bgergely0 force-pushed the users/bgergely0/bolt-rename-pac-cfi-passes branch from 1959952 to 73f4bef Compare November 24, 2025 13:51
@bgergely0 bgergely0 force-pushed the users/bgergely0/bolt-warn-on-sync-unw branch from b892645 to e25002a Compare November 24, 2025 14:13
@bgergely0 bgergely0 force-pushed the users/bgergely0/bolt-rename-pac-cfi-passes branch 2 times, most recently from 4aa24bf to 867d3ee Compare November 24, 2025 14:53
@bgergely0 bgergely0 force-pushed the users/bgergely0/bolt-warn-on-sync-unw branch from e25002a to ee00757 Compare November 24, 2025 14:53
@bgergely0 bgergely0 force-pushed the users/bgergely0/bolt-rename-pac-cfi-passes branch from 867d3ee to 166cb9c Compare November 24, 2025 15:43
@bgergely0 bgergely0 force-pushed the users/bgergely0/bolt-warn-on-sync-unw branch from ee00757 to 4b220b3 Compare November 24, 2025 15:43
@bgergely0 bgergely0 force-pushed the users/bgergely0/bolt-rename-pac-cfi-passes branch from 166cb9c to 1d61245 Compare November 26, 2025 12:30
@bgergely0 bgergely0 force-pushed the users/bgergely0/bolt-warn-on-sync-unw branch 2 times, most recently from 93ceb02 to fff7be1 Compare November 26, 2025 12:37
@bgergely0 bgergely0 force-pushed the users/bgergely0/bolt-rename-pac-cfi-passes branch from 1d61245 to 6c3f064 Compare November 26, 2025 12:37
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.
@bgergely0 bgergely0 force-pushed the users/bgergely0/bolt-rename-pac-cfi-passes branch from 6c3f064 to 2713157 Compare November 26, 2025 13:03
@bgergely0 bgergely0 force-pushed the users/bgergely0/bolt-warn-on-sync-unw branch from fff7be1 to 28b3151 Compare November 26, 2025 13:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants