This change allows building with compiler exception support enabled (`-DUSE_COMPILER_EXCEPTIONS`) on non-i386 targets.
On i386, `_except_handler3` needs to be available. While we provide it as an import from the msvcrt DLLs, that's not sufficient for modules like kernel32. Making this work would likely require moving `_except_handler3` to `winecrt0`.
In practice, this fixes the build with Clang, although the resulting binaries do not appear to be fully correct yet. Further investigation is needed, likely on the LLVM side.
-- v2: winecrt0: Undefine USE_COMPILER_EXCEPTIONS in exception.c.
From: Jacek Caban jacek@codeweavers.com
This fixes invalid syntax when compiler exceptions are enabled. --- dlls/msvcrt/cpp.c | 2 ++ 1 file changed, 2 insertions(+)
diff --git a/dlls/msvcrt/cpp.c b/dlls/msvcrt/cpp.c index 84959f1a05c..b8242c06e17 100644 --- a/dlls/msvcrt/cpp.c +++ b/dlls/msvcrt/cpp.c @@ -937,6 +937,8 @@ int __cdecl _is_exception_typeof(const type_info *ti, EXCEPTION_POINTERS *ep) } } __EXCEPT_PAGE_FAULT + { + } __ENDTRY
if(ret == -1)
From: Jacek Caban jacek@codeweavers.com
Fixes format warnings when compiler exception support is enabled. --- dlls/rpcrt4/tests/server.c | 2 +- include/rpc.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/dlls/rpcrt4/tests/server.c b/dlls/rpcrt4/tests/server.c index baf00aee744..07926ee9a36 100644 --- a/dlls/rpcrt4/tests/server.c +++ b/dlls/rpcrt4/tests/server.c @@ -2834,7 +2834,7 @@ START_TEST(server) } RpcExcept(TRUE) { - trace("Exception %d\n", RpcExceptionCode()); + trace("Exception %ld\n", RpcExceptionCode()); } RpcEndExcept } diff --git a/include/rpc.h b/include/rpc.h index 2d4323428c4..88bd51e94bf 100644 --- a/include/rpc.h +++ b/include/rpc.h @@ -79,7 +79,7 @@ typedef void* I_RPC_HANDLE; #define RpcTryFinally #define RpcFinally #define RpcEndFinally -#define RpcExceptionCode() 0 +#define RpcExceptionCode() ((ULONG)0) /* #define RpcAbnormalTermination() abort() */
#endif /* USE_COMPILER_EXCEPTIONS */
From: Jacek Caban jacek@codeweavers.com
--- dlls/winecrt0/exception.c | 1 + 1 file changed, 1 insertion(+)
diff --git a/dlls/winecrt0/exception.c b/dlls/winecrt0/exception.c index 58cf91172ac..2698b2339aa 100644 --- a/dlls/winecrt0/exception.c +++ b/dlls/winecrt0/exception.c @@ -18,6 +18,7 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */
+#undef USE_COMPILER_EXCEPTIONS #include <stdarg.h> #include "winternl.h" #include "wine/exception.h"
On Sat May 17 15:02:15 2025 +0000, Jacek Caban wrote:
changed this line in [version 2 of the diff](/wine/wine/-/merge_requests/8067/diffs?diff_id=178779&start_sha=7ee545a0736d23037ee410d30d8e331b357dbd08#2fcc7db613bea0da4ed5d34bbaede944a79ccc77_26_27)
I added `#undef USE_COMPILER_EXCEPTIONS` instead.
On Sat May 17 15:03:12 2025 +0000, Jacek Caban wrote:
I added `#undef USE_COMPILER_EXCEPTIONS` instead.
Thanks. Ultimately we probably want a compiler check instead of having to explicitly pass `-DUSE_COMPILER_EXCEPTIONS`, but let's see how it goes first.
This merge request was approved by Piotr Caban.
On Sat May 17 15:59:50 2025 +0000, Alexandre Julliard wrote:
Thanks. Ultimately we probably want a compiler check instead of having to explicitly pass `-DUSE_COMPILER_EXCEPTIONS`, but let's see how it goes first.
I took a closer look and managed to get it working without requiring LLVM changes. The original issue can be worked around by using `-fasync-exceptions` (which corresponds to `/EHa` in MSVC). This shouldn't be necessary for `__try`/`__except`, so it's an LLVM bug. However, using this flag should be fine for Wine, so we don't need to wait for an upstream fix.
With that workaround, Clang appears to generate reasonable code, but it runs into a Wine-side bug in exception handling: `_exception_code` inside a `__except` block expects the code to be passed in `eax`. The [attached WIP patch](/uploads/2c0482eee91670e21d7d7a533dd302e8/wip.diff) addresses this and gets things working. I still need to do more testing to confirm the approach is correct, so feedback is welcome.
Since we’re closer to a proper solution than I originally thought, I will drop the last commit from this MR. We might as well aim to get it right from the start.