Live data from Hacker News

C++ in the Linux Kernel

threatstack.com

11–20 of 102 posts

Re: C++ in the Linux Kernel

#11
> I found the real gold mine of C++ kernel module development knowledge in OSDev.org. They have an entire article on C++ issues. That includes avoiding templates

No, it doesn't?!? The linked article mentions templates two times (+ 2 mentions of the standard template library), once saying that templates can be used without further setup and the other times recommending that some template based data structures should be implemented. That's pretty far from "avoiding templates".

Re: C++ in the Linux Kernel

#14

> You see the problem. My C++ code expected the calling convention that pushed arguments on the stack, that would be very weird on Linux. The x86_64 linux ABI mandates that the first arguments go on registers afaik (I'm assuming x86_64 here since the post mentions linux distros which are overwhelmingly x64). What compiler would default to a pure stack-based calling convention ? Certainly not GCC or clang, no ? > and…

Perhaps the article is old enough to have been written in the 32-bit era?

The Page Info I see says this:

> article:published-time 2016-10-28T11:40:06+00:00

which is well into the era of 64-bit code.

Re: C++ in the Linux Kernel

#15

> A first-year computer science student can tell you that the arguments get pushed onto the stack. In other words, a call to this 3GL function results in the following assembly pseudo code Are people this ignorant when it comes to C/C++ or any systems language? ABI & calling conventions were introduced early in my C & C++ textbooks (age 13 btw, not even close to college years).

Well, if you believed as the author did that arguments are always pushed onto the stack, you are pretty ignorant--most major architectures these days don't use the stack for arguments, at least not for the first several arguments.

(Semi-random tangent: the hardest bug I ever had the pleasure of debugging was when I discovered that the PLT glue code to load an entry into the PLT was unexpectedly clobbering a register that the calling convention said needed to be preserved. By very, very careful using non-default calling conventions across shared object boundaries!)

Re: C++ in the Linux Kernel

#17
post #4

I guess Rust is far better choise for that.

Community wise, yes. It seems to have gained some momentum.

From a technical point of view, I'm not so sure. C++ still interoperate easier with C than Rust, if only because you can normally just include the headers and be done with it. (Although as the article says, there are some cleanup to do.)

Re: C++ in the Linux Kernel

#18
post #5

Lol, part of me likes the effort taken just because, but the kernel devs _really_ do not want C++. One hint: "struct class" https://elixir.bootlin.com/linux/latest/source/include/linux...

as long as nothing you're including includes that in c++, it shouldn't be an issue at the linker level, and thus not be an issue at all.

at least in general - if it's something that can't handled by a c shim then you might have an issue.

Re: C++ in the Linux Kernel

#19

> You see the problem. My C++ code expected the calling convention that pushed arguments on the stack, that would be very weird on Linux. The x86_64 linux ABI mandates that the first arguments go on registers afaik (I'm assuming x86_64 here since the post mentions linux distros which are overwhelmingly x64). What compiler would default to a pure stack-based calling convention ? Certainly not GCC or clang, no ? > and…

> so, how is that a problem with C++ and not [...]

I don't think you should see this article as a criticism of C++. Just a rent on how hard it is to use in the Linux kernel which is openly against it.

Re: C++ in the Linux Kernel

#20
post #5

Lol, part of me likes the effort taken just because, but the kernel devs _really_ do not want C++. One hint: "struct class" https://elixir.bootlin.com/linux/latest/source/include/linux...

as long as nothing you're including includes that in c++, it shouldn't be an issue at the linker level, and thus not be an issue at all. at least in general - if it's something that can't handled by a c shim then you might have an issue.

It's one of the most fundamental structures in the kernel. Pretty much all driver headers include it, if indirectly.
Post reply on HN