From c8ce89ff8956221fce9148237761308b18df315e Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Wed, 12 Jun 2024 13:23:30 +0100 Subject: [PATCH] Fix stack alignment issues with 32 bit MinGW Set incoming and preferred alignment to 4 bytes to match Win32 standard See: #704 --- cmake/CompileFlags.cmake | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cmake/CompileFlags.cmake b/cmake/CompileFlags.cmake index a02a65e162..62358e46fa 100644 --- a/cmake/CompileFlags.cmake +++ b/cmake/CompileFlags.cmake @@ -41,6 +41,11 @@ macro(compile_flags) "$<$:-Wa,-mbig-obj>" # Switch to pe-bigobj-x86-64 as x64 Debug builds push pe-x86-64 to the limits (linking errors with ASLR, ...) ) endif() + if(CMAKE_SIZEOF_VOID_P EQUAL 4) + # Fix MinGW's incorrect assumption that the incoming stack at function calls is 16-byte aligned + # The Win32 API/calling convention only requires and guarantees 4-byte alignment, leading to alignment problems with SSE/AVX/etc + add_compile_options(-mincoming-stack-boundary=2 -mpreferred-stack-boundary=2) + endif() add_compile_options(-Wno-stringop-overflow) # This warning false-positives on some MinGW versions so just turn it off endif()