C++ sjlj vs dwarf vs seh 有什么区别?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15670169/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 19:37:12  来源:igfitidea点击:

What is difference between sjlj vs dwarf vs seh?

c++compiler-constructionmingwcpu-architecturemingw-w64

提问by sorush-r

I can't find enough information to decide which compiler should I use to compile my project. There are several programs on different computers simulating a process. On Linux, I'm using GCC. Everything is great. I can optimize code, it compiles fast and uses not-so-much memory.

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

I do my own benchmark with MSVC and GCC compilers. Later one produces slightly faster binaries (for each subarchitecture). Though compile time is much more than MSVC.

我用 MSVC 和 GCC 编译器做我自己的基准测试。稍后生成稍微快一点的二进制文件(对于每个子架构)。虽然编译时间比 MSVC 多得多。

So I decided to use MinGW. But can't find any explanation about exception handling methods and their implementations in MinGW. I can use different distributions for different operating systems and architectures.

所以我决定使用MinGW。但是在MinGW中找不到关于异常处理方法及其实现的任何解释。我可以为不同的操作系统和架构使用不同的发行版。

Considerations:

注意事项:

  • Compile time and memory are not important for my usage. Only important thing is runtime optimization. I need my programs to be fast enough. A slow compiler is acceptable.
  • OS: Microsoft Windows XP / 7 / 8 / Linux
  • Architecture: Intel Core i7 / Core2 / and a very old i686 running XP :P
  • 编译时间和内存对我的使用并不重要。唯一重要的是运行时优化。我需要我的程序足够快。缓慢的编译器是可以接受的。
  • 操作系统:Microsoft Windows XP / 7 / 8 / Linux
  • 架构:Intel Core i7 / Core2 / 和运行 XP 的非常旧的 i686 :P

采纳答案by ollo

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

MinGW-w64 Wiki 上有一个简短的概述:

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

The Dwarf-2 EHimplementation 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 LongJumpmethod 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.

为什么 mingw-w64 gcc 不支持 Dwarf-2 异常处理?

适用于 Windows的Dwarf-2 EH实现根本不是为在 64 位 Windows 应用程序下工作而设计的。在 win32 模式下,异常展开处理程序无法通过非 dw2 感知代码传播,这意味着通过任何非 dw2 感知“外部框架”代码的任何异常都将失败,包括 Windows 系统 DLL 和使用 Visual Studio 构建的 DLL。gcc 中的 Dwarf-2 展开代码会检查 x86 展开程序集,并且在没有其他 dwarf-2 展开信息的情况下无法继续。

异常处理的SetJump LongJump方法适用于 win32 和win64 上的大多数情况,一般保护故障除外。正在开发 gcc 中的结构化异常处理支持,以克服 dw2 和 sjlj 的弱点。在 win64 上,展开信息放置在 xdata-section 中,并且有 .pdata(函数描述符表)而不是堆栈。对于 win32,处理程序链在堆栈上,需要由实际执行的代码保存/恢复。

GCC GNUabout Exception Handling:

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 支持两种异常处理 (EH) 方法:

  • DWARF-2 (DW2) EH,需要使用 DWARF-2(或 DWARF-3)调试信息。DW-2 EH 会导致可执行文件略微膨胀,因为必须在可执行文件中包含大型调用堆栈展开表。
  • 一种基于setjmp/longjmp (SJLJ) 的方法。基于 SJLJ 的 EH 比 DW2 EH 慢得多(在没有抛出异常时甚至会影响正常执行),但可以跨未使用 GCC 编译或没有调用堆栈展开信息的代码工作。

[...]

结构化异常处理 (SEH)

Windows 使用自己的异常处理机制,称为结构化异常处理 (SEH)。[...]不幸的是,GCC 还不支持 SEH。[...]

See also:

也可以看看:

回答by ollo

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.

SJLJ(setjmp/longjmp): – 适用于 32 位和 64 位 – 不是“零成本”:即使没有抛出异常,它也会导致轻微的性能损失(在异常繁重的代码中约 15%) – 允许异常遍历例如 Windows 回调

DWARF(DW2, dwarf-2) – 仅适用于 32 位 – 没有永久运行时开销 – 需要整个调用堆栈都启用 dwarf,这意味着不能通过例如 Windows 系统 DLL 抛出异常。

SEH(零开销异常)——将可用于 64 位 GCC 4.8。

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

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