What is difference between sjlj vs dwarf vs seh?

There’s a short overview at MinGW-w64 Wiki:

Why doesn’t mingw-w64 gcc support Dwarf-2 Exception Handling?

The Dwarf-2 EH implementation for Windows is not designed at all to
work under 64-bit Windows applications. In win32 mode, the exception
unwind handler cannot propagate through non-dw2 aware code, this means
that any exception going through any non-dw2 aware “foreign frames”
code will fail, including Windows system DLLs and DLLs built with
Visual Studio. Dwarf-2 unwinding code in gcc inspects the x86
unwinding assembly and is unable to proceed without other dwarf-2
unwind information.

The SetJump LongJump method of exception handling works for most
cases on both win32 and win64, except for general protection faults.
Structured exception handling support in gcc is being developed to
overcome the weaknesses of dw2 and sjlj. On win64, the
unwind-information are placed in xdata-section and there is the .pdata
(function descriptor table) instead of the stack. For win32, the chain
of handlers are on stack and need to be saved/restored by real
executed code.

GCC GNU about Exception Handling:

GCC supports two methods for exception handling (EH):

  • DWARF-2 (DW2) EH, which requires the use of DWARF-2 (or DWARF-3) debugging information. DW-2 EH can cause executables to be
    slightly bloated because large call stack unwinding tables have to be
    included in th executables.
  • A method based on setjmp/longjmp (SJLJ). SJLJ-based EH is much slower than DW2 EH (penalising even normal execution when no
    exceptions are thrown), but can work across code that has not been
    compiled with GCC or that does not have call-stack unwinding
    information.

[…]

Structured Exception Handling (SEH)

Windows uses its own exception handling mechanism known as Structured Exception Handling (SEH). […]
Unfortunately, GCC does not support SEH yet. […]

See also:

  • Exception handling models of GCC
  • C++ Exception Handling for IA-64
  • EH newbies howto

Leave a Comment