From bee1d65d213cc7850b8b2d69bc751476ff776b70 Mon Sep 17 00:00:00 2001 From: Emma Stensland Date: Mon, 21 Sep 2026 10:51:40 -0600 Subject: [PATCH] xasm: check IAR and KEIL before WOLF_C99 in XASM_VOLATILE() WOLF_C99 is on for IAR by default, so IAR (and Keil AC5) got __asm__, which neither accepts. --- ChangeLog.md | 7 +++++++ wolfssl/wolfcrypt/wc_port.h | 12 +++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 822e5347213..53daf96a099 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -154,6 +154,13 @@ now list `WOLFSSL_CRYPTOCELL` alongside the other ports that replace the software curve arithmetic. +* **Fix (`XASM_VOLATILE()` on IAR and Keil AC5)**: `WOLF_C99` follows + `__STDC_VERSION__`, so it is defined on IAR by default (unless built with + `--c89` or `NO_WOLF_C99`), and its arm was checked first. That handed IAR, + and Keil's AC5 armcc under `__KEIL__`, `__asm__`, which neither accepts. + Both now get `__asm`, which IAR keeps under `--strict` and both Keil + compilers accept. + ## Fixes * ML-KEM and ML-DSA now keep the key's device id on their internal SHAKE hashing, so a registered crypto callback sees the SHAKE-256 Update and Final calls. by @Frauschi (PR 11544) diff --git a/wolfssl/wolfcrypt/wc_port.h b/wolfssl/wolfcrypt/wc_port.h index d61ee49f6cb..a92ea27348c 100644 --- a/wolfssl/wolfcrypt/wc_port.h +++ b/wolfssl/wolfcrypt/wc_port.h @@ -2090,13 +2090,15 @@ WOLFSSL_ABI WOLFSSL_API int wolfCrypt_Cleanup(void); #endif #endif -#ifdef WOLF_C99 +/* Checked before WOLF_C99, which follows __STDC_VERSION__ and so is set on + * IAR by default: IAR and Keil's AC5 armcc reject __asm__. __asm works on + * IAR, including under --strict where plain asm does not, and on AC5 and + * AC6 alike. */ +#if defined(__IAR_SYSTEMS_ICC__) || defined(__KEIL__) + #define XASM_VOLATILE(a) __asm volatile(a) +#elif defined(WOLF_C99) /* use alternate keyword for compatibility with -std=c99 */ #define XASM_VOLATILE(a) __asm__ volatile(a) -#elif defined(__IAR_SYSTEMS_ICC__) - #define XASM_VOLATILE(a) asm volatile(a) -#elif defined(__KEIL__) - #define XASM_VOLATILE(a) __asm volatile(a) #else #define XASM_VOLATILE(a) __asm__ __volatile__(a) #endif