From 2856e076e6432b997d470cc1fbe6837c189f9fe2 Mon Sep 17 00:00:00 2001 From: Pengyu Lv Date: Tue, 10 Oct 2023 17:56:12 +0800 Subject: [PATCH 1/7] aesni: support cpuid on WIN32 `__cpuid` has two kinds of signatures in different headers depending on the target OS. We make it consistent between the usages ang the included header. Signed-off-by: Pengyu Lv --- library/aesni.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/aesni.c b/library/aesni.c index 866b6cbfbf10..5ea7985f10c4 100644 --- a/library/aesni.c +++ b/library/aesni.c @@ -58,7 +58,7 @@ int mbedtls_aesni_has_support(unsigned int what) if (!done) { #if MBEDTLS_AESNI_HAVE_CODE == 2 static unsigned info[4] = { 0, 0, 0, 0 }; -#if defined(_MSC_VER) +#if defined(_WIN32) __cpuid(info, 1); #else __cpuid(1, info[0], info[1], info[2], info[3]); From 79d7faf03048fcfcf8a4a045d16c45041a9080b0 Mon Sep 17 00:00:00 2001 From: Pengyu Lv Date: Tue, 10 Oct 2023 18:12:43 +0800 Subject: [PATCH 2/7] aesni: declare cpuinfo as int Change the type of array that stores the cpuinfo data to int[4] to match the signature of `__cpuinfo` in `intrin.h` header file. Signed-off-by: Pengyu Lv --- library/aesni.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/aesni.c b/library/aesni.c index 5ea7985f10c4..a0c8c0691f14 100644 --- a/library/aesni.c +++ b/library/aesni.c @@ -57,7 +57,7 @@ int mbedtls_aesni_has_support(unsigned int what) if (!done) { #if MBEDTLS_AESNI_HAVE_CODE == 2 - static unsigned info[4] = { 0, 0, 0, 0 }; + static int info[4] = { 0, 0, 0, 0 }; #if defined(_WIN32) __cpuid(info, 1); #else From f3c6e2ee348d25d4915fb18f2d5d25f0486a53b4 Mon Sep 17 00:00:00 2001 From: Pengyu Lv Date: Wed, 11 Oct 2023 10:36:55 +0800 Subject: [PATCH 3/7] aesni: select `__cpuid` impl based on compiler type MinGW provides both kinds of implementations of `__cpuid`, but since `cpuid.h` is provided by GNUC, so we should choose the implementation by the compiler type instead of OS type. Signed-off-by: Pengyu Lv --- library/aesni.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/library/aesni.c b/library/aesni.c index a0c8c0691f14..77c1f9024be4 100644 --- a/library/aesni.c +++ b/library/aesni.c @@ -39,10 +39,12 @@ #if defined(MBEDTLS_AESNI_HAVE_CODE) #if MBEDTLS_AESNI_HAVE_CODE == 2 -#if !defined(_WIN32) +#if defined(__GNUC__) #include -#else +#elif defined(_MSC_VER) #include +#else +#error "`__cpuid` required by MBEDTLS_AESNI_C is not supported by the compiler" #endif #include #endif @@ -58,7 +60,7 @@ int mbedtls_aesni_has_support(unsigned int what) if (!done) { #if MBEDTLS_AESNI_HAVE_CODE == 2 static int info[4] = { 0, 0, 0, 0 }; -#if defined(_WIN32) +#if defined(_MSC_VER) __cpuid(info, 1); #else __cpuid(1, info[0], info[1], info[2], info[3]); From f24a85fd5eb8fe084f30ba7cce0a0cd3856a5f0c Mon Sep 17 00:00:00 2001 From: Pengyu Lv Date: Thu, 19 Oct 2023 11:39:17 +0800 Subject: [PATCH 4/7] Add a changelog entry Signed-off-by: Pengyu Lv --- ChangeLog.d/fix-mingw32-build.txt | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 ChangeLog.d/fix-mingw32-build.txt diff --git a/ChangeLog.d/fix-mingw32-build.txt b/ChangeLog.d/fix-mingw32-build.txt new file mode 100644 index 000000000000..c657f23e28f3 --- /dev/null +++ b/ChangeLog.d/fix-mingw32-build.txt @@ -0,0 +1,4 @@ +Bugfix + * Fix an inconsistency between implementations and usages of `__cpuid`, + which mainly causes failures when building Windows target using + mingw or clang. Fix #8334 & #8332. From c5d9d2d67eb79c413c5187407e0ec91390f5a1f3 Mon Sep 17 00:00:00 2001 From: Pengyu Lv Date: Thu, 19 Oct 2023 16:50:45 +0800 Subject: [PATCH 5/7] Reword the changelog entry Signed-off-by: Pengyu Lv --- ChangeLog.d/fix-mingw32-build.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ChangeLog.d/fix-mingw32-build.txt b/ChangeLog.d/fix-mingw32-build.txt index c657f23e28f3..feef0a2c517f 100644 --- a/ChangeLog.d/fix-mingw32-build.txt +++ b/ChangeLog.d/fix-mingw32-build.txt @@ -1,4 +1,4 @@ Bugfix * Fix an inconsistency between implementations and usages of `__cpuid`, which mainly causes failures when building Windows target using - mingw or clang. Fix #8334 & #8332. + mingw or clang. Fixes #8334 & #8332. From b2ca03251dd0110db43f707d1e8287b69e32b963 Mon Sep 17 00:00:00 2001 From: Pengyu Lv Date: Thu, 19 Oct 2023 17:17:19 +0800 Subject: [PATCH 6/7] all.sh: build_mingw: test AESNI intrinsics Signed-off-by: Pengyu Lv --- tests/scripts/all.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/scripts/all.sh b/tests/scripts/all.sh index aeaaec9cc3be..5db85044bddc 100755 --- a/tests/scripts/all.sh +++ b/tests/scripts/all.sh @@ -3327,7 +3327,10 @@ component_build_mingw () { make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra' WINDOWS_BUILD=1 SHARED=1 lib programs make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra' WINDOWS_BUILD=1 SHARED=1 tests make WINDOWS_BUILD=1 clean -} + + msg "build: Windows cross build - mingw64, make (Library only, AESNI intrinsics)" # ~ 30s + make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra -maes -msse2 -mpclmul' WINDOWS_BUILD=1 lib + } support_build_mingw() { case $(i686-w64-mingw32-gcc -dumpversion 2>/dev/null) in [0-5]*|"") false;; From e6cbec8ea70e5ded1ab3d6c60c8c4c5062907a40 Mon Sep 17 00:00:00 2001 From: Pengyu Lv Date: Fri, 20 Oct 2023 09:49:01 +0800 Subject: [PATCH 7/7] all.sh: build_mingw: test build default config without MBEDTLS_AESNI_C Signed-off-by: Pengyu Lv --- tests/scripts/all.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/scripts/all.sh b/tests/scripts/all.sh index 5db85044bddc..baf05371f5de 100755 --- a/tests/scripts/all.sh +++ b/tests/scripts/all.sh @@ -3330,6 +3330,12 @@ component_build_mingw () { msg "build: Windows cross build - mingw64, make (Library only, AESNI intrinsics)" # ~ 30s make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra -maes -msse2 -mpclmul' WINDOWS_BUILD=1 lib + make WINDOWS_BUILD=1 clean + + msg "build: Windows cross build - mingw64, make (Library only, default config without MBEDTLS_AESNI_C)" # ~ 30s + ./scripts/config.py unset MBEDTLS_AESNI_C + make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra' WINDOWS_BUILD=1 lib + make WINDOWS_BUILD=1 clean } support_build_mingw() { case $(i686-w64-mingw32-gcc -dumpversion 2>/dev/null) in