Index: src/runtime/exception.m ================================================================== --- src/runtime/exception.m +++ src/runtime/exception.m @@ -37,10 +37,11 @@ # include #endif #if defined(__SEH__) # define PERSONALITY gnu_objc_personality +# define CXX_PERSONALITY_STR "__gxx_personality_seh0" #elif defined(__USING_SJLJ_EXCEPTIONS__) # define PERSONALITY __gnu_objc_personality_sj0 # define CXX_PERSONALITY_STR "__gxx_personality_sj0" # define _Unwind_RaiseException _Unwind_SjLj_RaiseException # define __builtin_eh_return_data_regno(i) (i) @@ -235,11 +236,38 @@ uintptr_t thumb = _Unwind_GetGR(ctx, 15) & 1; _Unwind_SetGR(ctx, 15, (value | thumb)); } #endif -#if defined(CXX_PERSONALITY_STR) && !defined(OF_AMIGAOS_M68K) +#if defined(OF_WINDOWS) +# ifdef __SEH__ +static EXCEPTION_DISPOSITION (*cxx_personality)(PEXCEPTION_RECORD, void *, + PCONTEXT, PDISPATCHER_CONTEXT); +# else +static PERSONALITY_FUNC((*cxx_personality)); +# endif + +OF_CONSTRUCTOR() +{ + /* + * This only works if the application uses libc++.dll or + * libstdc++-6.dll. There is unfortunately no other way, as Windows + * does not support proper weak linking. + */ + + HMODULE module; + + module = GetModuleHandle("libc++"); + + if (module == NULL) + module = GetModuleHandle("libstdc++-6"); + + if (module != NULL) + cxx_personality = (__typeof__(cxx_personality)) + GetProcAddress(module, CXX_PERSONALITY_STR); +} +#elif !defined(OF_AMIGAOS_M68K) static PERSONALITY_FUNC(cxx_personality) OF_WEAK_REF(CXX_PERSONALITY_STR); #endif #ifdef __SEH__ extern EXCEPTION_DISPOSITION _GCC_specific_handler(PEXCEPTION_RECORD, void *, @@ -613,11 +641,11 @@ uint8_t found = 0; intptr_t filter = 0; if (foreign) { switch (exClass) { -#if defined(CXX_PERSONALITY_STR) && !defined(OF_AMIGAOS_M68K) +#if !defined(__SEH__) && !defined(OF_AMIGAOS_M68K) case GNUCCXX0_EXCEPTION_CLASS: case CLNGCXX0_EXCEPTION_CLASS: if (cxx_personality != NULL) return CALL_PERSONALITY(cxx_personality); break; @@ -783,34 +811,10 @@ return old; } #ifdef __SEH__ -typedef EXCEPTION_DISPOSITION (*seh_personality_fn)(PEXCEPTION_RECORD, void *, - PCONTEXT, PDISPATCHER_CONTEXT); -static seh_personality_fn __gxx_personality_seh0; - -OF_CONSTRUCTOR() -{ - /* - * This only works if the application uses libc++.dll or - * libstdc++-6.dll. There is unfortunately no other way, as Windows - * does not support proper weak linking. - */ - - HMODULE module; - - module = GetModuleHandle("libc++"); - - if (module == NULL) - module = GetModuleHandle("libstdc++-6"); - - if (module != NULL) - __gxx_personality_seh0 = (seh_personality_fn) - GetProcAddress(module, "__gxx_personality_seh0"); -} - EXCEPTION_DISPOSITION __gnu_objc_personality_seh0(PEXCEPTION_RECORD ms_exc, void *this_frame, PCONTEXT ms_orig_context, PDISPATCHER_CONTEXT ms_disp) { struct _Unwind_Exception *ex = @@ -817,14 +821,14 @@ (struct _Unwind_Exception *)ms_exc->ExceptionInformation[0]; switch (ex->class) { case GNUCCXX0_EXCEPTION_CLASS: case CLNGCXX0_EXCEPTION_CLASS: - if (__gxx_personality_seh0 != NULL) - return __gxx_personality_seh0(ms_exc, this_frame, + if (cxx_personality != NULL) + return cxx_personality(ms_exc, this_frame, ms_orig_context, ms_disp); } return _GCC_specific_handler(ms_exc, this_frame, ms_orig_context, ms_disp, PERSONALITY); } #endif