2 ms·
You're making it sound like the C language has changed - it hasn't. I think this operation has been undefined in C as long as Linux has existed. They should not
by chrisseaton 8y ago
You're making it sound like the C language has changed - it hasn't. I think this operation has been undefined in C as long as Linux has existed. They should not have written that code in the first place - it was never correct.
- wruza 8y agoThey maybe should not have written code in C at all, since the language that you need hire a lawyer for is not a viable option. But everyone hoped that with a given team they could create something that both will meet requirements and be future-proof. While what they did was not really legal, it is not practical to make it not work anymore. If they did it right way, Linux would not exist, see? Lawyers don’t build anything.
- Filligree 8y agoMaybe they shouldn't have, but there was no realistic alternative. At the time, C compilers weren't as "smart" and the sort of trickery they're doing was a perfectly reasonable thing to try in C. Today, if you were starting a kernel project from scratch, I'd think Rust would deserve a good, hard look.
- Sharlin 8y agoDo you really not grok the difference between writing platform-independent code and writing the platform itself? You don't write for an abstract machine as specified by the standard, you're writing for a very concrete real-world machine in order to implement a part of that abstract machine. Indeed, that's exactly what C was created for in the first place, for writing an OS in something else than assembly!
- deleted 8y ago[deleted]
- kjeetgill 8y agoAt some level you have to eventually decide, "if it works it works." Obviously at the application level it's frowned upon, but in the kernel? You do what you have to with the tools you have. Think about Java. Yea sure, keep telling us sun.misc.Unsafe isn't legit. It's going to get use until that capability exists elsewhere.
- saagarjha 8y ago> Obviously at the application level it's frowned upon, but in the kernel? I'd rather my kernel not have a security hole in it because a compiler decided to optimize out undefined code: https://lwn.net/Articles/342330/ https://lwn.net/Articles/342330/
- pjmlp 8y agoAnd as the ongoing Linux Kernel Self Preservation Project proves, those tools are not enough. I appreciate using software that is actually written with security first, performance second in mind.
- CJefferson 8y agoThere seems to be two possibilities here: 1) you have rightly pointed out all the authors of the Linux kernel are total idiots who don't understand C. 2) It turns out writing a kernel isn't possible in pure C, and the kernel requires some carefully designed and considered methods of accessing all of raw memory, in various unusual ways.
- chrisseaton 8y ago> It turns out writing a kernel isn't possible in pure C This one is the case. Writing a kernel is not possible in pure C. I'm asking - given this, why are they trying to do that? Write the parts which aren't expressible in C using assembly, where they can get the semantics they want.
- CJefferson 8y agoThe reason is that by restricting yourself to gcc and clang, and agreeing how to define some undefined parts of C with those compiler authors, the amount of assembly you need drops massively, which is particularly useful when you are trying to support as many architectures as Linux. While technically this means your kernel is "gcc c" rather than "true c", this doesn't cause a practical problem. I know gcc, clang and visual studio's c++ standard libraries require a flat address space and 8 bit bytes, for example, but I've never seen anyone bothered by this.
- saagarjha 8y ago> the amount of assembly you need drops massively How about this as a compromise: use GCC, with all its flags, to generate the assembly, and just use that? Skip the messy transition step.
- 0xADD1E 8y agoAnd what would this change, if authors are working off of the GCC-C files? If you're after a system by which you don't need GCC to run Linux, you may be interested in a concept known as "binaries" which sounds remarkably close to what you're trying to invent here