关于c ++:sjlj vs dwarf vs seh有什么区别?

What is difference between sjlj vs dwarf vs seh?

我找不到足够的信息来决定应该使用哪个编译器来编译项目。在不同的计算机上有多个程序可以模拟一个过程。在Linux上,我正在使用GCC。一切都很棒。我可以优化代码,它可以快速编译并使用不太多的内存。

我使用MSVC和GCC编译器做自己的基准测试。后来,产生的二进制文件稍快一些(对于每个子体系结构)。尽管编译时间比MSVC多得多。

因此,我决定使用MinGW。但是找不到有关MinGW中异常处理方法及其实现的任何解释。我可以对不同的操作系统和体系结构使用不同的发行版。

注意事项:

  • 编译时间和内存对于我的使用并不重要。唯一重要的是运行时优化。我需要我的程序足够快。慢速编译器是可以接受的。
  • 操作系统:Microsoft Windows XP / 7/8 / Linux
  • 架构:Intel Core i7 / Core2 /和运行XP的非常老的i686:P


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:

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. [...]

也可以看看:

  • GCC的异常处理模型
  • IA-64的C ++异常处理
  • EH新手指南


SJLJ (setjmp/longjmp): – available for 32 bit and 64 bit – not"zero-cost": even if an exception isn’t thrown, it incurs a minor
performance penalty (~15% in exception heavy code) – allows exceptions
to traverse through e.g. windows callbacks

DWARF (DW2, dwarf-2) – available for 32 bit only – no permanent runtime overhead – needs whole call stack to be dwarf-enabled, which
means exceptions cannot be thrown over e.g. Windows system DLLs.

SEH (zero overhead exception) – will be available for 64-bit GCC 4.8.

来源:http://qt-project.org/wiki/MinGW-64-bit