문제

g++ is built using either the DWARF2, sjlj or seh exception model. MinGW-builds provide various builds of g++ that have different exception models. I would like to be able to determine from the gcc toolchain what exception model is being used. Is there a g++ argument that will dump the default exception model of the compiler?

도움이 되었습니까?

해결책

Edit: Originally, I was testing for the configuration flags that are described in g++ -v. As Jonathon Wakely points out in the comments, this is not a good thing to do.

An inspection way to do it is to compile to assembly:

struct S { ~S(); };
void bar();
void foo() {
  S s;
  bar();
}

The result of g++ -S <filename> -o output.s have the following exception references in them:

MinGW-4.8.1-x86-posix-sjlj:

.def    ___gxx_personality_sj0; .scl    2;  .type   32; .endef
.def    __Unwind_SjLj_Register; .scl    2;  .type   32; .endef
.def    __Unwind_SjLj_Unregister;   .scl    2;  .type   32; .endef
.def    __Unwind_SjLj_Resume;   .scl    2;  .type   32; .endef

MinGW-4.8.1-x86-posix-dwarf:

.def    ___gxx_personality_v0;  .scl    2;  .type   32; .endef
.def    __Unwind_Resume;    .scl    2;  .type   32; .endef

MinGW-4.8.1-x64-win32-sjlj:

.def    __gxx_personality_sj0;  .scl    2;  .type   32; .endef
.def    _Unwind_SjLj_Register;  .scl    2;  .type   32; .endef
.def    _Unwind_SjLj_Unregister;    .scl    2;  .type   32; .endef
.def    _Unwind_SjLj_Resume;    .scl    2;  .type   32; .endef

MinGW-4.8.1-x64-posix-seh:

.def    __gxx_personality_seh0; .scl    2;  .type   32; .endef
.def    _Unwind_Resume; .scl    2;  .type   32; .endef

MinGW-4.8.1-x64-posix-sjlj:

.def    __gxx_personality_sj0;  .scl    2;  .type   32; .endef
.def    _Unwind_SjLj_Register;  .scl    2;  .type   32; .endef
.def    _Unwind_SjLj_Unregister;    .scl    2;  .type   32; .endef
.def    _Unwind_SjLj_Resume;    .scl    2;  .type   32; .endef

FC17-g++-4.7.2-x64:

.cfi_personality 0x3,__gxx_personality_v0
.globl  __gxx_personality_v0
call    _Unwind_Resume

Looks like we should search for __gxx_personality_([a-z])(0-9]+) and then compare the first capture group to:

  • v = dwarf
  • seh = seh
  • sj = sjlj

다른 팁

Just to complement the answers above, GCC has a predefined macro allowing to recognize at compile time whether SJLJ exception model is used:

__USING_SJLJ_EXCEPTIONS__

This macro is defined, with value 1, if the compiler uses the old mechanism based on setjmp and longjmp for exception handling.

See https://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html

According to documentation, it is available since at least version 3.1.1; I have just tested it on GCC 7.1 (under MinGW-w64).

For me, finding corresponding DLL for each exception model works:
libgcc_s_dw2-1.dll (DWARF)
libgcc_s_seh-1.dll (SEH)
libgcc_s_sjlj-1.dll (SJLJ)
Reference: https://stackoverflow.com/a/19791995/16550663

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top