[llvm] [AArch64] Emit BTI j on EH landing pads () (PR #149680)
Shashi Shankar via llvm-commits
llvm-commits at lists.llvm.org
Sun Jul 20 15:29:42 PDT 2025
https://github.com/shashforge updated https://github.com/llvm/llvm-project/pull/149680
>From baf484901efa1440fa6967801da4bfdd8f52ba63 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>
---
.../Target/AArch64/AArch64BranchTargets.cpp | 2 +-
llvm/test/CodeGen/AArch64/bti-ehpad.ll | 22 +++++++++++++++++++
2 files changed, 23 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..149b89a18b2f9
--- /dev/null
+++ b/llvm/test/CodeGen/AArch64/bti-ehpad.ll
@@ -0,0 +1,22 @@
+; llvm/test/CodeGen/AArch64/bti-ehpad.ll
+; REQUIRES: aarch64-registered-target
+; RUN: llc -mtriple=aarch64-none-linux-gnu -mattr=+bti %s -o - | FileCheck %s
+
+define void @test() #0 personality i8* undef {
+entry:
+ invoke void @may_throw()
+ to label %ret unwind label %lpad
+lpad: ; catch.dispatch
+ landingpad { i8*, i32 }
+ cleanup
+ ret void
+ret:
+ ret void
+}
+
+declare void @may_throw()
+
+; Function needs both the architectural feature *and* the enforcement request.
+attributes #0 = { "branch-target-enforcement"="true" "target-features"="+bti" }
+
+; CHECK: bti j
More information about the llvm-commits
mailing list