Hi! The following patch fixes a bug in SEH exception handling that made it crash with ObjC (and most likely other languages as well). The problem is that the SEH exception handler always passes the unwind exception as 4th parameter to RtlUnwindEx, which RtlUnwindEx then later passes to the landing pad as argument. This works for C++, as libstdc++ sets data register 0 to the unwind exception anyway, but it crashes for ObjC as the landing pad expects the thrown object to be in data register 0. The solution is of course to fix the SEH wrapper to get the value that was set for data register 0 using _Unwind_SetGR and pass that to RtlUnwindEx, so that later on the correct value is passed to the landing pad.
The patch was tested for C++ and ObjC, the latter with both, the GNU libobjc runtime and my own. (With -O0, it still crashed and complained about invalid frames, but that is another issue.) I don't think this patch needs transfer of copyright, as it is small enoguh, so would it be possible to please include that in GCC 4.8.3? This would finally make ObjC usable on Windows again - and most likely other languages using exceptions as well. Thanks! PS: Please CC me as I'm not on the list! -- Jonathan
--- libgcc/unwind-seh.c.orig 2014-02-15 17:01:59.012396423 +0100 +++ libgcc/unwind-seh.c 2014-02-15 17:03:54.064755427 +0100 @@ -313,8 +313,9 @@ ms_exc->ExceptionInformation[3] = gcc_context.reg[1]; /* Begin phase 2. Perform the unwinding. */ - RtlUnwindEx (this_frame, gcc_context.ra, ms_exc, gcc_exc, - ms_orig_context, ms_disp->HistoryTable); + RtlUnwindEx (this_frame, gcc_context.ra, ms_exc, + (PVOID)gcc_context.reg[0], ms_orig_context, + ms_disp->HistoryTable); } /* In _Unwind_RaiseException we return _URC_FATAL_PHASE1_ERROR. */