Skip to content

Commit bbbc681

Browse files
authored
[AArch64] Force dwarf unwind for MTE-tagged stack frames (llvm#168530)
Currently, on Darwin running with -fsanitize=memtag-stack generates compact-unwind exception unwinding that does not untag MTE-tagged memory on the way back up. This patch forces dwarf unwinding on MTE-tagged frames. rdar://162195539
1 parent 535f604 commit bbbc681

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

llvm/lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,11 @@ class DarwinAArch64AsmBackend : public AArch64AsmBackend {
586586
/// Generate the compact unwind encoding from the CFI directives.
587587
uint64_t generateCompactUnwindEncoding(const MCDwarfFrameInfo *FI,
588588
const MCContext *Ctxt) const override {
589+
// MTE-tagged frames must use DWARF unwinding because compact unwind
590+
// doesn't handle MTE tags
591+
if (FI->IsMTETaggedFrame)
592+
return CU::UNWIND_ARM64_MODE_DWARF;
593+
589594
ArrayRef<MCCFIInstruction> Instrs = FI->Instructions;
590595
if (Instrs.empty())
591596
return CU::UNWIND_ARM64_MODE_FRAMELESS;
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
; RUN: llc -mtriple=arm64-apple-macosx -mattr=+mte %s -filetype=obj -o %t.o
2+
; RUN: llvm-objdump --unwind-info %t.o | FileCheck %s
3+
4+
; Frames with MTE stack tagging must use DWARF unwinding because compact unwind
5+
; doesn't handle MTE tag untagging during exception unwinding.
6+
7+
; MTE-tagged frame should use DWARF mode (0x03000000)
8+
; CHECK-LABEL: Contents of __compact_unwind section:
9+
; CHECK: compact encoding: 0x03000000
10+
11+
; Normal frame should NOT use DWARF mode
12+
; CHECK-NOT: compact encoding: 0x03000000
13+
; CHECK: compact encoding: 0x{{[0-9a-f]+}}
14+
15+
define void @mte_tagged_frame() sanitize_memtag "frame-pointer"="all" {
16+
%x = alloca i32, align 4
17+
store i32 42, ptr %x
18+
call void asm sideeffect "", "r"(ptr %x)
19+
ret void
20+
}
21+
22+
define void @normal_frame() "frame-pointer"="all" {
23+
%x = alloca i32, align 4
24+
store i32 42, ptr %x
25+
call void asm sideeffect "", "r"(ptr %x)
26+
ret void
27+
}

0 commit comments

Comments
 (0)