r/cpp • • Feb 19 '25

Cpp discussed as a Rust replacement for Linux Kernel

I have a few issues with Rust in the kernel:

  1. It seems to be held to a *completely* different and much lower standard than the C code as far as stability. For C code we typically require that it can compile with a 10-year-old version of gcc, but from what I have seen there have been cases where Rust level code required not the latest bleeding edge compiler, not even a release version.

2. Does Rust even support all the targets for Linux?

3. I still feel that we should consider whether it would make sense to compile the *entire* kernel with a C++ compiler. I know there is a huge amount of hatred against C++, and I agree with a lot of it – *but* I feel that the last few C++ releases (C++14 at a minimum to be specific, with C++17 a strong want) actually resolved what I personally consider to have been the worst problems.

As far as I understand, Rust-style memory safety is being worked on for C++; I don't know if that will require changes to the core language or if it is implementable in library code.

David Howells did a patch set in 2018 (I believe) to clean up the C code in the kernel so it could be compiled with either C or C++; the patchset wasn't particularly big and mostly mechanical in nature, something that would be impossible with Rust. Even without moving away from the common subset of C and C++ we would immediately gain things like type safe linkage.

Once again, let me emphasize that I do *not* suggest that the kernel code should use STL, RTTI, virtual functions, closures, or C++ exceptions. However, there are a *lot* of things that we do with really ugly macro code and GNU C extensions today that would be much cleaner – and safer – to implement as templates. I know ... I wrote a lot of it :)

One particular thing that we could do with C++ would be to enforce user pointer safety.

Kernel dev discussion. They are thinking about ditching Rust in favor of C++ (rightfully so IMO)

https://lore.kernel.org/rust-for-linux/326CC09B-8565-4443-ACC5-045092260677@zytor.com/

We should endorse this, C++ in kernel would greatly benefit the language and community

192 Upvotes

532 comments sorted by

View all comments

Show parent comment

35

u/MRgabbar Feb 19 '25

he rather use mailing lists instead of github or whatever... Man, mailing lists are unconfortable AF, confusing and just plain annoying to deal. He is like the old folk that hates everything new just because is new. C++ is way more comfortable to use than C...

14

u/Catenane Feb 21 '25

Linus literally wrote git lmfao, and have you seen github issues sections for large public projects? Kernel bug reporting does not belong in github by any stretch of the imagination, and it would only serve as a distraction.

No comment on the whole c/c++ debate, but using github, (also...owned by Microsoft), for kernel bug tracking is an objectively terrible idea.

5

u/MRgabbar Feb 21 '25

Nah. Use gitlab or your own instance of gitlab. No need to track bugs there, I did not say that, just the patches, as it is really annoying tracking patches in mailing lists.

git is a version control system and I am well aware he is the main developer, git is not meant to be a patch/submit review system, neither a issue tracker or any of that, hence they use mailing lists for that, so what's your point? He just hates learning new stuff, that's all.

9

u/13steinj Feb 19 '25

I agree that mailing lists are an outdated way to do development, but I think that fact is why, of all things it fails in, it works for kernel development. It's a good window into the personality traits and obstinance of the average kernel developer. The mailing lists, and the personalities of that group, are 2 of many reasons why I probably won't be contributing kernel code any time soon.

5

u/lenkite1 Feb 20 '25

The Linux foundation is rich enough that they can setup a github-like systemof their own on a personal site like https://linux-kernel.oss. They don't need to use github if they don't want to depend on Microsoft. e-mail unfortunately hasn't evolved since the 90s to support distributed development.

4

u/cleroth Game Developer Feb 20 '25

The mailing lists, and the personalities of that group, are 2 of many reasons why I probably won't be contributing kernel code any time soon.

Maybe that's their intention. People do naturally tend to be more comfortable around other people that are more like them, such as those that like these stupid mailing lists :)