I've been trying to write a simple hello world kernel module in Rust, but none of the examples available on GitHub appear to be working.
Could somebody write a simple hello world. module that actually compiles and works?
Have you compiled your kernel with rust support enabled? If so GitHub - Rust-for-Linux/rust-out-of-tree-module: Basic template for an out-of-tree Linux kernel module written in Rust. should work. If that doesn't work can you post the error? If you haven't enabled CONFIG_RUST
when compiling the kernel, the crates that will be used by the rust kernel module are not compiled and linked into the kernel and as such it doesn't work.
Thanks for the tip.
If I compile a bare bones version of the kernel module and don't use any specific kernel API, would I be able to successfully load that kernel module into older versions of the kernel on other systems?
Not really. All rust code depends on libcore, which rust-for-linux links into the kernel, not the kernel module. As such you will get an error about missing symbols if you try to load the kernel module in a kernel not compiled with rust support. There have been demos of rust kernel modules that are fully out-of-tree and thus would work without a rust enabled kernel, but I don't recall where to find those and I believe they aren't getting updated anymore.
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.