且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

sjlj vs dwarf vs seh 有什么区别?

更新时间:2022-02-15 03:36:52

MinGW-w64 维基:

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

Windows 的 Dwarf-2 EH 实现根本不是为了在 64 位 Windows 应用程序下工作.在win32模式下,异常展开处理程序不能通过非 dw2 感知代码传播,这意味着任何通过任何非 dw2 感知的外部框架"的异常代码将失败,包括 Windows 系统 DLL 和使用构建的 DLL视觉工作室.gcc 中的 Dwarf-2 展开代码检查 x86展开组装,没有其他 dwarf-2 就无法进行放松信息.

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.

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

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

GCC supports two methods for exception handling (EH):

  • DWARF-2 (DW2) EH,需要使用 DWARF-2(或 DWARF-3)调试信息.DW-2 EH 可能导致可执行文件略微臃肿,因为必须是大型调用堆栈展开表包含在可执行文件中.
  • 一种基于setjmp/longjmp (SJLJ)的方法.基于 SJLJ 的 EH 比 DW2 EH 慢得多(即使没有正常执行也会受到惩罚)异常被抛出),但可以跨尚未被抛出的代码工作使用 GCC 编译或没有调用堆栈展开信息.
  • 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.

[...]

结构化异常处理 (SEH)

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

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

另见: