Search code examples
gccmingw-w64

Obtaining current GCC exception model


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?


Solution

  • 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