Go to file
Miguel Ojeda 4805d764f9 kbuild: rust: force `alloc` extern to allow "empty" Rust files
commit ded103c7eb 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@vger.kernel.org # v6.6+
Reported-by: Daniel Almeida <daniel.almeida@collabora.com>
Reported-by: Julian Stecklina <julian.stecklina@cyberus-technology.de>
Closes: https://rust-for-linux.zulipchat.com/#narrow/stream/288089-General/topic/x/near/424096982 [1]
Fixes: 2f7ab1267d ("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@google.com>
Reviewed-by: Gary Guo <gary@garyguo.net>
Link: https://lore.kernel.org/r/20240422090644.525520-1-ojeda@kernel.org
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2024-05-02 16:32:42 +02:00
Documentation mm, treewide: introduce NR_PAGE_ORDERS 2024-05-02 16:32:41 +02:00
LICENSES
arch x86/cpu: Fix check for RDPKRU in __show_regs() 2024-05-02 16:32:42 +02:00
block block: fix q->blkg_list corruption during disk rebind 2024-04-17 11:19:28 +02:00
certs
crypto crypto: jitter - fix CRYPTO_JITTERENTROPY help text 2024-03-26 18:19:52 -04:00
drivers drm/ttm: stop pooling cached NUMA pages v2 2024-05-02 16:32:41 +02:00
fs Squashfs: check the inode number is not the invalid value of zero 2024-05-02 16:32:41 +02:00
include mm, treewide: introduce NR_PAGE_ORDERS 2024-05-02 16:32:41 +02:00
init rust: make mutually exclusive with CFI_CLANG 2024-05-02 16:32:42 +02:00
io_uring io_uring: Fix io_cqring_wait() not restoring sigmask on get_timespec64() failure 2024-04-27 17:11:30 +02:00
ipc Add x86 shadow stack support 2023-08-31 12:20:12 -07:00
kernel fork: defer linking file vma until vma is fully initialized 2024-05-02 16:32:42 +02:00
lib mm, treewide: introduce NR_PAGE_ORDERS 2024-05-02 16:32:41 +02:00
mm mm, treewide: introduce NR_PAGE_ORDERS 2024-05-02 16:32:41 +02:00
net af_unix: Suppress false-positive lockdep splat for spin_lock() in __unix_gc(). 2024-05-02 16:32:40 +02:00
rust kbuild: rust: remove unneeded `@rustc_cfg` to avoid ICE 2024-05-02 16:32:42 +02:00
samples work around gcc bugs with 'asm goto' with outputs 2024-02-23 09:24:47 +01:00
scripts kbuild: rust: force `alloc` extern to allow "empty" Rust files 2024-05-02 16:32:42 +02:00
security selinux: avoid dereference of garbage after mount failure 2024-04-10 16:35:48 +02:00
sound ALSA: hda/realtek - Enable audio jacks of Haier Boyue G42 with ALC269VC 2024-04-27 17:11:38 +02:00
tools selftests/seccomp: Handle EINVAL on unshare(CLONE_NEWPID) 2024-05-02 16:32:42 +02:00
usr
virt KVM: Always flush async #PF workqueue when vCPU is being destroyed 2024-04-03 15:28:18 +02:00
.clang-format
.cocciconfig
.get_maintainer.ignore
.gitattributes
.gitignore
.mailmap 20 hotfixes. 12 are cc:stable and the remainder address post-6.5 issues 2023-10-24 09:52:16 -10:00
.rustfmt.toml
COPYING
CREDITS
Kbuild
Kconfig
MAINTAINERS ALSA: scarlett2: Rename scarlett_gen2 to scarlett2 2024-04-27 17:11:36 +02:00
Makefile Linux 6.6.29 2024-04-27 17:11:44 +02:00
README

README

Linux kernel
============

There are several guides for kernel developers and users. These guides can
be rendered in a number of formats, like HTML and PDF. Please read
Documentation/admin-guide/README.rst first.

In order to build the documentation, use ``make htmldocs`` or
``make pdfdocs``.  The formatted documentation can also be read online at:

    https://www.kernel.org/doc/html/latest/

There are various text files in the Documentation/ subdirectory,
several of them using the Restructured Text markup notation.

Please read the Documentation/process/changes.rst file, as it contains the
requirements for building and running the kernel, and information about
the problems which may result by upgrading your kernel.