Skip to content
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

Add msvc support for AESCE #7316

Merged

Conversation

yuhaoth
Copy link
Contributor

@yuhaoth yuhaoth commented Mar 20, 2023

Description

Fixes #6920

This PR is enable MSVC support for AESCE module.

The code is verified under below condition.

  • Build with VS2022 and platformtoolsetversion=v143
    • With VS2022, platformtoolsetversion=v141 build fail. arm_neon.h reports ARM64 not supported
  • Test on Windows 10 with selftest

NOTE: Build command msbuild /nodeReuse:false /t:Rebuild /p:Configuration=Debug,Platform=ARM64,PlatformToolset=v143 "mbedTLS.sln"

Gatekeeper checklist

@yuhaoth yuhaoth added needs-review Every commit must be reviewed by at least two team members, component-crypto Crypto primitives and low-level interfaces needs-ci Needs to pass CI tests needs-reviewer This PR needs someone to pick it up for review labels Mar 20, 2023
@yuhaoth yuhaoth linked an issue Mar 20, 2023 that may be closed by this pull request
@daverodgman daverodgman added the priority-very-high Highest priority - prioritise this over other review work label Mar 20, 2023
@daverodgman
Copy link
Contributor

AFAICT platformtoolsetversion=v141 means VS 2017. We support VS 2013 - so if this doesn't work on VS 2017, it needs to detect the compiler version and only enable for recent versions of VS.

@daverodgman daverodgman added priority-high High priority - will be reviewed soon and removed priority-very-high Highest priority - prioritise this over other review work labels Mar 20, 2023
library/aesce.h Outdated
#define MBEDTLS_HAVE_ARM64
#endif
#endif

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With just this and the change to aesce.c, I get

Microsoft (R) Program Maintenance Utility Version 14.35.32215.0
Copyright (C) Microsoft Corporation.  All rights reserved.

        cl -nologo -Ilibrary/ -Iinclude/ -Fobuild\library\ -c ./library\aesce.c
aesce.c
./library\aesce.c(304): error C2440: 'type cast': cannot convert from '__n64' to 'poly64_t'
./library\aesce.c(301): error C2168: 'neon_pmull_64': too few actual parameters for intrinsic function
./library\aesce.c(368): error C2143: syntax error: missing ')' before ':'
NMAKE : fatal error U1077: 'cl -nologo -Ilibrary/ -Iinclude/ -Fobuild\library\ -c ./library\aesce.c' : return code '0x2'
Stop.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would the project file changes fix that, do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not get this error. What's your build command. It looks like msvc 2022.

Copy link
Contributor

@tom-cosgrove-arm tom-cosgrove-arm Mar 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was using a custom makefile. The command it executed was as shown

cl -nologo -Ilibrary/ -Iinclude/ -Fobuild\library\ -c ./library\aesce.c

The compiler it was running was

c:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.35.32215\bin\HostARM64\ARM64/cl.exe

i.e. Visual Studio 2022, running on ARM64, targeting ARM64

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let me try it.

I did not install arm64 host compiler. but I think it can be reproduced by same version.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can reproduce it now. I forget rebase this PR. :(

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that uwp is a Windows Store build, and might not be targeted by everyone

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed.

Copy link
Contributor Author

@yuhaoth yuhaoth Mar 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That might be a bug of GCC also.

GCC think poly64_t and poly64x1_t are different. So cast is a MUST for GCC. But I think they should be same, no cast needed

@tom-cosgrove-arm
Copy link
Contributor

This probably also needs an update to check_config.h around where it says

#error "MBEDTLS_AESCE_C defined, but not all prerequisites"

@tom-cosgrove-arm
Copy link
Contributor

There also needs to be a fix for around line 368 in aesce.h

/* use 'asm' as an optimisation barrier to prevent loading MODULO from memory */
asm ("" : "+w" (r));

@yuhaoth
Copy link
Contributor Author

yuhaoth commented Mar 21, 2023

I just rebased this PR due to gcm compile fail.

@yuhaoth
Copy link
Contributor Author

yuhaoth commented Mar 21, 2023

I have tried some msvc versions from vs2022 with bellow command

"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsall.bat" x64_arm64 uwp 10.0.22621.0 -vcvars_ver=%1

cl -Ilibrary/ -Iinclude/ -c ./library\aesce.c

The versions are 14.16.27023 14.29.30133 14.30.30705 14.31.31103 14.32.31326 14.33.31629 14.34.3193314.35.32215

14.16.27023 reports ARM64 not support from arm_neon.h . Others passed above test.

@yuhaoth
Copy link
Contributor Author

yuhaoth commented Mar 22, 2023

ARMCC reports license server error. Others pass

@yuhaoth yuhaoth force-pushed the pr/Add-msvc-support-for-aesce-module branch from 8894636 to 472cb58 Compare March 27, 2023 06:52
@yuhaoth
Copy link
Contributor Author

yuhaoth commented Mar 27, 2023

Rebase to re-trigger CI

@yuhaoth
Copy link
Contributor Author

yuhaoth commented Mar 29, 2023

It is replaced with #7286

@yuhaoth yuhaoth closed this Mar 29, 2023
@tom-cosgrove-arm
Copy link
Contributor

Actually, could we not do that? i.e. let's not have one PR (7286) that does a bunch of completely different things.

There should be one PR to replace the Perl scripts with Python, and another to add MSVC support for AESCE

@yuhaoth
Copy link
Contributor Author

yuhaoth commented Mar 29, 2023

Actually, could we not do that? i.e. let's not have one PR (7286) that does a bunch of completely different things.

There should be one PR to replace the Perl scripts with Python, and another to add MSVC support for AESCE

Agree. I do not think it more.

@yuhaoth yuhaoth reopened this Mar 29, 2023
@yuhaoth yuhaoth force-pushed the pr/Add-msvc-support-for-aesce-module branch 2 times, most recently from 22ea3fa to c1ad0ae Compare March 29, 2023 08:57
@daverodgman daverodgman added needs-work and removed needs-reviewer This PR needs someone to pick it up for review needs-ci Needs to pass CI tests labels Apr 24, 2023
- Add msc version check
- remove HAVE_ASM due to conflict with check_config

Signed-off-by: Jerry Yu <jerry.h.yu@arm.com>
Signed-off-by: Jerry Yu <jerry.h.yu@arm.com>
@yuhaoth yuhaoth added needs-review Every commit must be reviewed by at least two team members, and removed needs-work labels Apr 25, 2023
library/aesce.h Outdated Show resolved Hide resolved
@daverodgman
Copy link
Contributor

Do we want to add a #error if the user tries to build for Arm with MBEDTLS_AESCE_C enabled on an old MSVC? As it stands, I think it will silently not build AESCE_C, so if plain C is still enabled, the user will unexpectedly not get AESCE.

Signed-off-by: Jerry Yu <jerry.h.yu@arm.com>
When `MBEDTLS_AESCE_C` enabled and the compiler
is not expected, we should raise error to user.

Signed-off-by: Jerry Yu <jerry.h.yu@arm.com>
@yuhaoth yuhaoth force-pushed the pr/Add-msvc-support-for-aesce-module branch from c67ba96 to 61c4cfa Compare April 26, 2023 05:06
@daverodgman
Copy link
Contributor

Looks good but the gcc check triggers when building with clang

library/aesce.c Outdated Show resolved Hide resolved
@daverodgman
Copy link
Contributor

I think the recommended way to detect gcc but not clang is defined(__GNUC__) && !defined(__clang__) - see https://github.com/abseil/abseil.github.io/blob/master/docs/cpp/platforms/macros.md

@tom-cosgrove-arm
Copy link
Contributor

I think the recommended way to detect gcc but not clang is defined(__GNUC__) && !defined(__clang__) - see https://github.com/abseil/abseil.github.io/blob/master/docs/cpp/platforms/macros.md

That's what we normally do - but putting #if defined(__clang__) and #elif defined(__GNUC__) gives the same result

@daverodgman
Copy link
Contributor

I think the recommended way to detect gcc but not clang is defined(__GNUC__) && !defined(__clang__) - see https://github.com/abseil/abseil.github.io/blob/master/docs/cpp/platforms/macros.md

That's what we normally do - but putting #if defined(__clang__) and #elif defined(__GNUC__) gives the same result

It would, but the first if condition also has a version check, so we do need the suggested fix.

Signed-off-by: Jerry Yu <jerry.h.yu@arm.com>
@daverodgman daverodgman added the needs-ci Needs to pass CI tests label Apr 26, 2023
Copy link
Contributor

@tom-cosgrove-arm tom-cosgrove-arm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@tom-cosgrove-arm tom-cosgrove-arm added approved Design and code approved - may be waiting for CI or backports and removed needs-review Every commit must be reviewed by at least two team members, labels Apr 26, 2023
@daverodgman daverodgman merged commit 98062a7 into Mbed-TLS:development Apr 26, 2023
@yuhaoth yuhaoth deleted the pr/Add-msvc-support-for-aesce-module branch December 6, 2023 05:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Design and code approved - may be waiting for CI or backports component-crypto Crypto primitives and low-level interfaces needs-ci Needs to pass CI tests priority-high High priority - will be reviewed soon
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enable Arm64 windows build and test. Support armv8 crypto extensions for AES and GCM
4 participants