[llvm] [AArch64] Emit BTI j on EH landing pads () (PR #149680)
Shashi Shankar via llvm-commits
llvm-commits at lists.llvm.org
Sat Jul 19 15:18:20 PDT 2025
https://github.com/shashforge created https://github.com/llvm/llvm-project/pull/149680
Landing pads reached by the unwinder are entered via 'br', so they must start with BTI j when -mbranch-protection requests BTI. Add isEHPad() to the jump-target test.
Size/perf: +4 B per pad only when BTI is enabled.
Test: new CodeGen/AArch64/bti-ehpad.ll.
>From 7a02decd59bcde371bc395889e740a1762d4c0ee Mon Sep 17 00:00:00 2001
From: Shashi Shankar <shashishankar1687 at gmail.com>
Date: Sun, 20 Jul 2025 00:11:28 +0200
Subject: [PATCH] [AArch64] Emit BTI j on EH landing pads ()
Landing pads reached by the unwinder are entered via 'br', so they must
start with BTI j when -mbranch-protection requests BTI. Add isEHPad()
to the jump-target test.
Size/perf: +4 B per pad only when BTI is enabled.
Test: new CodeGen/AArch64/bti-ehpad.ll.
Signed-off-by: Shashi Shankar <shashishankar1687 at gmail.com>
---
.../lib/Target/AArch64/AArch64BranchTargets.cpp | 2 +-
llvm/test/CodeGen/AArch64/bti-ehpad.ll | 17 +++++++++++++++++
2 files changed, 18 insertions(+), 1 deletion(-)
create mode 100644 llvm/test/CodeGen/AArch64/bti-ehpad.ll
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..dda4a54b723d3
--- /dev/null
+++ b/llvm/test/CodeGen/AArch64/bti-ehpad.ll
@@ -0,0 +1,17 @@
+; RUN: llc -mtriple=aarch64-linux-gnu -mbranch-protection=standard %s -o - | FileCheck %s
+
+declare i32 @__gxx_personality_v0(...)
+
+define void @foo() personality ptr @__gxx_personality_v0 {
+entry:
+ invoke void @bar() to label %exit unwind label %lpad
+
+lpad: ; CHECK-LABEL: lpad:
+ landingpad { ptr, i32 } cleanup ; CHECK: bti j
+ resume { ptr null, i32 0 }
+
+exit:
+ ret void
+}
+
+declare void @bar()
More information about the llvm-commits
mailing list