diff --git a/Misc/NEWS.d/next/Build/2025-02-20-03-38-46.gh-issue-130213.MO0ZQD.rst b/Misc/NEWS.d/next/Build/2025-02-20-03-38-46.gh-issue-130213.MO0ZQD.rst new file mode 100644 index 00000000000000..7de83eee63d50f --- /dev/null +++ b/Misc/NEWS.d/next/Build/2025-02-20-03-38-46.gh-issue-130213.MO0ZQD.rst @@ -0,0 +1 @@ +Disabled use of Intel SIMD instructions for libhacl when it would cause the build to fail, such as with some older clang versions. diff --git a/configure b/configure index 453b0123ded0a4..5ba42da9571d1a 100755 --- a/configure +++ b/configure @@ -32076,7 +32076,9 @@ esac # Android. # The *mmintrin.h headers are x86-family-specific, so can't be used on WASI. if test "$ac_sys_system" != "Linux-android" -a "$ac_sys_system" != "WASI" || test "$ANDROID_API_LEVEL" -ge 28; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether C compiler accepts -msse -msse2 -msse3 -msse4.1 -msse4.2" >&5 + # Older versions of the mmintrin headers shipped with clang may error if they are + # included without using the corresponding -msse* option. See GH issue #130213. + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether C compiler accepts -msse -msse2 -msse3 -msse4.1 -msse4.2" >&5 printf %s "checking whether C compiler accepts -msse -msse2 -msse3 -msse4.1 -msse4.2... " >&6; } if test ${ax_cv_check_cflags__Werror__msse__msse2__msse3__msse4_1__msse4_2+y} then : @@ -32113,26 +32115,52 @@ if test "x$ax_cv_check_cflags__Werror__msse__msse2__msse3__msse4_1__msse4_2" = x then : LIBHACL_SIMD128_FLAGS="-msse -msse2 -msse3 -msse4.1 -msse4.2" + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if __m128i can be used without -msse*" >&5 +printf %s "checking if __m128i can be used without -msse*... " >&6; } + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include + #include + #include +int +main (void) +{ +__m128i testvar; + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO" +then : + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +printf "%s\n" "yes" >&6; } printf "%s\n" "#define HACL_CAN_COMPILE_SIMD128 1" >>confdefs.h - # macOS universal2 builds *support* the -msse etc flags because they're - # available on x86_64. However, performance of the HACL SIMD128 implementation - # isn't great, so it's disabled on ARM64. - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for HACL* SIMD128 implementation" >&5 + # macOS universal2 builds *support* the -msse etc flags because they're + # available on x86_64. However, performance of the HACL SIMD128 implementation + # isn't great, so it's disabled on ARM64. + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for HACL* SIMD128 implementation" >&5 printf %s "checking for HACL* SIMD128 implementation... " >&6; } - if test "$UNIVERSAL_ARCHS" == "universal2"; then - LIBHACL_SIMD128_OBJS="Modules/_hacl/Hacl_Hash_Blake2s_Simd128_universal2.o" - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: universal2" >&5 + if test "$UNIVERSAL_ARCHS" == "universal2"; then + LIBHACL_SIMD128_OBJS="Modules/_hacl/Hacl_Hash_Blake2s_Simd128_universal2.o" + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: universal2" >&5 printf "%s\n" "universal2" >&6; } - else - LIBHACL_SIMD128_OBJS="Modules/_hacl/Hacl_Hash_Blake2s_Simd128.o" - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: standard" >&5 + else + LIBHACL_SIMD128_OBJS="Modules/_hacl/Hacl_Hash_Blake2s_Simd128.o" + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: standard" >&5 printf "%s\n" "standard" >&6; } - fi + fi + +else case e in #( + e) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } ;; +esac +fi +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext else case e in #( e) : ;; @@ -32151,6 +32179,9 @@ fi # (https://developer.android.com/ndk/guides/abis#86-64), this is safe because we do a # runtime CPUID check. if test "$ac_sys_system" != "Linux-android" -a "$ac_sys_system" != "WASI" || test "$ANDROID_API_LEVEL" -ge 28; then + # Some versions of immintrin.h require -mavx* to provide the __m256i type + # but blake2module.c must not be compiled with those options and may + # include libintvector.h which contains __m256i. See GH issue #130213. { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether C compiler accepts -mavx2" >&5 printf %s "checking whether C compiler accepts -mavx2... " >&6; } if test ${ax_cv_check_cflags__Werror__mavx2+y} @@ -32187,26 +32218,50 @@ printf "%s\n" "$ax_cv_check_cflags__Werror__mavx2" >&6; } if test "x$ax_cv_check_cflags__Werror__mavx2" = xyes then : - LIBHACL_SIMD256_FLAGS="-mavx2" + LIBHACL_SIMD256_FLAGS="-mavx2" + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if __m256i can be used without -mavx2" >&5 +printf %s "checking if __m256i can be used without -mavx2... " >&6; } + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +int +main (void) +{ +__m256i testvar; + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO" +then : + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +printf "%s\n" "yes" >&6; } printf "%s\n" "#define HACL_CAN_COMPILE_SIMD256 1" >>confdefs.h - # macOS universal2 builds *support* the -mavx2 compiler flag because it's - # available on x86_64; but the HACL SIMD256 build then fails because the - # implementation requires symbols that aren't available on ARM64. Use a - # wrapped implementation if we're building for universal2. - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for HACL* SIMD256 implementation" >&5 + # macOS universal2 builds *support* the -mavx2 compiler flag because it's + # available on x86_64; but the HACL SIMD256 build then fails because the + # implementation requires symbols that aren't available on ARM64. Use a + # wrapped implementation if we're building for universal2. + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for HACL* SIMD256 implementation" >&5 printf %s "checking for HACL* SIMD256 implementation... " >&6; } - if test "$UNIVERSAL_ARCHS" == "universal2"; then - LIBHACL_SIMD256_OBJS="Modules/_hacl/Hacl_Hash_Blake2b_Simd256_universal2.o" - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: universal2" >&5 + if test "$UNIVERSAL_ARCHS" == "universal2"; then + LIBHACL_SIMD256_OBJS="Modules/_hacl/Hacl_Hash_Blake2b_Simd256_universal2.o" + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: universal2" >&5 printf "%s\n" "universal2" >&6; } - else - LIBHACL_SIMD256_OBJS="Modules/_hacl/Hacl_Hash_Blake2b_Simd256.o" - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: standard" >&5 + else + LIBHACL_SIMD256_OBJS="Modules/_hacl/Hacl_Hash_Blake2b_Simd256.o" + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: standard" >&5 printf "%s\n" "standard" >&6; } - fi + fi + +else case e in #( + e) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } ;; +esac +fi +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext else case e in #( e) : ;; diff --git a/configure.ac b/configure.ac index 234ae90616af62..b73b910b825586 100644 --- a/configure.ac +++ b/configure.ac @@ -7847,23 +7847,33 @@ AC_SUBST([LIBHACL_CFLAGS]) # The *mmintrin.h headers are x86-family-specific, so can't be used on WASI. if test "$ac_sys_system" != "Linux-android" -a "$ac_sys_system" != "WASI" || test "$ANDROID_API_LEVEL" -ge 28; then dnl This can be extended here to detect e.g. Power8, which HACL* should also support. + # Older versions of the mmintrin headers shipped with clang may error if they are + # included without using the corresponding -msse* option. See GH issue #130213. AX_CHECK_COMPILE_FLAG([-msse -msse2 -msse3 -msse4.1 -msse4.2],[ [LIBHACL_SIMD128_FLAGS="-msse -msse2 -msse3 -msse4.1 -msse4.2"] + AC_MSG_CHECKING([if __m128i can be used without -msse*]) + AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM([#include + #include + #include ], + [__m128i testvar;])], + [AC_MSG_RESULT([yes]) + + AC_DEFINE([HACL_CAN_COMPILE_SIMD128], [1], [HACL* library can compile SIMD128 implementations]) + + # macOS universal2 builds *support* the -msse etc flags because they're + # available on x86_64. However, performance of the HACL SIMD128 implementation + # isn't great, so it's disabled on ARM64. + AC_MSG_CHECKING([for HACL* SIMD128 implementation]) + if test "$UNIVERSAL_ARCHS" == "universal2"; then + [LIBHACL_SIMD128_OBJS="Modules/_hacl/Hacl_Hash_Blake2s_Simd128_universal2.o"] + AC_MSG_RESULT([universal2]) + else + [LIBHACL_SIMD128_OBJS="Modules/_hacl/Hacl_Hash_Blake2s_Simd128.o"] + AC_MSG_RESULT([standard]) + fi - AC_DEFINE([HACL_CAN_COMPILE_SIMD128], [1], [HACL* library can compile SIMD128 implementations]) - - # macOS universal2 builds *support* the -msse etc flags because they're - # available on x86_64. However, performance of the HACL SIMD128 implementation - # isn't great, so it's disabled on ARM64. - AC_MSG_CHECKING([for HACL* SIMD128 implementation]) - if test "$UNIVERSAL_ARCHS" == "universal2"; then - [LIBHACL_SIMD128_OBJS="Modules/_hacl/Hacl_Hash_Blake2s_Simd128_universal2.o"] - AC_MSG_RESULT([universal2]) - else - [LIBHACL_SIMD128_OBJS="Modules/_hacl/Hacl_Hash_Blake2s_Simd128.o"] - AC_MSG_RESULT([standard]) - fi - + ], [AC_MSG_RESULT([no])]) ], [], [-Werror]) fi AC_SUBST([LIBHACL_SIMD128_FLAGS]) @@ -7877,23 +7887,32 @@ AC_SUBST([LIBHACL_SIMD128_OBJS]) # (https://developer.android.com/ndk/guides/abis#86-64), this is safe because we do a # runtime CPUID check. if test "$ac_sys_system" != "Linux-android" -a "$ac_sys_system" != "WASI" || test "$ANDROID_API_LEVEL" -ge 28; then + # Some versions of immintrin.h require -mavx* to provide the __m256i type + # but blake2module.c must not be compiled with those options and may + # include libintvector.h which contains __m256i. See GH issue #130213. AX_CHECK_COMPILE_FLAG([-mavx2],[ - [LIBHACL_SIMD256_FLAGS="-mavx2"] - AC_DEFINE([HACL_CAN_COMPILE_SIMD256], [1], [HACL* library can compile SIMD256 implementations]) - - # macOS universal2 builds *support* the -mavx2 compiler flag because it's - # available on x86_64; but the HACL SIMD256 build then fails because the - # implementation requires symbols that aren't available on ARM64. Use a - # wrapped implementation if we're building for universal2. - AC_MSG_CHECKING([for HACL* SIMD256 implementation]) - if test "$UNIVERSAL_ARCHS" == "universal2"; then - [LIBHACL_SIMD256_OBJS="Modules/_hacl/Hacl_Hash_Blake2b_Simd256_universal2.o"] - AC_MSG_RESULT([universal2]) - else - [LIBHACL_SIMD256_OBJS="Modules/_hacl/Hacl_Hash_Blake2b_Simd256.o"] - AC_MSG_RESULT([standard]) - fi - ], [], [-Werror]) + [LIBHACL_SIMD256_FLAGS="-mavx2"] + AC_MSG_CHECKING([if __m256i can be used without -mavx2]) + AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM([#include ], + [__m256i testvar;])], + [AC_MSG_RESULT([yes]) + AC_DEFINE([HACL_CAN_COMPILE_SIMD256], [1], [HACL* library can compile SIMD256 implementations]) + + # macOS universal2 builds *support* the -mavx2 compiler flag because it's + # available on x86_64; but the HACL SIMD256 build then fails because the + # implementation requires symbols that aren't available on ARM64. Use a + # wrapped implementation if we're building for universal2. + AC_MSG_CHECKING([for HACL* SIMD256 implementation]) + if test "$UNIVERSAL_ARCHS" == "universal2"; then + [LIBHACL_SIMD256_OBJS="Modules/_hacl/Hacl_Hash_Blake2b_Simd256_universal2.o"] + AC_MSG_RESULT([universal2]) + else + [LIBHACL_SIMD256_OBJS="Modules/_hacl/Hacl_Hash_Blake2b_Simd256.o"] + AC_MSG_RESULT([standard]) + fi + ], [AC_MSG_RESULT([no])]) + ], [], [-Werror]) fi AC_SUBST([LIBHACL_SIMD256_FLAGS]) AC_SUBST([LIBHACL_SIMD256_OBJS])