I’m trying to figure out how feasible it would be to use Rust for Linux kernel development. I’d love to be able to hack the kernel in a language that’s more high-level and safe than C. Looks like getting started is not straightforward, though.
My problem is very similar to that discussed in this thread. However, I’m trying to write a kernel module for Linux, not FreeBSD, so I figured it might be better to open a new thread instead of reviving the old one.
For now, my code simply defines a
rust_add function that is called from the kernel module’s entry point (written in C). As the name suggests, this function adds its two
i32 arguments and returns the result. For reference, here is the code.
Loading this module fails, however. This is the dmesg output:
hello: Unknown symbol __muloti4 (err 0)
hello: Unknown symbol __floatundidf (err 0)
hello: Unknown symbol __floatundisf (err 0)
hello: Unknown symbol __umodti3 (err 0)
hello: Unknown symbol __udivti3 (err 0)
There were more unknown symbols previously, e.g.
memcmp, but I could resolve this by including the
I am linking with
--gc-sections, which doesn’t help, so it seems like those symbols are actually used by my Rust code. What I figured out so far is that it must be because of panic handling, specifically integer overflow checking. If I let
rust_add return a constant instead of the sum, those symbols are not present in the final binary and it loads just fine. Similarly, if I compile in release mode everything works as well, since overflow checking is disabled there. I don’t know, however, what kind of panic handling would require these kinds of functions. AFAICT they are (soft) floating point and 128-bit integer operations.
I checked the
compiler-builtins crate, which implements most but now all of the missing functions, so it wouldn’t solve the problem. The only other solution I can think of is mocking the missing functions with dummy implementations. But I don’t feel comfortable doing this if they can actually be called at runtime. Is there anything else I could try?