Rust support hits linux-next
Posted Mar 19, 2021 15:17 UTC (Fri)
by kragil (guest, #34373)
[Link]
Posted Mar 19, 2021 16:12 UTC (Fri)
by darwi (subscriber, #131202)
[Link] (4 responses)
A lot of standard kernel abstractions and APIs are not yet "rustified" at all.
Having a character driver is also not the most encouraging of examples: adding new character drivers to the kernel is really frowned upon — real drivers need way much more functionality than just FileOperations, a Mutex, and an (incomplete) SpinLock API. Nonetheless, the merge to -next is of course a very encouraging sign.
Posted Mar 20, 2021 0:04 UTC (Sat)
by ndesaulniers (subscriber, #110768)
[Link]
Posted Mar 20, 2021 2:33 UTC (Sat)
by willy (subscriber, #9762)
[Link] (2 responses)
Maybe they're still working on it!
Posted Mar 20, 2021 13:16 UTC (Sat)
by atnot (subscriber, #124910)
[Link] (1 responses)
Posted Mar 20, 2021 14:00 UTC (Sat)
by willy (subscriber, #9762)
[Link]
The advantage of writing an actual driver for hardware that really exists is that you figure out what's missing from the kernel Rust API -- interrupts, PCI, DMA, locks that need to be shared with code written in C. That kind of thing.
Posted Mar 19, 2021 22:02 UTC (Fri)
by flussence (guest, #85566)
[Link] (13 responses)
If I had to guess, nothing much is going to come of this for maybe 2-3 years. By then I'd expect GCC to have a Rust frontend and everything can be business as usual.
Posted Mar 20, 2021 14:10 UTC (Sat)
by adobriyan (subscriber, #30858)
[Link] (12 responses)
Posted Mar 20, 2021 19:06 UTC (Sat)
by stevenrwalter (guest, #128616)
[Link] (11 responses)
Posted Mar 20, 2021 22:18 UTC (Sat)
by adobriyan (subscriber, #30858)
[Link] (10 responses)
I can't even push trivial stuff like renaming few "this" identifiers, so no.
> Also C++ is not source-compatible with C
C++ is maximally source compatible with C which automatically makes it the best
Trivial sources of source incompatibility come from casts and keywords
The most difficult sources of incompatibility don't come from C99 initialisers
If someone knows how C++ people deal with macrology/features above, please tell me.
Modules also have a _lot_ of icky macros as does tracing. I don't even want to think about it.
The biggest problem so far is g++ being so eager to shift compile time initialisation
That one different oops was int/long confusion in ERR_PTR rewrite.
C99 caluse shuffling is very dangerous when rebasing. It is so easy to mismerge stuff and
Posted Mar 20, 2021 22:24 UTC (Sat)
by adobriyan (subscriber, #30858)
[Link]
Posted Mar 21, 2021 4:00 UTC (Sun)
by nyanpasu64 (guest, #135579)
[Link] (1 responses)
C++20 has the constinit keyword to enforce compile-time initialization of a data structure (designed to avoid the static initialization order fiasco), but I don't think it's coming to C anytime soon. I think it might solve your problem with gcc or g++, but I'm not confident.
Posted Mar 22, 2021 15:02 UTC (Mon)
by adobriyan (subscriber, #30858)
[Link]
What's needed is compiler flag to disable dynamic initialisation or
Posted Mar 21, 2021 21:42 UTC (Sun)
by moltonel (guest, #45207)
[Link] (4 responses)
This is debatable. Some very smart and knowledgeable Linux devs still give C++ a firm "No", while they're giving Rust a cautious "Maybe". You shouldn't ignore that hint.
Any tech shift needs a high gain-over-cost ratio. While the cost of enabling C++ build in a C project is indeed very low, the gains are (in Linux's case, and compared to Rust) not amazing either, and the inadvertent compatibility issues can negate a lot of the gains. Which leads to another counter-argument: being source-incompatible might actually be a good thing, as the clear demarcation between the C world and the Rust world could be more manageable than the fuzzy C/C++ demarcation.
The jury is still out on Linux-Rust, but Linux-C++ looks like a well-beaten dead horse.
Posted Mar 22, 2021 11:10 UTC (Mon)
by Wol (subscriber, #4433)
[Link] (3 responses)
We've had that discussion elsewhere. Linux needs a low-level language, and probably the best definition of such a language is "it doesn't give the optimiser many options". The linux devs don't like getting bitten by optimisations where the compiler "assumes facts not in evidence", and C++ adds far too many features that enable exactly that.
I gather Rust has been designed as a low-level language, and as such is currently much better than C, which has steadily been acreting hi-level features. That's not to say it'll *stay* a low-level language, but at present Rust is actually probably a far better language than C for system-level programming.
Cheers,
Posted Apr 27, 2021 14:25 UTC (Tue)
by nix (subscriber, #2304)
[Link] (2 responses)
That's a fairly ridiculous characterization. By any standard, Rust is much higher-level than C: you name it, language-wise it has way more advanced features and permits a higher level of abstraction than C does. What it also has is more consistency (fewer implementation-defined edge cases).
Posted Apr 27, 2021 16:21 UTC (Tue)
by Wol (subscriber, #4433)
[Link] (1 responses)
I've come to the conclusion that a good low-level language "does not give the compiler much opportunity to optimise well-written code". It seems most problems with C (for the kernel at least) are caused by the compiler optimising the hell out of it.
So long as high-level constructs map cleanly to the obvious underlying machine/assembler code, I'd call that a "good low-level language".
Cheers,
Posted Apr 27, 2021 17:01 UTC (Tue)
by mathstuf (subscriber, #69389)
[Link]
That said, I don't know Rust's guarantees around reordering statements, but given the more explicit "I'm using a single variable across threads" model, there are likely a lot fewer ways the compiler can think to order things (barring bugs in the compiler, but that's C's problem too).
Posted Mar 22, 2021 0:30 UTC (Mon)
by flussence (guest, #85566)
[Link] (1 responses)
Objective-C would be a much better candidate by that criteria.
Posted Mar 22, 2021 15:17 UTC (Mon)
by adobriyan (subscriber, #30858)
[Link]
Posted Mar 20, 2021 22:12 UTC (Sat)
by amarao (guest, #87073)
[Link]
I'd like to see more polished base, where all kernel grind been enveloped in a higher level abstractions.
Posted Mar 21, 2021 20:06 UTC (Sun)
by julesb (guest, #139334)
[Link] (8 responses)
Posted Mar 24, 2021 22:06 UTC (Wed)
by Subsentient (guest, #142918)
[Link] (7 responses)
Posted Mar 25, 2021 10:05 UTC (Thu)
by farnz (subscriber, #17727)
[Link] (5 responses)
Out of interest, what issues do you see in the culture around Rust? I'm curious, because I like the culture around Rust a lot more than I like the culture around C and C++, but that may be bias because of how I got introduced to the two sets of cultures.
Posted Apr 16, 2021 12:14 UTC (Fri)
by LtWorf (subscriber, #124958)
[Link] (4 responses)
Posted Apr 16, 2021 13:15 UTC (Fri)
by farnz (subscriber, #17727)
[Link] (3 responses)
Of those, cargo and dynamic linking are technical, not culture. Pinning dependencies is culture, but I'd like to know where it happens because mostly people pin semver versions, not dependencies.
Posted Apr 16, 2021 22:30 UTC (Fri)
by LtWorf (subscriber, #124958)
[Link] (2 responses)
The choice was made exactly to have this culture, so it's not really a technical choice.
Posted Apr 17, 2021 12:36 UTC (Sat)
by mathstuf (subscriber, #69389)
[Link]
Hmm. Are there any links you have to back this up? AFAIK, it's because defining an ABI now would tie their hands for future improvements that are wanted (e.g., better structure packing, new sentinel representations for stdlib types, etc.), but haven't been implemented yet. I suspect a symbol versioning set of attributes would likely also be in order.
Posted Apr 17, 2021 14:58 UTC (Sat)
by farnz (subscriber, #17727)
[Link]
All the discussions I can find on dynamic linking Rust say it works just fine, it's just that there's no stable Rust ABI yet - you have to have a C ABI if you want to be dynamically linked. They then go into technical reasons why there is no stable Rust ABI yet.
I cannot find anything to back your claim that the choice was made exactly to have this culture - rather that the choice has been made for sound technical reasons (and it's the same reason you can't dynamically link a lot of C++ code like the C++ STL too), and that if a good technical solution can be found, then dynamic linking will be revisited.
Posted Mar 25, 2021 23:13 UTC (Thu)
by mathstuf (subscriber, #69389)
[Link]
Rust support hits linux-next
There is also an example character driver at drivers/char/rust_example.rs
Rust support hits linux-next
Rust support hits linux-next
Rust support hits linux-next
Rust support hits linux-next
Rust support hits linux-next
Rust support hits linux-next
Rust support hits linux-next
Rust support hits linux-next
Rust support hits linux-next
candidate for upgrading to a more capable programming language.
(people like plain "new" very much) but they can be scripted away.
I mean Googlers who posted Rust to linux-next are surely capable of it.
(which can be rearranged) but from code like this:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/...
to runtime. So far all oopses but one in my little Linux++ project were caused by this:
empty system call table, empty paravirt ops and empty protection_map[] array.
omit or double init. Double init is tolerable because g++ complains but omission is silent.
The best part was min/max rewrite. I liked it so much.
Rust support hits linux-next
template<typename T, typename... Ts>
constexpr T min(T a, T b, Ts... etc)
{
if constexpr (sizeof...(Ts) == 0) {
return (a < b) ? a : b;
} else {
return min(min(a, b), etc...);
}
}
Rust support hits linux-next
> to runtime. So far all oopses but one in my little Linux++ project were caused by this:
> empty system call table, empty paravirt ops and empty protection_map[] array.
Rust support hits linux-next
equivalent of "nm vmlinux | grep -e _GLOBAL__sub_I_".
The latter would have saved me a lot of time. :-\
Rust support hits linux-next
Rust support hits linux-next
Wol
Rust support hits linux-next
Rust support hits linux-next
Wol
Rust support hits linux-next
Rust support hits linux-next
> candidate for upgrading to a more capable programming language.
I don't know Objective-C. How big is the flag day patch? The one which contains the following chunk:
Rust support hits linux-next
-CC = $(CROSS_COMPILE)gcc
+CC = $(CROSS_COMPILE)g++
Rust support hits linux-next
Rust support hits linux-next
Rust support hits linux-next
Rust support hits linux-next
Rust support hits linux-next
Rust support hits linux-next
Rust support hits linux-next
Rust support hits linux-next
Rust support hits linux-next
Rust support hits linux-next