[llvm] bbbc681 - [AArch64] Force dwarf unwind for MTE-tagged stack frames (#168530)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 2 02:34:08 PST 2025
Author: Dan Blackwell
Date: 2025-12-02T10:34:04Z
New Revision: bbbc681463316425e3e511a030a2f932e5999bef
URL: https://github.com/llvm/llvm-project/commit/bbbc681463316425e3e511a030a2f932e5999bef
DIFF: https://github.com/llvm/llvm-project/commit/bbbc681463316425e3e511a030a2f932e5999bef.diff
LOG: [AArch64] Force dwarf unwind for MTE-tagged stack frames (#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
Added:
llvm/test/CodeGen/AArch64/memtag-compact-unwind.ll
Modified:
llvm/lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp
index 7a2b6790f8a5b..1f9694cf98fec 100644
--- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp
+++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp
@@ -586,6 +586,11 @@ class DarwinAArch64AsmBackend : public AArch64AsmBackend {
/// Generate the compact unwind encoding from the CFI directives.
uint64_t generateCompactUnwindEncoding(const MCDwarfFrameInfo *FI,
const MCContext *Ctxt) const override {
+ // MTE-tagged frames must use DWARF unwinding because compact unwind
+ // doesn't handle MTE tags
+ if (FI->IsMTETaggedFrame)
+ return CU::UNWIND_ARM64_MODE_DWARF;
+
ArrayRef<MCCFIInstruction> Instrs = FI->Instructions;
if (Instrs.empty())
return CU::UNWIND_ARM64_MODE_FRAMELESS;
diff --git a/llvm/test/CodeGen/AArch64/memtag-compact-unwind.ll b/llvm/test/CodeGen/AArch64/memtag-compact-unwind.ll
new file mode 100644
index 0000000000000..50cda8d285a42
--- /dev/null
+++ b/llvm/test/CodeGen/AArch64/memtag-compact-unwind.ll
@@ -0,0 +1,27 @@
+; RUN: llc -mtriple=arm64-apple-macosx -mattr=+mte %s -filetype=obj -o %t.o
+; RUN: llvm-objdump --unwind-info %t.o | FileCheck %s
+
+; Frames with MTE stack tagging must use DWARF unwinding because compact unwind
+; doesn't handle MTE tag untagging during exception unwinding.
+
+; MTE-tagged frame should use DWARF mode (0x03000000)
+; CHECK-LABEL: Contents of __compact_unwind section:
+; CHECK: compact encoding: 0x03000000
+
+; Normal frame should NOT use DWARF mode
+; CHECK-NOT: compact encoding: 0x03000000
+; CHECK: compact encoding: 0x{{[0-9a-f]+}}
+
+define void @mte_tagged_frame() sanitize_memtag "frame-pointer"="all" {
+ %x = alloca i32, align 4
+ store i32 42, ptr %x
+ call void asm sideeffect "", "r"(ptr %x)
+ ret void
+}
+
+define void @normal_frame() "frame-pointer"="all" {
+ %x = alloca i32, align 4
+ store i32 42, ptr %x
+ call void asm sideeffect "", "r"(ptr %x)
+ ret void
+}
More information about the llvm-commits
mailing list