Skip to content

Backport 1.1: IAR build fixes after 1.1.0#708

Open
gilles-peskine-arm wants to merge 12 commits intoMbed-TLS:tf-psa-crypto-1.1from
gilles-peskine-arm:iar-1.1.0
Open

Backport 1.1: IAR build fixes after 1.1.0#708
gilles-peskine-arm wants to merge 12 commits intoMbed-TLS:tf-psa-crypto-1.1from
gilles-peskine-arm:iar-1.1.0

Conversation

@gilles-peskine-arm
Copy link
Copy Markdown
Contributor

@gilles-peskine-arm gilles-peskine-arm commented Mar 11, 2026

Fix the build of the library and the unit tests with IAR.

This is the 1.1 version. I'll do the development version once the 1.1 version is approved or close to being appoved, since development is a moving target and there's already one more warning (in the new MLDSA code) now.

The build was already broken in 1.0.0, but #694 made it worse by adding deprecation warnings on the use of many standard library functions.

Needs preceding PR: submodule update, although this is only needed to actually fix the IAR build, not to pass our CI.

Needs preceding PR:

PR checklist

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes IAR build issues/regressions in the library and unit tests (notably IAR-specific deprecation warnings and diagnostics).

Changes:

  • Adds IAR-specific configuration and diagnostic suppressions to unblock compilation of library and test code.
  • Updates unit tests to avoid constructs that trigger IAR warnings/errors (e.g., TEST_ASSERT(!"msg")TEST_FAIL("msg")).
  • Adjusts platform/header behavior around C11 Annex K and zeroization functions; updates framework submodule.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
tests/suites/test_suite_rsa.function Simplifies a test callsite argument (always NULL).
tests/suites/test_suite_psa_crypto_pake.function Replaces assertion idiom with explicit test failure to satisfy IAR.
tests/suites/test_suite_psa_crypto.function Same as above for PSA crypto suite variant.
tests/suites/test_suite_alignment.function Removes unused local buffer initialization from alignment test.
tests/suites/main_test.function Adds IAR DLIB config and suppresses specific IAR diagnostics in test runner TU.
tests/suites/host_test.function Changes integer parsing validation for IAR compatibility.
platform/platform_util.c Enables memset_s path even under IAR.
framework Updates framework submodule pointer.
drivers/builtin/src/psa_crypto_cipher.c Suppresses IAR goto/initialization diagnostic in cipher module TU.
drivers/builtin/src/bignum.c Suppresses IAR goto/initialization diagnostic in bignum module TU.
drivers/builtin/src/aes.c Fixes logic for selecting AES implementation return value under hardware-only builds.
core/tf_psa_crypto_platform_requirements.h Documents IAR Annex K side-effect on deprecations.
core/tf_psa_crypto_common.h Adds IAR-specific workaround redefining __DEPREC after enabling Annex K.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines 41 to 45
long value = strtol(str, &end, 0);
if (errno == EINVAL || *end != '\0') {
if (*end != '\0' || end == str) {
mbedtls_fprintf(stderr,
"Expected integer for parameter and got: %s\n", str);
return KEY_VALUE_MAPPING_NOT_FOUND;
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

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

strtol() errors aren’t fully handled here: overflow/underflow sets errno = ERANGE and returns a clamped value, which would currently be accepted and can yield incorrect test parameter values. Consider setting errno = 0 before calling strtol() and rejecting inputs when errno == ERANGE (in addition to the existing end == str / trailing characters checks).

Copilot uses AI. Check for mistakes.
Comment on lines +64 to +80
#if defined(__IAR_SYSTEMS_ICC__)
/* Suppress a very overeager warning from IAR: it dislikes a forward goto
* that bypasses the initialization of a variable, even if that variable
* is not used after the jump. (This is perfectly valid C; it would only
* be invalid C if jumping into a block from outside that block.)
*/
#pragma diag_suppress=Pe546 // transfer of control bypasses initialization

/* Temporarily suppress a perfectly reasonable warning from IAR that
* comes up very often in our unit tests: silent conversion of int to
* an enum type.
*
* Remove this when https://github.com/Mbed-TLS/TF-PSA-Crypto/issues/707
* is fixed.
*/
#pragma diag_suppress=Pe188 // enumerated type mixed with another type
#endif
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

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

These diagnostic suppressions apply to the remainder of the translation unit and are not restored, which can mask unrelated warnings and make future debugging harder. Consider scoping them (e.g., using IAR’s diagnostic push/pop if available, or restoring with #pragma diag_default=Pe546 / #pragma diag_default=Pe188 after the affected section) so only the intended code patterns are covered.

Copilot uses AI. Check for mistakes.
Comment on lines +48 to +51
#include <stddef.h>
#undef __DEPREC
#define __DEPREC
#endif
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

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

Redefining a toolchain/system macro like __DEPREC in a widely-included header can leak into downstream includes and alter how unrelated headers declare deprecations (effectively disabling deprecation annotations beyond this library). A more contained approach would be to localize this workaround to implementation files, or to bracket only the specific system header inclusions that trigger the unwanted deprecations (and then restore the original macro), or to prefer a compiler pragma/warning-control mechanism where possible.

Copilot uses AI. Check for mistakes.
#if defined(__IAR_SYSTEMS_ICC__)
/* In IAR (at least IAR 9.40 for Arm), enabling the C11 annex K functions
* (memset_s(), memcpy_s(), ...) with `#define __STDC_WANT_LIB_EXT1__ 1`
* causes the non-s functions to be declared as deprecatd. We want some
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

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

Corrected spelling of 'deprecatd' to 'deprecated'.

Suggested change
* causes the non-s functions to be declared as deprecatd. We want some
* causes the non-s functions to be declared as deprecated. We want some

Copilot uses AI. Check for mistakes.
@mpg mpg added needs-work and removed needs-preceding-pr Requires another PR to be merged first labels Mar 17, 2026
@gilles-peskine-arm gilles-peskine-arm changed the title IAR build fixes before 1.1.0 IAR build fixes after 1.1.0 Mar 19, 2026
@gilles-peskine-arm gilles-peskine-arm added needs-preceding-pr Requires another PR to be merged first and removed needs-work labels Apr 10, 2026
@gilles-peskine-arm gilles-peskine-arm added needs-review Every commit must be reviewed by at least two team members needs-reviewer This PR needs someone to pick it up for review labels Apr 10, 2026
GCC is ok with it but IAR frowns.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
We enable `__STDC_WANT_LIB_EXT1__` because we want some C11 Annex K
functions (`memset_s()` and `gmtime_s()`). This causes IAR 9.40 (and likely
other versions) to deprecate every function that has an annex K equivalent,
which we don't want. Hack around the deprecation warning.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
We had previously disabled the use of `memset_s` on IAR in
Mbed-TLS/mbedtls#7950 because it wasn't found when
building. But I believe the problem was not that IAR doesn't provide
`memset_s`: as far as I can tell, IAR added C11 support in version 8,
including Annex K. Rather, the problem was that at the time, we defined
`__STDC_WANT_LIB_EXT1__` too late, after some system headers were already
included, which made it ineffective. This ordering problem is fixed now, so
do use `memset_s` when it's supposed to be available.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
IAR emits Pe546 a "transfer of control bypasses initialization" diagnostic
in many cases that are perfectly valid and idiomatic C. Disable that warning
in places where IAR complains. This includes a lot of test suites.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
Standard C doesn't have `EINVAL`. Check for invalid inputs in a portable way.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
Temporarily suppress a perfectly reasonable warning from IAR that
comes up very often in our unit tests: silent conversion of int to
an enum type.

Improvement tracked as Mbed-TLS#707

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
If `NULL` is an integer constant expression with the value 0 (which C
allows), the expression `prng ? NULL : NULL` is not an integer constant
expression so it is not a null pointer constant, and thus it is not a
pointer.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This gets rid of a warning from IAR.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
Even without CI validation, we can promise that we've made the situation
better, and an IAR warning has been reported in
Mbed-TLS/mbedtls#10648

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
@gilles-peskine-arm gilles-peskine-arm changed the base branch from development to tf-psa-crypto-1.1 April 15, 2026 10:33
@gilles-peskine-arm gilles-peskine-arm changed the title IAR build fixes after 1.1.0 Backport 1.1: IAR build fixes after 1.1.0 Apr 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-ci Needs to pass CI tests needs-preceding-pr Requires another PR to be merged first needs-review Every commit must be reviewed by at least two team members needs-reviewer This PR needs someone to pick it up for review priority-high High priority - will be reviewed soon size-s Estimated task size: small (~2d)

Projects

Development

Successfully merging this pull request may close these issues.

3 participants