Skip to content

Simplify automatic support of Unix-like platforms across modules #675

@gilles-peskine-arm

Description

@gilles-peskine-arm

There are several places in TF-PSA-Crypto and Mbed TLS that have an adherence on non-standard C features, either mandatory or optional. We have built-in support for Unix-like platforms and for Windows, and sometimes ways to configure the library on other platforms. “Unix-like” covers a vast range of systems, including:

  • Linux kernel with several possible libc.
  • Unix implementations from a single vendor such as *BSD, macOS, QNX, AIX, …
  • Various Unix/POSIX/Linux layers on Windows.
  • Various embedded systems with partial Unix APIs.

The goal of this issue is to simplify the code that we use to detect, and adapt to, Unix-like platforms, so that we are less afraid of breaking things if we need to fix a bug in the next long-time support branch. It covers both TF-PSA-Crypto and Mbed TLS.

Here are some known problems, as of TF-PSA-Crypto 1.0.0 and Mbed TLS 4.0.0:

  • We include unistd.h and other Unix headers in many different places: platform_util.c, threading.c, unistd.c, net_sockets.c (and that's just for the library, the rest matters less). Each file has a different idea of whether to include QNX, Haiku, Midipix…
  • Compiler options can break the build as they may influence which symbols are declared in system headers.
  • We have hacks to allow a non-C99 printf in debug.h, only for Windows. These hacks may or may not work correctly because the printf variant (standard C99 or Windows legacy) is determined when debug.c is built, but the format strings is determined when ssl_*.c is built. They may end up being different if, for example, a module using debug also defines a macro such as _POSIX_C_SOURCE or _XOPEN_SOURCE — then Mingw will pull in the GNU printf implementation which is C99-compliant, instead of the default one which isn't. The way Mingw picks the printf implementation seems to have been overhauled in version 13, released in June 2025, and our code may not work with that version (I suspect that's the cause of MinGW-w64 GCC build fails with -Werror=format: MBEDTLS_PRINTF_LONGLONG mismatches long long in ssl_client.c/ssl_tls12_server.c mbedtls#10566). We've had other problems with these hacks before (Wrong MSVC version guard for C99 format size specifiers mbedtls#10017).

Out of scope:

  • Providing additional configurability is out of scope here. It is of course desirable, but it would take a lot of effort. This issue focusing on what works out of the box.
  • Only the libraries is in scope. While it would be nice for the sample programs to run on more platforms, it's a lot less important. Test tools are completely out of scope, we only care about them running on our CI environment and on developer machines.

Metadata

Metadata

Assignees

No one assigned

    Labels

    size-sEstimated task size: small (~2d)

    Type

    Projects

    Status

    Design needed

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions