rustc-1.62: allow to build out-of-tree kernel modules in Rust
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
rustc-1.62 (Ubuntu) |
Fix Released
|
Undecided
|
Unassigned | ||
Jammy |
New
|
Undecided
|
Unassigned | ||
Lunar |
Fix Released
|
Undecided
|
Unassigned |
Bug Description
[Impact]
Rust 1.62 is required by the kernel to provide the proper infrastructure to build kernel modules (in Rust).
Unfortunately trying to build an out-of-tree kernel module in Rust gives an error like the following:
error[E0461]: couldn't find crate `core` with expected target triple target-
|
= note: the following crate versions were found:
crate `core`, target triple target-
It is possible to workaround this problem by downloading the kernel source, copying the right config and running a `make modules_prepare`.
However, this is not an appropriate method for distributing Rust support in the kernel. A more suitable approach would be to use the data provided by the linux-headers package and build out-of-tree kernel modules by simply running "make".
[Test case]
Install the latest lunar/linux 6.2 kernel and try to build a simple hello world kernel module in Rust out-of-tree.
[Fix]
The reason of this problem is that rustc generates the target triple using the path of target.json, instead of the content of target.json. So during the build of linux-headers in the ppa the absolute path of target.json is completely different than the path of the same file when linux-headers is installed, causing a different target triple hash number, therefore rustc detects a mismatch when trying to link against the Rust libraries provided by the kernel.
The solution is generate the target triple using the content of target.json. This change has been merged upstream in rustc, starting with 1.63. However we can't upgrade rustc to 1.63, because the kernel is still enforcing the constraint of using rustc == 1.62.
Therefore the proper solution is to apply only the patch that changes the target triple generation to use the content of target.json.
See also: https:/
[Regression potential]
Changing the target triple generation behavior can potentially break users of rustc-1.62. However, considering that the only user of rustc-1.62 is the kernel itself, there is basically zero risk of regressions (there's no reason for any other user to use rustc-1.62, since they can use the stock rustc provided in Ubuntu).
ProblemType: Bug
DistroRelease: Ubuntu 23.04
Package: rustc-1.62 1.62.1+
ProcVersionSign
Uname: Linux 6.2.0-16-generic x86_64
ApportVersion: 2.26.0-0ubuntu2
Architecture: amd64
CasperMD5CheckR
Date: Sun Mar 12 22:37:28 2023
InstallationDate: Installed on 2022-07-25 (230 days ago)
InstallationMedia: Ubuntu 22.10 "Kinetic Kudu" - Alpha amd64 (20220724)
SourcePackage: rustc-1.62
UpgradeStatus: Upgraded to lunar on 2023-02-11 (29 days ago)
tags: | added: patch |
Changed in rustc-1.62 (Ubuntu Lunar): | |
status: | New → Fix Committed |
debdiff in attach allows to properly build out-of-tree kernel modules using rustc-1.62, without "refreshing" the content of linux-headers using `make modules_parepare` and without downloading the whole kernel source code (but only using the content provided by linux-headers).