diff --git a/llvm/lib/MC/MCDwarf.cpp b/llvm/lib/MC/MCDwarf.cpp --- a/llvm/lib/MC/MCDwarf.cpp +++ b/llvm/lib/MC/MCDwarf.cpp @@ -1876,7 +1876,11 @@ } } - if (!NeedsEHFrameSection) return; + // Compact unwind information can be emitted in the eh_frame section or the + // debug_frame section. Skip emitting FDEs and CIEs when the compact unwind + // doesn't need an eh_frame section and the emission location is the eh_frame + // section. + if (!NeedsEHFrameSection && IsEH) return; MCSection &Section = IsEH ? *const_cast(MOFI)->getEHFrameSection() @@ -1903,9 +1907,13 @@ const MCDwarfFrameInfo &Frame = *I; ++I; if (CanOmitDwarf && Frame.CompactUnwindEncoding != - MOFI->getCompactUnwindDwarfEHFrameOnly()) - // Don't generate an EH frame if we don't need one. I.e., it's taken care - // of by the compact unwind encoding. + MOFI->getCompactUnwindDwarfEHFrameOnly() && IsEH) + // CIEs and FDEs can be emitted in either the eh_frame section or the + // debug_frame section, on some platforms (e.g. AArch64) the target object + // file supports emitting a compact_unwind section without an associated + // eh_frame section. If the eh_frame section is not needed, and the + // location where the CIEs and FDEs are to be emitted is the eh_frame + // section, do not emit anything. continue; CIEKey Key(Frame); diff --git a/llvm/test/DebugInfo/AArch64/debugframeinfo.s b/llvm/test/DebugInfo/AArch64/debugframeinfo.s new file mode 100644 --- /dev/null +++ b/llvm/test/DebugInfo/AArch64/debugframeinfo.s @@ -0,0 +1,20 @@ +# RUN: llvm-mc -filetype=obj --triple=arm64-apple-darwin22.1.0 %s -o %t.o +# RUN: llvm-dwarfdump -debug-frame %t.o | FileCheck %s + +# CHECK: .debug_frame contents: +# CHECK-EMPTY: +# CHECK-NEXT: {{.+}} + +# CHECK: .eh_frame contents: +# CHECK-EMPTY: +# CHECK-EMPTY: + + .cfi_sections .debug_frame + .cfi_startproc + .cfi_personality 0x9b, g + .cfi_lsda 0x1b, h + .cfi_endproc + .global g +g: + .global h +h: