Issue 179694
Summary -femit-dwarf-unwind=always does not work on macOS arm64/aarch64
Labels new issue
Assignees
Reporter CendioOssman
    The flag `-femit-dwarf-unwind=always` is documented as always emitting DWARF unwinding tables.  This doesn't work in practice for Darwin aarch64 targets, and it behaves more like `-femit-dwarf-unwind=no-compact-unwind`.

This is an issue if the linker then gets the `-no_compact_unwind` flag as there will then be no unwind information at all. At which point exceptions stop working.

(The reason for that linker flag is interoperability with object files produced by gcc, which has issues with compact unwind generation)

The bug is in `MCDwarfFrameEmitter::Emit()` AFAICT. It aborts to early if `SupportsCompactUnwindWithoutEHFrame()` is set, never considering `-femit-dwarf-unwind`.

Suggested fix:

```diff
diff -up cendio-build-llvm-native-macarm-20.1.8/llvm/lib/MC/MCDwarf.cpp.dwarf cendio-build-llvm-native-macarm-20.1.8/llvm/lib/MC/MCDwarf.cpp
--- cendio-build-llvm-native-macarm-20.1.8/llvm/lib/MC/MCDwarf.cpp.dwarf	2026-02-04 16:10:53.226216444 +0100
+++ cendio-build-llvm-native-macarm-20.1.8/llvm/lib/MC/MCDwarf.cpp	2026-02-04 16:11:27.899072994 +0100
@@ -1905,11 +1905,13 @@ void MCDwarfFrameEmitter::Emit(MCObjectS
     }
   }
 
+  bool CanOmitDwarf = MOFI->getOmitDwarfIfHaveCompactUnwind();
+
   // 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;
+  if (!NeedsEHFrameSection && IsEH && CanOmitDwarf) return;
 
   MCSection &Section =
       IsEH ? *const_cast<MCObjectFileInfo *>(MOFI)->getEHFrameSection()
@@ -1919,7 +1921,6 @@ void MCDwarfFrameEmitter::Emit(MCObjectS
   MCSymbol *SectionStart = Context.createTempSymbol();
 Streamer.emitLabel(SectionStart);
 
-  bool CanOmitDwarf = MOFI->getOmitDwarfIfHaveCompactUnwind();
   // Sort the FDEs by their corresponding CIE before we emit them.
   // This isn't technically necessary according to the DWARF standard,
   // but the Android libunwindstack rejects eh_frame sections where
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to