News for hackers. Stuff that matters.
Re:Rust support in the Linux kernel by megous on Wednesday December 08, 2021 @12:13PM (#29487421)
I just really hope this thing will not be a bitch to cross-compile. I'm not interested in building llvm + rust in addition to my 5 or so gcc cross-compilers, especially looking at the cadence of rust releases.

So as long as it will be possible to use the system's llvm+rust to build for all 4 CPU archs (at once) I'm currently building my kernels for, I'll probably not be too cranky about rust in the kernel.

Re:Rust support in the Linux kernel by kelnos on Wednesday December 08, 2021 @03:02PM (#29489711)
Cross-compilation with Rust is fairly trivial; it's just a matter of "rustup target add some-host-triple".

GCC's cross-compilation story is indeed a nightmare. I expect if you have to use the GCC Rust backend (after it's ready) for arches rustc/LLVM don't support, you'll have that pain, but I expect it will just be a matter of adding an "--enable-language rust" to the GCC configure script run, similar to adding C++, ObjC, etc. to a GCC build. So the cross-compiler build will take longer, but won't involve extra steps or infrastructure.

Re:Rust support in the Linux kernel by megous on Wednesday December 08, 2021 @06:56PM (#29492194)
Binutils/gcc cross-compiler can be built rather quickly, once you know the right configure flags for each. Then it's just make && make install. You can speed the buil considerably by building with -g0 and not doing a bootrstrap or building needless targets.

Then you have a cross-compiler in some --prefix that you can point the kernel build system to via some environment variables and you're done. It's a well known process.

It's basically built just like any other dependency and doesn't take much time.

Hardly a nightmare. If it would be possible to just add rust to the list of gcc languages, that would indeed be very easy.

Re:Rust support in the Linux kernel by lambda on Wednesday December 08, 2021 @03:20PM (#29489946)
Cross compilation is actually much easier with Rust than it is with gcc. Every Rust compiler is a cross-compiler for all architectures that Rust supports; all you need is the rest of the toolchain like linker and libraries. rustup handles installing the libraries, and as lld (the LLVM linker) adds support for more platforms it can also be used as a cross linker, rather than a linker per target as in the older toolchains.
Re:Rust support in the Linux kernel by floatboth on Wednesday December 08, 2021 @01:46PM (#29488683)
LLVM is always inherently a "cross-compiler". In fact having to have "5 or so compilers" is just GCC being stupid.
Re:Rust support in the Linux kernel by megous on Wednesday December 08, 2021 @03:07PM (#29489764)
Good. :)
Re:Rust support in the Linux kernel by duped on Wednesday December 08, 2021 @01:21PM (#29488354)
Cross compiling with Rust is actually not that bad.
Re:Rust support in the Linux kernel by b20000 on Wednesday December 08, 2021 @12:34PM (#29487746)
what if your driver or user space app is affected by a poorly architected driver which was written in rust? now you need to deal with that rust source code. a true nightmare.
Re:Rust support in the Linux kernel by dagmx on Wednesday December 08, 2021 @12:43PM (#29487858)
Why would that be worse than if it was written in C? A rust codebase would be much easier to find the bugs in and refactor accordingly, than in C.

Plus it's not like most people are going to dive into driver code without experience in the driver itself. So it's a niche set of folks this would affect, the majority of whom would likely be writing the rust code anyway since they're likely the ones most familiar with the driver aspects.

Re:Rust support in the Linux kernel by kbenson on Wednesday December 08, 2021 @01:00PM (#29488091)
People have said the same thing about every language. I'm positive people complained about using C over assembly (people still do for certain things).

I ask you to imagine a situation where a kernel is written in assembly, and they decide to start allowing C to be used for drivers. How would you view a change such as that?

Re:Rust support in the Linux kernel by edgyquant on Wednesday December 08, 2021 @01:45PM (#29488673)
There’s a huge difference. Rust syntax is a lot more complex than C, while this isn’t true for C v assembly.
Re:Rust support in the Linux kernel by kbenson on Wednesday December 08, 2021 @02:05PM (#29488916)
The semantics of C and how to write code that is well defined is much more complex than assembly.
Re:Rust support in the Linux kernel by edgyquant on Wednesday December 08, 2021 @09:24PM (#29493085)
I disagree. You can learn the semantics of C in a day, assembly requires a ton more memorization and a ton more code to write. C is more abstract that assembly but it is less complicated, on its face, than assembly or rust.
Re:Rust support in the Linux kernel by kbenson on Thursday December 09, 2021 @01:21AM (#29494440)
If you're familiar enough with programming to learn C in a day, you can learn assembly in a couple hours. It's really not that complicated. You can copy to/from memory addresses to local temp variable containers that are various sizes of bits (registers), you can do various math operations on those bits in those registers, you can compare those registers and test that comparison, and you can jump from the current point in the code to any other point by label or address (go-to). Sometimes operations will result in other registers you can check to see if something happened (overflow). The OS will provide some interrupts to do some base things as interrupts such as IO.

If you didn't know how to code in assembly already, you now know enough to do everything C can do with a simple reference sheet. All the extra boilerplate (such as program segments and where to store costants such as what the 'strings' program sees in a binary) you can read two to three pages to explain what you need for whatever OS you're on.

Assembly isn't hard, it's just tedious.

Re:Rust support in the Linux kernel by formerly_proven on Wednesday December 08, 2021 @02:33PM (#29489305)
C is easy to read and follow though. Rust has far more syntax and as a language is way beyond the complexity of C.
Re:Rust support in the Linux kernel by nicoburns on Wednesday December 08, 2021 @03:14PM (#29489844)
Only if you know C but not Rust. I personally find Rust fairly easy to follow and C a complete nightmare (the details in C are ok, but it's really hard to see the forest for the trees).
Re:Rust support in the Linux kernel by edgyquant on Wednesday December 08, 2021 @09:26PM (#29493094)
I know C and can get by in Rust and I disagree that rust is easier to follow. C is a simple language, the complexity comes from large systems, while Rust is just not.
Re:Rust support in the Linux kernel by nicoburns on Thursday December 09, 2021 @07:53AM (#29496795)
Well I know Rust and I can get by in C. Perhaps that makes a difference.

> C is a simple language, the complexity comes from large systems, while Rust is just not.

I mean I agree that C is simple if you're making a 50 line program that writes to stdout or something. But more often than not with C or Rust you are working with a large complex system. And I'd argue that when working with such a large system, Rust programs are less complex than C programs.

Re:Rust support in the Linux kernel by formerly_proven on Thursday December 09, 2021 @10:05AM (#29498104)
There is a huge difference between reading and writing C. C is very easy to read, but it's quite difficult to write (secure, portable, performant) C. Code is typically read a lot more than it is written. I haven't written a single line of code in torvalds/linux.git but read probably tens of thousands of lines of Linux kernel code over the years. I'd wager that for every kernel developer there are at least 10 people reading the code to figure out how something works, or how it broke.

C makes many questions when reading trivial to answer, questions like "how do I get here?", "where does it go?", "what is this type?" and "what does this code do?" are generally very easy to answer without expert-level C knowledge. From what I've seen, that's not true for rust.