lib/ukatomic: Import FreeBSD `stdatomic.h` header by mogasergiu · Pull Request #1919 · unikraft/unikraft · GitHub
Skip to content

lib/ukatomic: Import FreeBSD stdatomic.h header - #1919

Open
mogasergiu wants to merge 1 commit into
unikraft:stagingfrom
mogasergiu:sergiu/#1918/ukatomic-stdatomic
Open

mogasergiu wants to merge 1 commit into
unikraft:stagingfrom
mogasergiu:sergiu/#1918/ukatomic-stdatomic

Conversation

@mogasergiu

Copy link
Copy Markdown
Member

stdatomic.h comes with the compiler, not the libc (musl/glibc don't ship it), and -nostdinc hides the compiler's copy, so anything including it fails with fatal error: stdatomic.h: No such file or directory. Context: #1843.

This imports FreeBSD's sys/sys/stdatomic.h (BSD-2-Clause, upstream 5076e9b5463a) into lib/ukatomic/include. Its sys/cdefs.h/sys/_types.h deps are swapped for compiler predefines, so it has no includes: one copy serves nolibc and musl, and ukatomic stays libc-free. It's exported through ukatomic's existing include path. No API or Kconfig changes. The commit message lists every deviation from upstream and why.

Description of Changes

Related Work

N/A

PR Checklist

  • Read the contribution guidelines regarding submitting new changes to the project;
  • Tested your changes against relevant architectures and platforms;
  • Ran the checkpatch.uk on your commit series before opening this PR;
  • Updated relevant documentation.

Import the `stdatomic.h` header from FreeBSD, providing C11 atomics.
It normally comes with the compiler, not the libc (musl/glibc don't
ship it), and -nostdinc hides the compiler's copy, so anything
including it fails to build.

Pinned to a main commit, as the latest release (15.1.0) predates the
pointer atomic_fetch_{add,sub} stride fix for GCC.

Changed to:
- use compiler predefines instead of sys/cdefs.h and sys/_types.h, so it
  has no includes and one copy serves nolibc and musl. Downside:
  atomic_{u,}int_fast{16,32}_t follow the compiler's ABI, not musl's
- pick the backend w/ #ifdef __clang__; upstream's __has_extension and
  __GNUC_PREREQ__ checks always land there for our GCC-7/Clang-9 floor
- gate C23 bits on __STDC_VERSION__ (upstream's __ISO_C_VISIBLE defaults
  to 2023, i.e. on for any -std)
- make ATOMIC_VAR_INIT() (value) on GCC too: upstream's { .__val = }
  wants a struct-wrapped _Atomic and breaks with GCC's native one
- drop the pre-GCC-4.7 __sync fallback, C++ _Bool shim and _KERNEL bits

Source of import:
Repository: https://git.FreeBSD.org/src.git
Commit: 5076e9b5463afa47cf2e7689431d3dd33e5b15cb
Path: sys/sys/stdatomic.h

Checkpatch-Ignore: BRACES
Checkpatch-Ignore: CAMELCASE
Checkpatch-Ignore: COMMIT_LOG_USE_LINK
Checkpatch-Ignore: INLINE
Checkpatch-Ignore: LEADING_SPACE
Checkpatch-Ignore: MACRO_ARG_REUSE
Checkpatch-Ignore: PARENTHESIS_ALIGNMENT
Checkpatch-Ignore: SPACING
Checkpatch-Ignore: SPDX_LICENSE_TAG
Checkpatch-Ignore: VOLATILE
Signed-off-by: Sergiu Moga <sergiu@unikraft.io>
@github-actions github-actions Bot added the area/lib Internal Unikraft Microlibrary label Oct 6, 2026

@michpappas michpappas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Reviewed-by: Michalis Pappas michalis@unikraft.io

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/lib Internal Unikraft Microlibrary

Projects

Status: 🧊 Icebox

Development

Successfully merging this pull request may close these issues.

2 participants