[PATCH] rust: kbuild: add `no_io_statics` to `core-cfgs`

Alice Ryhl posted 1 patch 3 weeks, 1 day ago
rust/Makefile | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
[PATCH] rust: kbuild: add `no_io_statics` to `core-cfgs`
Posted by Alice Ryhl 3 weeks, 1 day ago
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@google.com>
---
 rust/Makefile | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/rust/Makefile b/rust/Makefile
index da1a7409d984..8cbee5b6b0bd 100644
--- a/rust/Makefile
+++ b/rust/Makefile
@@ -75,7 +75,8 @@ endif
 cfgs-to-flags = $(patsubst %,--cfg='%',$1)
 
 core-cfgs := \
-    no_fp_fmt_parse
+    no_fp_fmt_parse \
+    no_io_statics
 
 core-edition := $(if $(call rustc-min-version,108700),2024,2021)
 

---
base-commit: cee9395acd8043be0644b25c34bfa86623f2b935
change-id: 20260904-no-io-statics-ab07a70358c8

Best regards,
-- 
Alice Ryhl <aliceryhl@google.com>
Re: [PATCH] rust: kbuild: add `no_io_statics` to `core-cfgs`
Posted by Gary Guo 3 weeks, 1 day ago
On Fri Sep 4, 2026 at 10:31 AM BST, Alice Ryhl 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@google.com>

Didn't know that this already exists :)

Reviewed-by: Gary Guo <gary@garyguo.net>

> ---
>  rust/Makefile | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)