Skip to content

Commit 38698e6

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 38698e6

File tree

2 files changed

+27
-1
lines changed

2 files changed

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

0 commit comments

Comments
 (0)