Hi, found several issues on MinGW target. Patch is attached.
Build with OpenMP results in link time error, since gcc requires -fopenmp on link time but it is not set. This can be fixed by setting target LINK_FLAGS property to $OpenMP_C_FLAGS, but I don't know if it's appropriate for other compilers/linkers than GNU C. It seems at least OK for MSVC (Although MSVC linker doesn't need -openmp switch, it's just gracefully ignored with a warning).
Found several ABI weakness on MinGW DLL. At first, GNUC assumes 16byte stack frame alignment by dafault, but it's not assured by x86 ABI, and MSVC doesn't align stack frames as such. As a result, calling SIMD enabled function in MinGW DLL from MSVC program results in segfaults, due to stack frame misalignment. This can be avoided by setting -mincoming-stack-boundary=2.
Hmm, setting -mincomming-stack-boundary=2 on x86_64 target seems to result in compile error.
More finer condition is required by investigating target arch (we only need it for 32bit x86 target).
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello and thanks for these suggestions. For the first issue, please can you let me know if the following patch works for you?
diff --git a/cmake/Modules/FindSIMD.cmake b/cmake/Modules/FindSIMD.cmake
index 6484bbd..6ac51cb 100644
--- a/cmake/Modules/FindSIMD.cmake
+++ b/cmake/Modules/FindSIMD.cmake
@@ -40,12 +40,18 @@
include (CheckCSourceCompiles)
include (FindPackageHandleStandardArgs)
+if (WIN32) # Safety for when mixed lib/app compilers (but performance hit)
+ set (GCC_WIN32_SIMD_OPTS "-mincoming-stack-boundary=2")
+endif ()
+
set (SIMD_C_FLAG_CANDIDATES
- # Microsoft Visual Studio x64
+ # x64
" "
# Microsoft Visual Studio x86
"/arch:SSE /fp:fast -DSSE"
- # Gnu
+ # Gcc x86
+ "-msse -mfpmath=sse ${GCC_WIN32_SIMD_OPTS}"
+ # Gcc x86 (old versions)
"-msse -mfpmath=sse"
)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks, it works fine here.
And sorry for patch formatting. Since all whitespaces at line beginning are stripped off, copy & paste doesn't seem to work.
One more thing. On i686-w64-mingw target, __divdi3() is imported from libgcc.
Requiring extra libgcc DLL for merely one function looks somewhat wasteful.
Is it possible to set -static-libgcc for MinGW target?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi, found several issues on MinGW target. Patch is attached.
The following is the patch I tried.
Hmm, setting -mincomming-stack-boundary=2 on x86_64 target seems to result in compile error.
More finer condition is required by investigating target arch (we only need it for 32bit x86 target).
Updated patch.
Hello and thanks for these suggestions. For the first issue, please can you let me know if the following patch works for you?
diff --git a/cmake/Modules/FindSIMD.cmake b/cmake/Modules/FindSIMD.cmake
index 6484bbd..6ac51cb 100644
--- a/cmake/Modules/FindSIMD.cmake
+++ b/cmake/Modules/FindSIMD.cmake
@@ -40,12 +40,18 @@
include (CheckCSourceCompiles)
include (FindPackageHandleStandardArgs)
+if (WIN32) # Safety for when mixed lib/app compilers (but performance hit)
+ set (GCC_WIN32_SIMD_OPTS "-mincoming-stack-boundary=2")
+endif ()
+
set (SIMD_C_FLAG_CANDIDATES
- # Microsoft Visual Studio x64
+ # x64
" "
# Microsoft Visual Studio x86
"/arch:SSE /fp:fast -DSSE"
- # Gnu
+ # Gcc x86
+ "-msse -mfpmath=sse ${GCC_WIN32_SIMD_OPTS}"
+ # Gcc x86 (old versions)
"-msse -mfpmath=sse"
)
and maybe this for the second issue:
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8a24952..7bfcd97 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -79,6 +79,9 @@ endif ()
if (OPENMP_FOUND)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
+ if (MINGW)
+ set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${OpenMP_C_FLAGS}")
+ endif ()
endif ()
if (WITH_SIMD)
Thanks, it works fine here.
And sorry for patch formatting. Since all whitespaces at line beginning are stripped off, copy & paste doesn't seem to work.
One more thing. On i686-w64-mingw target, __divdi3() is imported from libgcc.
Requiring extra libgcc DLL for merely one function looks somewhat wasteful.
Is it possible to set -static-libgcc for MinGW target?