You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Out-of-tree module failed to build if the kernel source path is different #792
As most of the Linux distribution install the kernel with their package (.deb, .rpm, ...). I also tried to do the same thing to test Linux kernel with Rust support. However, when I build some out-of-tree Rust kernel module, it failed to compile with the following message:
error[E0461]: couldn't find crate `core` with expected target triple target-13637732820183936185
|
= note: the following crate versions were found:
crate `core`, target triple target-4719486650351723570: /usr/src/linux-headers-5.18.0-rc2-2-rust/rust/libcore.rmeta
error[E0461]: couldn't find crate `compiler_builtins` with expected target triple target-13637732820183936185
|
= note: the following crate versions were found:
crate `compiler_builtins`, target triple target-4719486650351723570: /usr/src/linux-headers-5.18.0-rc2-2-rust/rust/libcompiler_builtins
.rmeta
error[E0461]: couldn't find crate `kernel` with expected target triple target-13637732820183936185
--> /home/leo/rust-kernel-modules/rust-random/rust_random.rs:11:5
|
11 | use kernel::{
| ^^^^^^
|
= note: the following crate versions were found:
crate `kernel`, target triple target-4719486650351723570: /usr/src/linux-headers-5.18.0-rc2-2-rust/rust/libkernel.rmeta
P.s. I think that this is the problem of the compiler, however, this issue must be resolved if we want to support out-of-tree Rust kernel module in the future.
Now with Rust 1.63.0, which btw hasn't required further patching, I could confirm that I'm able to build out of tree modules with the kernel build system using v9 of the patchset.
$ make KDIR=/lib/modules/5.19.1-arch2-1/build LLVM=1
make -C /lib/modules/5.19.1-arch2-1/build M=$PWD
make[1]: Entering directory '/usr/lib/modules/5.19.1-arch2-1/build'
RUSTC [M] ~/Codes/Rust/Tests/kernelmoduletest/printk/rust_printk.o
MODPOST ~/Codes/Rust/Tests/kernelmoduletest/printk/Module.symvers
CC [M] ~/Codes/Rust/Tests/kernelmoduletest/printk/rust_printk.mod.o
LD [M] ~/Codes/Rust/Tests/kernelmoduletest/printk/rust_printk.ko
BTF [M] ~/Codes/Rust/Tests/kernelmoduletest/printk/rust_printk.ko
die__process_class: tag not supported 0x33 (variant_part)!
die__process_class: tag not supported 0x2f (template_type_parameter)!
make[1]: Leaving directory '/usr/lib/modules/5.19.1-arch2-1/build'
Said module, alongside a C counterpart, was tested in a QEMU VM, both loading and removing work as expected. If Rust 1.63.0 becomes mandatory then this issue can be closed indeed.
Activity
bjorn3 commentedon Jun 17, 2022
Yeah, I think rustc should hash the file contents rather than the file path.
Rollup merge of rust-lang#98225 - bjorn3:stable_target_json_hash, r=n…
Rollup merge of rust-lang#98225 - bjorn3:stable_target_json_hash, r=n…
bjorn3 commentedon Jun 20, 2022
rust-lang/rust#98225 has landed. This issue should be fixed in rustc 1.63.0.
ojeda commentedon Jun 20, 2022
Thanks a lot @bjorn3!
Leo1003 commentedon Jun 22, 2022
Thank you for fixing this issue which troubled me for a long time!
YakoYakoYokuYoku commentedon Aug 14, 2022
Now with Rust 1.63.0, which btw hasn't required further patching, I could confirm that I'm able to build out of tree modules with the kernel build system using v9 of the patchset.
Said module, alongside a C counterpart, was tested in a QEMU VM, both loading and removing work as expected. If Rust 1.63.0 becomes mandatory then this issue can be closed indeed.
bjorn3 commentedon Aug 14, 2022
Thanks for confirming the fix @YakoYakoYokuYoku! @ojeda will probably update to Rust 1.63.0 soon.
ojeda commentedon Oct 29, 2024
Nowadays we require a way higher version.