-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support cpuid for win32 #8339
Support cpuid for win32 #8339
Conversation
`__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 <pengyu.lv@arm.com>
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 <pengyu.lv@arm.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
library/aesni.c
Outdated
static unsigned info[4] = { 0, 0, 0, 0 }; | ||
#if defined(_MSC_VER) | ||
static int info[4] = { 0, 0, 0, 0 }; | ||
#if defined(_WIN32) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's difference between GCC and MSC. I prefer change ln 36 to #if !defined(_MSC_VER)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might not work when using clang compiler driver under Visual Studio, which is becoming more common.
(When clang is run under Linux, it sets __GNUC__
, but when run as compiler driver under Visual Studio, it sets _MSC_VER
. This definitely causes a problem for inline assembly (since clang format is not the same as MSVC format) - I need to test the intrinsics)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tom-cosgrove-arm , Yes, that might be a problem. Does that mean both macro will be defined in this case ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might not work when using clang compiler driver under Visual Studio, which is becoming more common.
I've tested it, and no related issue. When clang is running in MSVC compatibility mode, it sets _MSC_VER
and provide a compatible intrin.h
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for checking
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 <pengyu.lv@arm.com>
Signed-off-by: Pengyu Lv <pengyu.lv@arm.com>
tests/scripts/all.sh
Outdated
@@ -4626,8 +4626,7 @@ component_test_m32_o0 () { | |||
# build) and not the i386-specific inline assembly. | |||
msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s | |||
scripts/config.py full | |||
scripts/config.py unset MBEDTLS_AESNI_C # AESNI depends on cpu modifiers | |||
make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O0" LDFLAGS="-m32 $ASAN_CFLAGS" | |||
make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O0 -maes -msse2 -mpclmul" LDFLAGS="-m32 $ASAN_CFLAGS" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this change being made?
The comment at line 4625 is explicit: this component is intended to test the portable C code in a 32-bit build
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was trying to revert the workarrounds added in #7384, that's why I removed the previous line 4629, and the additional CFLAGS were just for a successful build.
I have just realize that all AESNI m32 test are in a separate component, so only reverting the work arround in component_build_mingw
should be sufficient?
BTW, I don't quite understand the comments in line 4625 and line 4642. Why different optimization levels make a difference on using or not using i386-specific inline assembly?
At the moment, 3.5.0 compilation fails on 32-bit x86 for both clang and gcc, on Linux. Not sure if this is related in any way to this issue, but I will try to have a closer look next week. Error is the same on both gcc/clang:
|
AESNI for x86 (32-bit) have been tested in a seperate component, we don't need to test twice. Signed-off-by: Pengyu Lv <pengyu.lv@arm.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
|
||
# note Make tests only builds the tests, but doesn't run them | ||
make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror' WINDOWS_BUILD=1 tests | ||
make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -maes -msse2 -mpclmul' WINDOWS_BUILD=1 tests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change should be replace with Pragma or function attribute in future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Please verify the VS compiler driver case raised by @tom-cosgrove-arm. I guess this change can cover the case
@@ -5114,16 +5114,15 @@ component_test_tls13_only_record_size_limit () { | |||
|
|||
component_build_mingw () { | |||
msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s | |||
scripts/config.py unset MBEDTLS_AESNI_C # AESNI depends on cpu modifiers | |||
make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra' WINDOWS_BUILD=1 lib programs | |||
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 programs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to make lib
without MBEDTLS_AESNI_C
to check that it works on mingw?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean to test the build of pure C impl of AES? I think they have been covered because MBEDTLS_AES_USE_HARDWARE_ONLY
is unset in defaul config.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but I mean to check that the C code builds under mingw, which is quite a "strange" environment - just lib
, not programs
, which shouldn't take long
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I didn't get the point. We do build lib
and programs
and later tests
for both static and dynamic linked libraries in this mingw
test...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So with this PR, under mingw we are now building only with MBEDTLS_AESNI_C
set, and not without it? So we are no longer checking that we build correctly under mingw without MBEDTLS_AESNI_C
. If that's right, I think we should add a build of lib
on its own without MBEDTLS_AESNI_C
Signed-off-by: Pengyu Lv <pengyu.lv@arm.com>
3a26529
to
bb4f63c
Compare
tests/scripts/all.sh
Outdated
msg "build: Windows cross build - mingw64, make (Link Library, 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 programs | ||
make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror' WINDOWS_BUILD=1 tests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the config without MBEDTLS_AESNI_C
we only need to make lib
- we don't need to build programs
or tests
. The main reason for doing this is to ensure that the strange mingw environment (not quite *nix, not quite Windows) doesn't cause something related to AES-NI to get mis-compiled in. Outside of the aes*.c
modules this is very unlikely, and will add unnecessary time to CI runs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do not need to test DLL
either, I think?
Also: do we need a ChangeLog entry for this? |
Signed-off-by: Pengyu Lv <pengyu.lv@arm.com>
Signed-off-by: Pengyu Lv <pengyu.lv@arm.com>
ChangeLog.d/fix-mingw32-build.txt
Outdated
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(minor) We normally says "Fixes #nnnn and #nnn2"
$ fgrep 'Fixes #' ChangeLog | wc -l
184
$ fgrep 'Fix #' ChangeLog | wc -l
9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Can you update the "backport done, or not required" text with "backport not required because ..." at the top, please? |
Signed-off-by: Pengyu Lv <pengyu.lv@arm.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@yuhaoth can you re-review please? Also, do you have bandwidth to look at the backport? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Description
Fix: #8334 and #8332
cpuid.h
andintrin.h
define__cpuid
with different signatures. We includeintrin.h
for WIN32 but we only use the correct signature for MSVC. This cause problem when build WIN32 target with non-MSVC compilers (i.gclang
ori686-w64-mingw32
).PR checklist
Please tick as appropriate and edit the reasons (e.g.: "backport: not needed because this is a new feature")