[UCRT] Fix GCC/Clang SIMD compilation

GCC and Clang need to mark functions that use SSE/AVX etc, either with a function attribute or a pragma around the function. strlen uses a template function that either uses SSE2 or AVX2. Previously the template was surrounded with pragmas to allow both SSE2 and AVX2, but that makes GCC assume that it can use AVX2 instructions even in the SSE2 version. To fix this the template instances are now build in individual compilation units for SSE2 and AVX, separate from the "dispatcher" function.
Now ucrtbase doesn't crash anymore on GCC build.

Another issue was the namespace around strnlen_mode, which has confused clang so much, that it forgot to instantiate the template code.
This commit is contained in:
Timo Kreuzer 2025-07-22 20:17:46 +03:00
parent e2deec8235
commit 719ea022ec
5 changed files with 92 additions and 10 deletions

View file

@ -57,6 +57,17 @@ list(APPEND UCRT_STRING_SOURCES
string/wmemmove_s.cpp
)
# Special handling for GCC and Clang
if(CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID STREQUAL "Clang")
list(APPEND UCRT_STRING_SOURCES
string/strnlen-avx2.cpp
string/strnlen-sse2.cpp
)
set_source_files_properties(string/strnlen-sse2.cpp PROPERTIES COMPILE_OPTIONS "-msse2")
set_source_files_properties(string/strnlen-avx2.cpp PROPERTIES COMPILE_OPTIONS "-mavx2")
endif()
if(${ARCH} STREQUAL "i386")
list(APPEND UCRT_STRING_ASM_SOURCES
string/i386/_memicmp.s