Skip to content

arch/espressif: add stdatomic.h shim for ATOMIC_VAR_INIT - #20770

Merged
acassis merged 1 commit into
apache:masterfrom
Swatantra-66:fix/espressif-gcc15-atomic-var-init
Oct 18, 2026
Merged

acassis merged 1 commit into
apache:masterfrom
Swatantra-66:fix/espressif-gcc15-atomic-var-init

Conversation

@Swatantra-66

Copy link
Copy Markdown
Contributor

Summary

  • Why change is necessary:
    In C23 and GCC 15 toolchains (e.g., xtensa-esp-elf-gcc 15.2.0), the legacy ATOMIC_VAR_INIT macro was completely removed from <stdatomic.h> after being deprecated in C17. Third-party HAL components in esp-hal-3rdparty (such as components/esp_hw_support/esp_gpio_reserve.c) still use ATOMIC_VAR_INIT to initialize atomic masks (s_reserved_pin_mask), triggering -Wimplicit-function-declaration and initializer element is not constant errors during build.
  • What it does:
    Adds a lightweight platform_include wrapper for <stdatomic.h> under:
    • arch/xtensa/src/common/espressif/platform_include/stdatomic.h
    • arch/risc-v/src/common/espressif/platform_include/stdatomic.h
      The wrapper uses #include_next <stdatomic.h> to include the toolchain's header first, and then conditionally defines ATOMIC_VAR_INIT(value) (value) if not already provided.
  • References:
    Fixes [BUG] esp32s3: esp-hal-3rdparty fails to build with GCC 15 (ATOMIC_VAR_INIT removed) #20704

Impact

  • Is new feature added?: NO
  • Impact on user?: NO (internal build compatibility fix)
  • Impact on build?: YES (fixes compilation failures under GCC 15 and C23 for Espressif chips)
  • Impact on hardware?: YES (Espressif targets: ESP32, ESP32-S2, ESP32-S3, ESP32-C2, ESP32-C3, ESP32-C6, ESP32-H2, ESP32-P4)
  • Impact on documentation?: NO
  • Impact on security?: NO
  • Impact on compatibility?: Fully backward compatible with GCC <= 14. Because #include_next is evaluated first, older toolchains that already define ATOMIC_VAR_INIT take precedence and will not trigger macro redefinition warnings.
  • Impact on submodules?: NO modifications required to the external esp-hal-3rdparty repository.

Testing

  • Verified #include_next <stdatomic.h> header interception and #ifndef ATOMIC_VAR_INIT fallback logic.
  • Verified style compliance with nxstyle (0 errors, 0 warnings).
  • Verified spelling and UTF-8 encoding with codespell and cvt2utf.
  • Verified commit message rules with tools/checkpatch.sh.

In C23 and GCC 15 (e.g., xtensa-esp-elf-gcc 15.2.0), ATOMIC_VAR_INIT was
removed from <stdatomic.h> after being deprecated in C17.

Third-party HAL components in esp-hal-3rdparty (such as
esp_gpio_reserve.c) still utilize ATOMIC_VAR_INIT to initialize atomic
masks (e.g., s_reserved_pin_mask), causing compilation errors under
GCC 15 due to implicit function declarations and non-constant
initializers.

Provide a platform_include wrapper for <stdatomic.h> on both Xtensa
and RISC-V Espressif architectures using #include_next that defines
ATOMIC_VAR_INIT(value) when it is not provided by the toolchain.

Fixes apache#20704

Signed-off-by: Swatantra Yadav <[email protected]>
@github-actions github-actions Bot added Arch: risc-v Issues related to the RISC-V (32-bit or 64-bit) architecture Arch: xtensa Issues related to the Xtensa architecture Size: S The size of the change in this PR is small labels Oct 18, 2026
@github-actions

Copy link
Copy Markdown

MemBrowse Memory Report

No memory changes detected for:

@acassis
acassis merged commit 4189d28 into apache:master Oct 18, 2026
53 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Arch: risc-v Issues related to the RISC-V (32-bit or 64-bit) architecture Arch: xtensa Issues related to the Xtensa architecture Size: S The size of the change in this PR is small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] esp32s3: esp-hal-3rdparty fails to build with GCC 15 (ATOMIC_VAR_INIT removed)

3 participants