From 2371cabb29fbd650b3e059a8c983f35fa5d54442 Mon Sep 17 00:00:00 2001 From: Shauren Date: Thu, 7 May 2026 16:42:01 +0200 Subject: [PATCH] Dep/g3d: Build fix for gcc on windows --- dep/g3dlite/G3D-v9.0 hotfix20.diff | 87 ++++++++++++++++++++++++++++++ dep/g3dlite/Readme.txt | 1 + dep/g3dlite/include/G3D/platform.h | 8 ++- dep/g3dlite/source/GThread.cpp | 11 ++-- dep/g3dlite/source/System.cpp | 5 +- 5 files changed, 105 insertions(+), 7 deletions(-) create mode 100644 dep/g3dlite/G3D-v9.0 hotfix20.diff diff --git a/dep/g3dlite/G3D-v9.0 hotfix20.diff b/dep/g3dlite/G3D-v9.0 hotfix20.diff new file mode 100644 index 0000000000..d8eef3c184 --- /dev/null +++ b/dep/g3dlite/G3D-v9.0 hotfix20.diff @@ -0,0 +1,87 @@ +diff --git a/dep/g3dlite/include/G3D/platform.h b/dep/g3dlite/include/G3D/platform.h +index 9202fe41d0..400a81361e 100644 +--- a/dep/g3dlite/include/G3D/platform.h ++++ b/dep/g3dlite/include/G3D/platform.h +@@ -52,8 +52,10 @@ These control the version of Winsock used by G3D. + + #ifndef _MSC_VER + /// Fast call is a register-based optimized calling convention supported only by Visual C++ ++#ifndef __fastcall + #define __fastcall + #endif ++#endif + + /** \def G3D_WINDOWS*/ + /** \def G3D_FREEBSD2*/ +@@ -64,8 +66,10 @@ These control the version of Winsock used by G3D. + # define G3D_WINDOWS + #elif defined(__MINGW32__) + #define G3D_WINDOWS +- #undef __MSVCRT_VERSION__ +- #define __MSVCRT_VERSION__ 0x0601 ++ #if !defined(__MSVCRT_VERSION__) || __MSVCRT_VERSION__ < 0x0601 ++ #undef __MSVCRT_VERSION__ ++ #define __MSVCRT_VERSION__ 0x0601 ++ #endif + #include + #elif defined(__FreeBSD__) || defined(__OpenBSD__) + #define G3D_FREEBSD +diff --git a/dep/g3dlite/source/GThread.cpp b/dep/g3dlite/source/GThread.cpp +index 5f3f7ffd64..f6483a75d1 100644 +--- a/dep/g3dlite/source/GThread.cpp ++++ b/dep/g3dlite/source/GThread.cpp +@@ -91,6 +91,11 @@ typedef struct tagTHREADNAME_INFO { + } THREADNAME_INFO; + #pragma pack(pop) + ++static LONG ExceptionIgnorer(PEXCEPTION_POINTERS ex) ++{ ++ return ex->ExceptionRecord->ExceptionCode == MS_VC_EXCEPTION ? EXCEPTION_CONTINUE_EXECUTION : EXCEPTION_CONTINUE_SEARCH; ++} ++ + static void SetThreadName(DWORD dwThreadID, const char* threadName) { + THREADNAME_INFO info; + info.dwType = 0x1000; +@@ -98,9 +103,9 @@ static void SetThreadName(DWORD dwThreadID, const char* threadName) { + info.dwThreadID = dwThreadID; + info.dwFlags = 0; + +- __try { +- RaiseException( MS_VC_EXCEPTION, 0, sizeof(info)/sizeof(ULONG_PTR), (ULONG_PTR*)&info ); +- } __except(EXCEPTION_EXECUTE_HANDLER) {} ++ PVOID handler = AddVectoredExceptionHandler(1, &ExceptionIgnorer); ++ RaiseException( MS_VC_EXCEPTION, 0, sizeof(info)/sizeof(ULONG_PTR), (ULONG_PTR*)&info ); ++ RemoveVectoredExceptionHandler(handler); + } + #endif + +diff --git a/dep/g3dlite/source/System.cpp b/dep/g3dlite/source/System.cpp +index d6fbfa7567..213cec86d8 100644 +--- a/dep/g3dlite/source/System.cpp ++++ b/dep/g3dlite/source/System.cpp +@@ -42,6 +42,7 @@ + #ifdef G3D_WINDOWS + + # include ++# include + # include + # include "G3D/RegistryUtil.h" + #include +@@ -1725,7 +1726,7 @@ void System::cpuid(CPUIDFunction func, uint32& eax, uint32& ebx, uint32& ecx, ui + #if ! defined(__PIC__) || defined(__x86_64__) + // AT&T assembler syntax + asm volatile( +- "movl $0, %%ecx \n\n" /* Wipe ecx */ ++ "xor %%ecx, %%ecx \n\n" /* Wipe ecx */ + "cpuid \n\t" + : "=a"(eax), "=b"(ebx), "=c"(ecx), "=d"(edx) + : "a"(func)); +@@ -1733,7 +1734,7 @@ void System::cpuid(CPUIDFunction func, uint32& eax, uint32& ebx, uint32& ecx, ui + // AT&T assembler syntax + asm volatile( + "pushl %%ebx \n\t" /* save ebx */ +- "movl $0, %%ecx \n\n" /* Wipe ecx */ ++ "xor %%ecx, %%ecx \n\n" /* Wipe ecx */ + "cpuid \n\t" + "movl %%ebx, %1 \n\t" /* save what cpuid just put in %ebx */ + "popl %%ebx \n\t" /* restore the old ebx */ diff --git a/dep/g3dlite/Readme.txt b/dep/g3dlite/Readme.txt index 30e86cc8b6..0fa457de60 100644 --- a/dep/g3dlite/Readme.txt +++ b/dep/g3dlite/Readme.txt @@ -29,3 +29,4 @@ G3D-v9.0 hotfix16.diff - 2022-02-11 - Fix *BSD compile errors G3D-v9.0 hotfix17.diff - 2023-03-25 - Fix macOS compile errors G3D-v9.0 hotfix18.diff - 2024-02-17 - ARM64 support on MSVC G3D-v9.0 hotfix19.diff - 2024-06-09 - clang build fix on windows +G3D-v9.0 hotfix20.diff - 2026-05-07 - gcc build fix on windows diff --git a/dep/g3dlite/include/G3D/platform.h b/dep/g3dlite/include/G3D/platform.h index 9202fe41d0..400a81361e 100644 --- a/dep/g3dlite/include/G3D/platform.h +++ b/dep/g3dlite/include/G3D/platform.h @@ -52,8 +52,10 @@ These control the version of Winsock used by G3D. #ifndef _MSC_VER /// Fast call is a register-based optimized calling convention supported only by Visual C++ +#ifndef __fastcall #define __fastcall #endif +#endif /** \def G3D_WINDOWS*/ /** \def G3D_FREEBSD2*/ @@ -64,8 +66,10 @@ These control the version of Winsock used by G3D. # define G3D_WINDOWS #elif defined(__MINGW32__) #define G3D_WINDOWS - #undef __MSVCRT_VERSION__ - #define __MSVCRT_VERSION__ 0x0601 + #if !defined(__MSVCRT_VERSION__) || __MSVCRT_VERSION__ < 0x0601 + #undef __MSVCRT_VERSION__ + #define __MSVCRT_VERSION__ 0x0601 + #endif #include #elif defined(__FreeBSD__) || defined(__OpenBSD__) #define G3D_FREEBSD diff --git a/dep/g3dlite/source/GThread.cpp b/dep/g3dlite/source/GThread.cpp index 5f3f7ffd64..f6483a75d1 100644 --- a/dep/g3dlite/source/GThread.cpp +++ b/dep/g3dlite/source/GThread.cpp @@ -91,6 +91,11 @@ typedef struct tagTHREADNAME_INFO { } THREADNAME_INFO; #pragma pack(pop) +static LONG ExceptionIgnorer(PEXCEPTION_POINTERS ex) +{ + return ex->ExceptionRecord->ExceptionCode == MS_VC_EXCEPTION ? EXCEPTION_CONTINUE_EXECUTION : EXCEPTION_CONTINUE_SEARCH; +} + static void SetThreadName(DWORD dwThreadID, const char* threadName) { THREADNAME_INFO info; info.dwType = 0x1000; @@ -98,9 +103,9 @@ static void SetThreadName(DWORD dwThreadID, const char* threadName) { info.dwThreadID = dwThreadID; info.dwFlags = 0; - __try { - RaiseException( MS_VC_EXCEPTION, 0, sizeof(info)/sizeof(ULONG_PTR), (ULONG_PTR*)&info ); - } __except(EXCEPTION_EXECUTE_HANDLER) {} + PVOID handler = AddVectoredExceptionHandler(1, &ExceptionIgnorer); + RaiseException( MS_VC_EXCEPTION, 0, sizeof(info)/sizeof(ULONG_PTR), (ULONG_PTR*)&info ); + RemoveVectoredExceptionHandler(handler); } #endif diff --git a/dep/g3dlite/source/System.cpp b/dep/g3dlite/source/System.cpp index d6fbfa7567..213cec86d8 100644 --- a/dep/g3dlite/source/System.cpp +++ b/dep/g3dlite/source/System.cpp @@ -42,6 +42,7 @@ #ifdef G3D_WINDOWS # include +# include # include # include "G3D/RegistryUtil.h" #include @@ -1725,7 +1726,7 @@ void System::cpuid(CPUIDFunction func, uint32& eax, uint32& ebx, uint32& ecx, ui #if ! defined(__PIC__) || defined(__x86_64__) // AT&T assembler syntax asm volatile( - "movl $0, %%ecx \n\n" /* Wipe ecx */ + "xor %%ecx, %%ecx \n\n" /* Wipe ecx */ "cpuid \n\t" : "=a"(eax), "=b"(ebx), "=c"(ecx), "=d"(edx) : "a"(func)); @@ -1733,7 +1734,7 @@ void System::cpuid(CPUIDFunction func, uint32& eax, uint32& ebx, uint32& ecx, ui // AT&T assembler syntax asm volatile( "pushl %%ebx \n\t" /* save ebx */ - "movl $0, %%ecx \n\n" /* Wipe ecx */ + "xor %%ecx, %%ecx \n\n" /* Wipe ecx */ "cpuid \n\t" "movl %%ebx, %1 \n\t" /* save what cpuid just put in %ebx */ "popl %%ebx \n\t" /* restore the old ebx */