Re: [PATCH] rust: kbuild: add `no_io_statics` to `core-cfgs`
From: Miguel Ojeda
Date: Fri Oct 02 2026 - 09:31:08 EST
On Fri, Sep 4, 2026 at 11:31 AM Alice Ryhl <aliceryhl@xxxxxxxxxx> wrote:
>
> In upstream Rust, PR #155625 moved `std::io::Error` into `core` under
> the `core_io` feature gate. To support decoding and formatting raw OS
> errors (`RawOsError`) from within `core` without depending on OS
> facilities, `core` introduced a global atomic pointer:
>
> static OS_FUNCTIONS: atomic::AtomicPtr<OsFunctions>
>
> At runtime, `std` registers its OS error vtable with this pointer via
> `set_functions()`, which uses `core::sync::atomic` to modify the value
> of this atomic variable.
>
> To ensure that `core` does not introduce usage of `core::sync::atomic`
> into the kernel image, set the `no_io_statics` cfg, which removes this
> logic from the build.
>
> Note that changing the `OS_FUNCTIONS` global is only possible via the
> unstable `from_raw_os_error_with_functions()` function from `core`,
> which is called by `std`. There is no way for us to invoke it from the
> kernel, as we do not use `std`.
>
> Link: https://github.com/rust-lang/rust/pull/155625
> Link: https://github.com/rust-lang/rust/issues/154046
> Link: https://github.com/rust-lang/libs-team/issues/755
> Signed-off-by: Alice Ryhl <aliceryhl@xxxxxxxxxx>
Applied to `rust-next` -- thanks everyone!
[ Pass `-Aunused_variables` to `core` to avoid:
error: unused variable: `f`
--> .../library/core/src/io/error/os_functions.rs:9:36
|
9 | pub(super) unsafe fn set_functions(f: &'static OsFunctions) {
| ^ help: if this is
intentional, prefix it with an underscore: `_f`
|
= note: `-D unused-variables` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(unused_variables)]`
I sent a PR upstream [1] to clean it up and to add a test to check
that `core` builds are warning-free with the `cfg` enabled, similar
to what I added for other `cfg`s.
Link: https://github.com/rust-lang/rust/pull/163633 [1]
- Miguel ]
Cheers,
Miguel