6 ms·
> Linux kernel is written in C Not exclusively in C, not anymore: https://docs.kernel.org/rust/index.html https://docs.kernel.org/rust/index.html It might tak
by nousermane 4y ago
> Linux kernel is written in C
Not exclusively in C, not anymore: https://docs.kernel.org/rust/index.html https://docs.kernel.org/rust/index.html
It might take another decade for a C-free build to be possible, though.
- c7DJTLrn 4y agoOnly a decade? I don't think so. AFAIK Torvalds has also stipulated that any Rust code needs to be mirrored in C.
- deleted 4y ago[deleted]
- michaelsshaw 4y agoThis right here. Rust only JUST got added to the kernel in 6.0 and I doubt that it will replace 30 years of C development any time soon.
- mustache_kimono 4y ago> AFAIK Torvalds has also stipulated that any Rust code needs to be mirrored in C. Do you have a cite for this? I hadn't heard this at all.
- c7DJTLrn 4y agoApologies, I can't find a source. I probably read it on LWN somewhere. Linus wouldn't dip both feet into the water at the same time. I'm confident he's said that the kernel needs to be buildable without Rust if need be.
- mustache_kimono 4y ago> I'm confident he's said that the kernel needs to be buildable without Rust if need be. FWIW that's not the same thing? That's simply CONFIG_RUST=n, not "You have to write this driver twice in two different languages".
- unwind 4y agoWow that sounds fantastically optimistic, or pessimistic depending on your point of view I guess. Rewriting that amount of code in ten years sounds very very hard, at least.
- ImprobableTruth 4y agoThey said a C-free build. For that you'd need to "just" rewrite the core kernel, which will be 150-200k lines, and the drivers + arch specific parts for one system. Still a tall order, but a decade isn't unrealistic if Rust proves itself. Now, rewriting everything, including all the legacy drivers? Yeah, never happening even if Rust succeeds utterly.
- chillingeffect 4y agoOnce they get to that point, a new language will be available that makes up for the things Rust is still short on.
- Sakos 4y agoMaybe there's a case to be made for a multi-language kernel. Rust is the first step. Maybe it'll make sense at some point to keep Rust, but add another language.
- tristanbvk 4y agoI don't see such a feat taking place in the next decade, you need highly dedicated people. I can see new code being written in Rust but a C free build sounds like something that really won't be happening anytime soon. I wish something like it could happen, but I am causyiously optimistic.
- Sakos 4y agoA significant amount of the lines of code in the kernel are for drivers (7 of 12 million lines?). A potential strategy would be to set a date where any new drivers must be written in Rust. Deprecate every non-Rust driver on a date after that. Focus on rewriting only the drivers necessary for current hardware platforms (and some sensible/arbitrary cut-off going back x years). Then set a final deadline for a New Linux kernel release that removes all deprecated/C drivers. I would blindly estimate that entire process to take 10-20 years (not including the time needed for debating the whole thing). Then somebody "just" needs to rewrite the rest of the code. So, uh, any volunteers?
- attractivechaos 4y agoThe Linux kernel comes with many old drivers that modern programmers have little knowledge about. It is probably more realistic to write a new kernel in rust (like Redox), targeting modern machines only.
- timbit42 4y agoBy the time it's rewritten in Rust, old drivers will be dropped due to lack of demand for them.
- tmtvl 4y agoAs long as there isn't a Rust compiler written in Rust (there is a transpiler to LLVM bytecode, but that gets compiled by a C++ compiler, same for GCC-rs) I don't think a C-free (or a C++-free) build will be possible at all, so I'm guessing it'll take somewhere in the 60-100 year range.
- ansible 4y agoThere are some open issues and features like inline assembly that aren't supported, but a moderately complete backend exists now: https://github.com/bjorn3/rustc_codegen_cranelift https://github.com/bjorn3/rustc_codegen_cranelift The compiler frontend is already written in Rust.
- estebank 4y agoHonest question: what would the engineering rationale be behind dropping LLVM entirely and have rustc have its own code generation backend? There are two out there that might be interesting, one uses gcc and another is called cranelift, but it isn't the default and focuses exclusively on compilation speed for debug binaries.
- tmtvl 4y agoWell people keep telling me that C/C++ code should be replaced by Rust for ~safety~ reasons, and LLVM is a C++ project, so... Let's say it would avoid all the memory bugs in LLVM, that would doubtlessly make it worth throwing away the LLVM implementation (avoid sunk cost fallacy).
- tialaramex 4y agoIf anything, it's more likely that the desirable choice is to shift LLVM to Rust.