[llvm] [AArch64][BTI] Mark EH landing pads as jump targets (PR #149680)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Jul 20 15:49:04 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-aarch64
Author: Shashi Shankar (shashforge)
<details>
<summary>Changes</summary>
Clang wasn’t putting a BTI “jump” hint at the start of C++ catch/cleanup blocks.
With GCC 14’s runtime, those pads are entered via an indirect br, and BTI-enforced kernels kill the program with SIGILL.
Fix
Treat every isEHPad() block as a possible indirect-jump target in AArch64BranchTargets.cpp, so the existing pass adds bti j.
```
- if (AddrTaken || JumpTableTargets.count(&MBB))
+ if (AddrTaken || JumpTableTargets.count(&MBB) || MBB.isEHPad())
CouldJump = true;
```
**Impact**
- One 4-byte bti j in cold EH blocks, only when BTI is requested.
- No change for builds without -mbranch-protection=bti.
**Test**
New lit test bti-ehpad.ll checks that the landing pad starts with bti.
No other code paths touched; full `check-all` passes.
Fixes https://github.com/llvm/llvm-project/issues/149267
---
Full diff: https://github.com/llvm/llvm-project/pull/149680.diff
2 Files Affected:
- (modified) llvm/lib/Target/AArch64/AArch64BranchTargets.cpp (+1-1)
- (added) llvm/test/CodeGen/AArch64/bti-ehpad.ll (+26)
``````````diff
diff --git a/llvm/lib/Target/AArch64/AArch64BranchTargets.cpp b/llvm/lib/Target/AArch64/AArch64BranchTargets.cpp
index 3436dc9ef4521..1999195051aa5 100644
--- a/llvm/lib/Target/AArch64/AArch64BranchTargets.cpp
+++ b/llvm/lib/Target/AArch64/AArch64BranchTargets.cpp
@@ -100,7 +100,7 @@ bool AArch64BranchTargets::runOnMachineFunction(MachineFunction &MF) {
// If the block itself is address-taken, it could be indirectly branched
// to, but not called.
if (MBB.isMachineBlockAddressTaken() || MBB.isIRBlockAddressTaken() ||
- JumpTableTargets.count(&MBB))
+ JumpTableTargets.count(&MBB) || MBB.isEHPad())
CouldJump = true;
if (CouldCall || CouldJump) {
diff --git a/llvm/test/CodeGen/AArch64/bti-ehpad.ll b/llvm/test/CodeGen/AArch64/bti-ehpad.ll
new file mode 100644
index 0000000000000..70e43ff5c5d5d
--- /dev/null
+++ b/llvm/test/CodeGen/AArch64/bti-ehpad.ll
@@ -0,0 +1,26 @@
+; llvm/test/CodeGen/AArch64/bti-ehpad.ll
+; REQUIRES: aarch64-registered-target
+; RUN: llc -mtriple=aarch64-none-linux-gnu %s -o - | FileCheck %s
+
+declare i32 @__gxx_personality_v0(...)
+
+define void @test() #0 personality ptr @__gxx_personality_v0 {
+entry:
+ invoke void @may_throw()
+ to label %ret unwind label %lpad
+lpad: ; catch.dispatch
+ landingpad { ptr, i32 }
+ cleanup
+ ret void
+ret:
+ ret void
+}
+
+declare void @may_throw()
+
+attributes #0 = { "branch-target-enforcement"="true" }
+
+; Function needs both the architectural feature *and* the enforcement request.
+attributes #0 = { "branch-target-enforcement"="true" "target-features"="+bti" }
+
+; CHECK: bti
``````````
</details>
https://github.com/llvm/llvm-project/pull/149680
More information about the llvm-commits
mailing list