From fb09d61f060d515e47a5e527092c9c92bd4f4346 Mon Sep 17 00:00:00 2001 From: SChernykh <15806605+SChernykh@users.noreply.github.com> Date: Thu, 23 Jul 2026 10:02:01 +0200 Subject: [PATCH] Fix TryAcquireSRWLockShared being implicitly defined and causing UB (cherry picked from commit 342c3a0fd42584385c76743bb165ff6a75584c1e) --- CMakeLists.txt | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 46cc06fbf..04b92c815 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -806,9 +806,8 @@ else() # mingw doesn't support LTO (multiple definition errors at link time) set(USE_LTO_DEFAULT false) set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--stack,10485760") - if(NOT BUILD_64) - add_definitions(-DWINVER=0x0600 -D_WIN32_WINNT=0x0600) - endif() + # TryAcquireSRWLock* requires Windows 7 or later. + add_definitions(-DWINVER=0x0601 -D_WIN32_WINNT=0x0601) endif() set(C_WARNINGS "-Waggregate-return -Wnested-externs -Wold-style-definition -Wstrict-prototypes") set(CXX_WARNINGS "-Wno-reorder -Wno-missing-field-initializers") @@ -911,6 +910,11 @@ else() add_c_flag_if_supported( -Werror=return-type C_SECURITY_FLAGS) add_cxx_flag_if_supported(-Werror=return-type CXX_SECURITY_FLAGS) + # A missing WinAPI prototype (e.g. TryAcquireSRWLock*) must fail the build + if(MINGW) + add_c_flag_if_supported(-Werror=implicit-function-declaration C_SECURITY_FLAGS) + endif() + message(STATUS "Using C security hardening flags: ${C_SECURITY_FLAGS}") message(STATUS "Using C++ security hardening flags: ${CXX_SECURITY_FLAGS}") message(STATUS "Using linker security hardening flags: ${LD_SECURITY_FLAGS}")