diff --git a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp --- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp +++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp @@ -569,7 +569,10 @@ ArrayRef Instrs = FI->Instructions; if (Instrs.empty()) return CU::UNWIND_ARM64_MODE_FRAMELESS; - if (!isDarwinCanonicalPersonality(FI->Personality) && + // For Darwin, generate DWARF for non-canonical personality, unless + // otherwise specified (via -femit-compact-unwid-non-canonical) + if (FI->Personality && FI->isMachO() && + !isDarwinCanonicalPersonality(FI->Personality) && !Ctxt->emitCompactUnwindNonCanonical()) return CU::UNWIND_ARM64_MODE_DWARF; diff --git a/llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp b/llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp --- a/llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp +++ b/llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp @@ -1116,7 +1116,10 @@ ArrayRef Instrs = FI->Instructions; if (Instrs.empty()) return 0; - if (!isDarwinCanonicalPersonality(FI->Personality) && + // For Darwin, generate DWARF for non-canonical personality, unless otherwise + // specified (via -femit-compact-unwid-non-canonical) + if (FI->Personality && FI->Personality->isMachO() && + !isDarwinCanonicalPersonality(FI->Personality) && !Ctxt->emitCompactUnwindNonCanonical()) return CU::UNWIND_ARM_MODE_DWARF; diff --git a/llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp b/llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp --- a/llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp +++ b/llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp @@ -1331,7 +1331,10 @@ const MCContext *Ctxt) const override { ArrayRef Instrs = FI->Instructions; if (Instrs.empty()) return 0; - if (!isDarwinCanonicalPersonality(FI->Personality) && + // For Darwin, generate DWARF for non-canonical personality, unless + // otherwise specified (via -femit-compact-unwid-non-canonical) + if (FI->Personality && FI->Personality->isMachO() && + !isDarwinCanonicalPersonality(FI->Personality) && !Ctxt->emitCompactUnwindNonCanonical()) return CU::UNWIND_MODE_DWARF; diff --git a/llvm/test/MC/MachO/AArch64/darwin-ARM64-no-personality.s b/llvm/test/MC/MachO/AArch64/darwin-ARM64-no-personality.s new file mode 100644 --- /dev/null +++ b/llvm/test/MC/MachO/AArch64/darwin-ARM64-no-personality.s @@ -0,0 +1,73 @@ +# RUN: llvm-mc -filetype=obj -triple=arm64-apple-macos11.0 %s | llvm-objdump --unwind-info - | FileCheck %s + +# Check that we emit the right encoding for the no-personality case. + +# CHECK: Contents of __compact_unwind section: +# CHECK: Entry at offset {{.+}} +# CHECK: start: {{.+}} ltmp0 +# CHECK: length: {{.+}} +# CHECK: compact encoding: 0x02001000 +# CHECK: Entry at offset {{.+}} +# CHECK: start: {{.+}} __Z3foov +# CHECK: length: {{.+}} +# CHECK: compact encoding: 0x04000000 +# CHECK: Entry at offset {{.+}} +# CHECK: start: {{.+}} _main +# CHECK: length: {{.+}} +# CHECK: compact encoding: 0x04000000 + + + .section __TEXT,__text,regular,pure_instructions + .build_version macos, 11, 0 + .globl __Z3barPi + .p2align 2 +__Z3barPi: + .cfi_startproc + sub sp, sp, #16 + .cfi_def_cfa_offset 16 + str x0, [sp, #8] + add sp, sp, #16 + ret + .cfi_endproc + + .globl __Z3foov + .p2align 2 +__Z3foov: + .cfi_startproc + + sub sp, sp, #32 + .cfi_def_cfa_offset 32 + stp x29, x30, [sp, #16] + add x29, sp, #16 + .cfi_def_cfa w29, 16 + .cfi_offset w30, -8 + .cfi_offset w29, -16 + sub x0, x29, #4 + bl __Z3barPi + ldp x29, x30, [sp, #16] + add sp, sp, #32 + ret + .cfi_endproc + + .globl _main + .p2align 2 +_main: + .cfi_startproc + sub sp, sp, #32 + .cfi_def_cfa_offset 32 + stp x29, x30, [sp, #16] + add x29, sp, #16 + .cfi_def_cfa w29, 16 + .cfi_offset w30, -8 + .cfi_offset w29, -16 + mov w8, #0 + str w8, [sp, #8] + stur wzr, [x29, #-4] + bl __Z3foov + ldr w0, [sp, #8] + ldp x29, x30, [sp, #16] + add sp, sp, #32 + ret + .cfi_endproc + +.subsections_via_symbols diff --git a/llvm/test/MC/MachO/darwin-x86_64-no-personality.s b/llvm/test/MC/MachO/darwin-x86_64-no-personality.s new file mode 100644 --- /dev/null +++ b/llvm/test/MC/MachO/darwin-x86_64-no-personality.s @@ -0,0 +1,68 @@ +# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin10.0 %s | llvm-objdump --unwind-info - | FileCheck %s + +# Check that we emit the right encoding for the no-personality case. + +# CHECK: Contents of __compact_unwind section: +# CHECK: Entry at offset {{.+}} +# CHECK: start: {{.+}} __Z3barPi +# CHECK: length: {{.+}} +# CHECK: compact encoding: 0x01000000 +# CHECK: Entry at offset {{.+}} +# CHECK: start: {{.+}} __Z3foov +# CHECK: length: {{.+}} +# CHECK: compact encoding: 0x01000000 +# CHECK: Entry at offset {{.+}} +# CHECK: start: {{.+}} _main +# CHECK: length: 0x1c + + .section __TEXT,__text,regular,pure_instructions + .globl __Z3barPi + .p2align 4, 0x90 +__Z3barPi: + .cfi_startproc + pushq %rbp + .cfi_def_cfa_offset 16 + .cfi_offset %rbp, -16 + movq %rsp, %rbp + .cfi_def_cfa_register %rbp + movq %rdi, -8(%rbp) + popq %rbp + retq + .cfi_endproc + + .globl __Z3foov + .p2align 4, 0x90 +__Z3foov: + .cfi_startproc + pushq %rbp + .cfi_def_cfa_offset 16 + .cfi_offset %rbp, -16 + movq %rsp, %rbp + .cfi_def_cfa_register %rbp + subq $16, %rsp + leaq -4(%rbp), %rdi + callq __Z3barPi + addq $16, %rsp + popq %rbp + retq + .cfi_endproc + + .globl _main + .p2align 4, 0x90 +_main: + .cfi_startproc + pushq %rbp + .cfi_def_cfa_offset 16 + .cfi_offset %rbp, -16 + movq %rsp, %rbp + .cfi_def_cfa_register %rbp + subq $16, %rsp + movl $0, -4(%rbp) + callq __Z3foov + xorl %eax, %eax + addq $16, %rsp + popq %rbp + retq + .cfi_endproc + +.subsections_via_symbols