Skip to content
Prev 16 / 139 Next

experimental toolchain: C++ exceptions + setjmp, longjmp

One candidate here -- it looks like the way msvcrt's setjmp is called
has changed in the new toolchain. Previously, we had (in setjmp.h):

    #ifdef _WIN64
    #define setjmp(BUF) _setjmp((BUF), mingw_getsp())
    #else
    #define setjmp(BUF) _setjmp3((BUF), NULL)
    #endif

whereas now we have:

    #    ifdef _WIN64
    #     if (__MINGW_GCC_VERSION < 40702)
    #      define setjmp(BUF) _setjmp((BUF), mingw_getsp())
    #     else
    #      define setjmp(BUF) _setjmp((BUF), __builtin_frame_address (0))
    #     endif
    #    else
    #      define setjmp(BUF) _setjmp3((BUF), NULL)
    #    endif

In other words, the previous toolchain attempted to get the stack
pointer with `mingw_getsp()`, while now it's done through
`__builtin_frame_address(0)`.

The definition of `mingw_getsp()` is here:
https://sourceforge.net/p/mingw-w64/mingw-w64/ci/9592360c86d5cc04d7a265fb11e4611f6df33a62/tree/mingw-w64-crt/misc/mingw_getsp.S

The definition for `__builtin_frame_address()` is here (assuming I am
reading the gcc sources properly):
https://github.com/gcc-mirror/gcc/blob/7aea4e7cdcd40d7bd47c64e76325a62191887d1b/gcc/builtins.c#L4528-L4574

And motivation for the change is here:
https://sourceforge.net/p/mingw-w64/mailman/mingw-w64-public/thread/CAEwic4bjMb851Y2T2dUr_ObBVYaiWY0XkgWnDodVUgjibWO-Sw%40mail.gmail.com/#msg29496874

FWIW, in my tests `mingw_getsp()` and `__builtin_frame_address()` do
return different values, so I think this is worth investigating a bit,
and hopefully someone with more expertise than I can weigh in.

Kevin
On Wed, Sep 9, 2015 at 1:25 PM, Kevin Ushey <kevinushey at gmail.com> wrote: