Skip to content

Commit baf4849

Browse files
committed
[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 <[email protected]>
1 parent 07100c6 commit baf4849

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

llvm/lib/Target/AArch64/AArch64BranchTargets.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ bool AArch64BranchTargets::runOnMachineFunction(MachineFunction &MF) {
100100
// If the block itself is address-taken, it could be indirectly branched
101101
// to, but not called.
102102
if (MBB.isMachineBlockAddressTaken() || MBB.isIRBlockAddressTaken() ||
103-
JumpTableTargets.count(&MBB))
103+
JumpTableTargets.count(&MBB) || MBB.isEHPad())
104104
CouldJump = true;
105105

106106
if (CouldCall || CouldJump) {
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
; llvm/test/CodeGen/AArch64/bti-ehpad.ll
2+
; REQUIRES: aarch64-registered-target
3+
; RUN: llc -mtriple=aarch64-none-linux-gnu -mattr=+bti %s -o - | FileCheck %s
4+
5+
define void @test() #0 personality i8* undef {
6+
entry:
7+
invoke void @may_throw()
8+
to label %ret unwind label %lpad
9+
lpad: ; catch.dispatch
10+
landingpad { i8*, i32 }
11+
cleanup
12+
ret void
13+
ret:
14+
ret void
15+
}
16+
17+
declare void @may_throw()
18+
19+
; Function needs both the architectural feature *and* the enforcement request.
20+
attributes #0 = { "branch-target-enforcement"="true" "target-features"="+bti" }
21+
22+
; CHECK: bti j

0 commit comments

Comments
 (0)