Exception handling: SJLJ, DWARF, and SEH
Some packages like MinGW-builds and TDM-GCC let you choose which exception implementation you want to use. You must ensure you use the same compiler used to build the Qt you use in order to avoid linker errors. If you choose to change the exception handling mechanism, you will need to rebuild all code, mostly because the libgcc shared library name is different between the exception handling settings.
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) but sometimes the penalty can be more significant: [QTBUG-29653] Significant performance regression in Qt 5.0.1 compiled with MinGW - Qt Bug Tracker
- 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.
- rubenvb release is available targetting Win64/Personal Builds/rubenvb/gcc-4.8-release/x86_64-w64-mingw32-gcc-4.8.0-win64_rubenvb.7z/download
- MinGW-builds release is available
From TDM-GCC readme:
"GCC currently supports two methods of stack frame unwinding: Dwarf-2 (DW2) or SJLJ (setjmp/longjmp). Until recently, only SJLJ has been available for the Windows platform. This affects you, the end user, primarily in programs that throw and catch exceptions. Programs which utilize the DW2 unwind method generally execute more quickly than programs which utilize the SJLJ method, because the DW2 method incurs no runtime overhead until an exception is thrown. However, the DW2 method does incur a size penalty on code that must handle exceptions, and more importantly the DW2 method cannot yet unwind (pass exceptions) through "foreign" stack frames: stack frames compiled by another non-DW2-enabled compiler, such as OS DLLs in a Windows callback.
This means that you should in general choose the SJLJ version of the TDM-GCC builds unless you know you need faster exception-aware programs and can be certain you will never throw an exception through a foreign stack area.
As distributed, the SJLJ and DW2 packages of TDM-GCC can coexist peacefully extracted to the same directory (i.e. any files in common are for all intents and purposes identical), because the driver executables (the ones in the "bin" directory) are suffixed with "-dw2" for the DW2 build, and the libraries and other executables hide in another "-dw2" directory in "lib(exec)/gcc/mingw32". This allows you to use the same single addition to your PATH, and use DW2 exceptions only when you need them by calling "gcc-dw2", etc. If you truly want DW2 exceptions as the default when calling "gcc" (from Makefiles or configury systems, for example), you can rename or copy the suffixed executables to their original names."
DW2 Issues
- If a library that uses DW2 exception handling (e.g. libgcc_s_dw2-1.dll) is loaded using LoadLibrary and FreeLibrary is not called, the program will crash. See http://comments.gmane.org/gmane.comp.gnu.mingw.user/41724
- Calling FreeLibrary to unload a dll that links to both dynamic libgcc_s_dw2 and a library that links to static libgcc_s_dw2 results in a crash
GCC Threading model (posix vs win32)
Mingw-Builds (and the experimental rubenvb packages) also let you choose between the threading model internally used by (lib)gcc:
- posix (built upon MinGW-w64's winpthreads)
- "an implementation of POSIX threads for win32 is also available under the experimental directory. Its main goal is to support C+11 standard threading, which supports only using POSIX threads at the moment." Mingw-w64
- enables C11 library features contained in the headers <thread>, <mutex>, and <future>.
- Performance degradation in specific scenarios. C11 functionality is significantly slower than native Win32 implementation or even MSVS2012's implementation.
- win32
- uses native Win32 threading functions.
- no C11 <thread>, <mutex>, or <future>
- best performance
More reading: MinGW - Minimalist GNU for Windows / Re: [Mingw-users] enable std::thread experimental patch
原文链接:
参考文章:
MinGW gcc下载链接及sjlj、dwarf、seh异同以及gcc安装
MinGW-w64各版本—— sjlj seh dwarf 有什么区别?
MinGW下载地址: