Skip to content

Add winsock2 header into build_info.h #262

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

Open
wants to merge 1 commit into
base: development
Choose a base branch
from

Conversation

irwir
Copy link
Contributor

@irwir irwir commented Apr 19, 2025

Description

Ensures proper socket definitions on Windows (as a part of resolving mbedtls issue #10097).

PR checklist

  • changelog not required
  • framework PR not required
  • mbedtls development PR provided #10140
  • mbedtls 3.6 PR not required because: not planned
  • tests not required

@gilles-peskine-arm
Copy link
Contributor

TF-PSA-Crypto needs to build outside of Mbed TLS. So it doesn't seem right to me that the Windows build (with an unchanged mbedtls) is failing here.

@irwir
Copy link
Contributor Author

irwir commented Apr 22, 2025

This is odd if an additional standard header breaks things so badly.

[2025-04-21T19:59:35.604Z] 291>C:/Users/Administrator/AppData/Local/Temp/tmp5cfern6y/tf-psa-crypto/tests/suites/test_suite_ecp.function(19): error C2143: syntax error : missing ')' before 'constant' [C:\Users\Administrator\AppData\Local\Temp\tmp5cfern6y\cmake_solution\tf-psa-crypto\tests\test_suite_ecp.vcxproj]

How to parse this?
The C2143 error code from a compiler and the last word vcxproj indicate a compilation error.
But the source file is test_suite_ecp.function while make build uses tf-psa-crypto/tests/test_suite_ecp.c?

@irwir
Copy link
Contributor Author

irwir commented Apr 22, 2025

[2025-04-21T19:59:36.764Z] cl : Command line warning D9002: ignoring unknown option '/utf-8' [C:\Users\Administrator\AppData\Local\Temp\tmp5cfern6y\cmake_solution\tf-psa-crypto\tests\test_suite_gcm.aes128_en.vcxproj]

Numerous warnings in the log. Maybe VS 2013 did not have this option?
Unlike for mbdetls, tests were never tried with later versions of Visual Studio.

@gilles-peskine-arm
Copy link
Contributor

test_suite_xxx.c is generated from test_suite_xxx.function using framework/scripts/generate_test_code.py. It does a couple of substitutions and adds some boilerplate as well as code to prepare arguments to test functions.

The offending line (more visible in the message from MinGW) is

inline static int mbedtls_ecp_group_cmp(mbedtls_ecp_group *grp1,

It looks like the parser gets confused because it doesn't recognize inline as intended.

We use the inline keyword in our code base. For compilers such as MSVC that don't define it, tf-psa-crypto/build_info.h defines it. This happens shortly before the inclusion of winsock2.h. I have no idea why including winsock2.h breaks this.

As for /utf-8, the warning is annoying but harmless. It was added to fix a warning that does break the build in some environments (those using a non-UTF-8 multibyte encoding by default, if I understand correctly).

@irwir
Copy link
Contributor Author

irwir commented Apr 22, 2025

test_suite_xxx.c is generated from test_suite_xxx.function

The question was why .function instead of the expected .c in the compiler diagnostics. This was explained by #line directive.

I have no idea why including winsock2.h breaks this.

It is difficult to guess without installed VS 2013 and the generated projects and sources.
A trivial inlined function after including build_info.h could be compiled even in VS 2012. The issue should be somewhere deeper.
With VS 2022, I copied and renamed cert_app.vcxproj, changed the source file to test_suite_ecp.c. Some paths had to be added, but finally it compiled.

@irwir
Copy link
Contributor Author

irwir commented Apr 22, 2025

As for /utf-8

Available since VS 2015.

@irwir
Copy link
Contributor Author

irwir commented Apr 23, 2025

As far as I remember, a bug in VS 2015 increased the minimum required version for mbedtls to VS 2017, even though the official documentation still says VS 2013 (also in solution path visualc/VS2013/mbedTLS.sln).

Quote from the current README.md in TF-PSA-Crypto:

The following instructions have been tested on Microsoft Visual Studio Community 2019 Version 16.11.26.

Yet there is nothing but VS 2013 in TF OpenCI: PR tests.

Should this have been changed in development branches?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants