This is a note to let you know that I've just added the patch titled kbuild: rust: force `alloc` extern to allow "empty" Rust files to the 6.8-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: kbuild-rust-force-alloc-extern-to-allow-empty-rust-files.patch and it can be found in the queue-6.8 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. >From ded103c7eb23753f22597afa500a7c1ad34116ba Mon Sep 17 00:00:00 2001 From: Miguel Ojeda <ojeda@xxxxxxxxxx> Date: Mon, 22 Apr 2024 11:06:44 +0200 Subject: kbuild: rust: force `alloc` extern to allow "empty" Rust files From: Miguel Ojeda <ojeda@xxxxxxxxxx> commit ded103c7eb23753f22597afa500a7c1ad34116ba upstream. If one attempts to build an essentially empty file somewhere in the kernel tree, it leads to a build error because the compiler does not recognize the `new_uninit` unstable feature: error[E0635]: unknown feature `new_uninit` --> <crate attribute>:1:9 | 1 | feature(new_uninit) | ^^^^^^^^^^ The reason is that we pass `-Zcrate-attr='feature(new_uninit)'` (together with `-Zallow-features=new_uninit`) to let non-`rust/` code use that unstable feature. However, the compiler only recognizes the feature if the `alloc` crate is resolved (the feature is an `alloc` one). `--extern alloc`, which we pass, is not enough to resolve the crate. Introducing a reference like `use alloc;` or `extern crate alloc;` solves the issue, thus this is not seen in normal files. For instance, `use`ing the `kernel` prelude introduces such a reference, since `alloc` is used inside. While normal use of the build system is not impacted by this, it can still be fairly confusing for kernel developers [1], thus use the unstable `force` option of `--extern` [2] (added in Rust 1.71 [3]) to force the compiler to resolve `alloc`. This new unstable feature is only needed meanwhile we use the other unstable feature, since then we will not need `-Zcrate-attr`. Cc: stable@xxxxxxxxxxxxxxx # v6.6+ Reported-by: Daniel Almeida <daniel.almeida@xxxxxxxxxxxxx> Reported-by: Julian Stecklina <julian.stecklina@xxxxxxxxxxxxxxxxxxxxx> Closes: https://rust-for-linux.zulipchat.com/#narrow/stream/288089-General/topic/x/near/424096982 [1] Fixes: 2f7ab1267dc9 ("Kbuild: add Rust support") Link: https://github.com/rust-lang/rust/issues/111302 [2] Link: https://github.com/rust-lang/rust/pull/109421 [3] Reviewed-by: Alice Ryhl <aliceryhl@xxxxxxxxxx> Reviewed-by: Gary Guo <gary@xxxxxxxxxxx> Link: https://lore.kernel.org/r/20240422090644.525520-1-ojeda@xxxxxxxxxx Signed-off-by: Miguel Ojeda <ojeda@xxxxxxxxxx> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- scripts/Makefile.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -272,7 +272,7 @@ rust_common_cmd = \ -Zallow-features=$(rust_allowed_features) \ -Zcrate-attr=no_std \ -Zcrate-attr='feature($(rust_allowed_features))' \ - --extern alloc --extern kernel \ + -Zunstable-options --extern force:alloc --extern kernel \ --crate-type rlib -L $(objtree)/rust/ \ --crate-name $(basename $(notdir $@)) \ --sysroot=/dev/null \ Patches currently in stable-queue which might be from ojeda@xxxxxxxxxx are queue-6.8/rust-remove-params-from-module-macro-example.patch queue-6.8/kbuild-rust-remove-unneeded-rustc_cfg-to-avoid-ice.patch queue-6.8/rust-don-t-select-constructors.patch queue-6.8/rust-kernel-require-send-for-module-implementations.patch queue-6.8/rust-init-remove-impl-zeroable-for-infallible.patch queue-6.8/rust-make-mutually-exclusive-with-cfi_clang.patch queue-6.8/kbuild-rust-force-alloc-extern-to-allow-empty-rust-files.patch