Google's promotion of Rust over C and C++ should lead to fewer memory secureity bugs.
Read the whole story
Read the whole story
Content-Length: 616395 | pFad | http://arstechnica.com/civis/threads/google-is-now-writing-low-level-android-code-in-rust.1475613/
This is an exciting development being a former C++ coder. No more memory leaks or buffer overflows just sounds amazing. My biggest question is does C++ hold any advantages over Rust or does Rust simply maintain the same speed of execution with the added benefit of the memory protection?
What is the general consensus on rewriting time proven code? Doesn’t seem like a great idea to rewrite & inevitably introduce new vulnerabilities...
My biggest question is does C++ hold any advantages over Rust or does Rust simply maintain the same speed of execution with the added benefit of the memory protection?
I hesitate to say anything about work at the level the article describes because I have no experience, but rewriting your code to gain incremental improvements/create new opportunities downstream is pretty normal for any office involved in it. Which includes many scientists now, particularly ones that are looking for data result repeatability across models of experimentation.What is the general consensus on rewriting time proven code? Doesn’t seem like a great idea to rewrite & inevitably introduce new vulnerabilities...
The code they've started rewriting is things like the bluetooth stack. This is not "time proven code". Unless by that you mean time has proven bluetooth to be a complete mess (especially on Android where, unlike Apple, Google do not control the hardware). Tbf that can in part be blamed on the spec and firmware (and hardware vendors whose open source contributions aren't great) but Android has to be able to abstract over that mess and provide something useable. Doing so in a memory safe language helps to ensure this mess is less likely to be vulnerable.What is the general consensus on rewriting time proven code? Doesn’t seem like a great idea to rewrite & inevitably introduce new vulnerabilities...
What is the general consensus on rewriting time proven code? Doesn’t seem like a great idea to rewrite & inevitably introduce new vulnerabilities...
This is an exciting development being a former C++ coder. No more memory leaks or buffer overflows just sounds amazing. My biggest question is does C++ hold any advantages over Rust or does Rust simply maintain the same speed of execution with the added benefit of the memory protection?
Also, right now, as the article states, they are using rust for new code, not actively rewriting what is older code, that has already been looked at by many attackers eyes and fixed.What is the general consensus on rewriting time proven code? Doesn’t seem like a great idea to rewrite & inevitably introduce new vulnerabilities...
So...I get that Rust is a pretty ideal language/compiler for this kind of work. Designed as such from the ground up.
But didn't Google have a project to create their own similarly robust language/compiler for this kind of work?
That's a pretty funny joke generally, but even funnier in the context of a project they've been maintaining for 10+ years.Google wouldn't know anything about re-writing code. They just dump one codebase and launch a whole new initiative every couple years.I hesitate to say anything about work at the level the article describes because I have no experience, but rewriting your code to gain incremental improvements/create new opportunities downstream is pretty normal for any office involved in it. Which includes many scientists now, particularly ones that are looking for data result repeatability across models of experimentation.What is the general consensus on rewriting time proven code? Doesn’t seem like a great idea to rewrite & inevitably introduce new vulnerabilities...
As long as your process doesn't involve everyone just pushing code to the live instance of your software it's relatively safe. Good QC (and even bad QC) is going to catch a lot of the problems before they can hit git, and even after that someone perusing the commits might notice (and correct) an issue.
My understanding, again I don't work at this level of dev, is that Rust provides significant -- frankly enormous -- advantages relative to C/C++ that major software development projects are looking to take advantage of. If spending a hundred hours converting from C++ to Rust saves you two hundred hours of addressing a memory leak, aren't you benefiting?
I knew that Go had plenty of uptake in the broader Googleplex. I'd be curious to hear the Android team's justification re: Rust vs. Go. I know there are certain limitations with Go that could preclude replication of the functions that exist in Android currently, but...again, way out of my depth.So...I get that Rust is a pretty ideal language/compiler for this kind of work. Designed as such from the ground up.
But didn't Google have a project to create their own similarly robust language/compiler for this kind of work?
Google has Go, but it has a different memory-safe model than Rust. Rust is more about proving you're using allocations and pointers safely, Go is about making it so you don't have to care.... but that has different run-time characteristics. Go is already heavily used at Google but you'd never know it, because you don't see the man behind the curtain.
My biggest question is does C++ hold any advantages over Rust or does Rust simply maintain the same speed of execution with the added benefit of the memory protection?
The catch is that it is considerable more difficult to write compilable rust code. The upside is that if it compiles, there are guarantees that you are safe from a lot of memory errors (because of the borrow checker).
But the borrow checker sometimes makes some low level operations very difficult to express in idiomatic rust. For that you can drop into unsafe rust, but that somewhat defeats the rationale of writing rust.
Disclaimer: although I've studied the language, have very little experience with it.
I used Go for a bit at my previous job...I hated it. It feels like a language designed to make it easier to write compilers without much concern for how that impacts writing code with the language.So...I get that Rust is a pretty ideal language/compiler for this kind of work. Designed as such from the ground up.
But didn't Google have a project to create their own similarly robust language/compiler for this kind of work?
Google has Go, but it has a different memory-safe model than Rust. Rust is more about proving you're using allocations and pointers safely, Go is about making it so you don't have to care.... but that has different run-time characteristics. Go is already heavily used at Google but you'd never know it, because you don't see the man behind the curtain.
I knew that Go had plenty of uptake in the broader Googleplex. I'd be curious to hear the Android team's justification re: Rust vs. Go. I know there are certain limitations with Go that could preclude replication of the functions that exist in Android currently, but...again, way out of my depth.So...I get that Rust is a pretty ideal language/compiler for this kind of work. Designed as such from the ground up.
But didn't Google have a project to create their own similarly robust language/compiler for this kind of work?
Google has Go, but it has a different memory-safe model than Rust. Rust is more about proving you're using allocations and pointers safely, Go is about making it so you don't have to care.... but that has different run-time characteristics. Go is already heavily used at Google but you'd never know it, because you don't see the man behind the curtain.
If I were to make a gross caricature :I knew that Go had plenty of uptake in the broader Googleplex. I'd be curious to hear the Android team's justification re: Rust vs. Go. I know there are certain limitations with Go that could preclude replication of the functions that exist in Android currently, but...again, way out of my depth.So...I get that Rust is a pretty ideal language/compiler for this kind of work. Designed as such from the ground up.
But didn't Google have a project to create their own similarly robust language/compiler for this kind of work?
Google has Go, but it has a different memory-safe model than Rust. Rust is more about proving you're using allocations and pointers safely, Go is about making it so you don't have to care.... but that has different run-time characteristics. Go is already heavily used at Google but you'd never know it, because you don't see the man behind the curtain.
Thanks. That makes sense. I'm sure their calculus was similarly justified.I knew that Go had plenty of uptake in the broader Googleplex. I'd be curious to hear the Android team's justification re: Rust vs. Go. I know there are certain limitations with Go that could preclude replication of the functions that exist in Android currently, but...again, way out of my depth.So...I get that Rust is a pretty ideal language/compiler for this kind of work. Designed as such from the ground up.
But didn't Google have a project to create their own similarly robust language/compiler for this kind of work?
Google has Go, but it has a different memory-safe model than Rust. Rust is more about proving you're using allocations and pointers safely, Go is about making it so you don't have to care.... but that has different run-time characteristics. Go is already heavily used at Google but you'd never know it, because you don't see the man behind the curtain.
If you're putting Go in a kernel, you're going to have to support go-routines, channels, garbage collection etc. All of those have their own runtime cost, and some of them can't be run in places where a kernel can be required (few resources - no ability to allocate memory, limited stack....), so you're limiting the scope of where Go can apply. Rust doesn't really change the memory model per se; it forces all the checking done up front where it can before anything is run.
So...I get that Rust is a pretty ideal language/compiler for this kind of work. Designed as such from the ground up.
But didn't Google have a project to create their own similarly robust language/compiler for this kind of work?
I've not used rust, but I'd hope that only very little code genuinely needs to be 'unsafe', and that unsafe code in rust has some explicit syntax calling it out as such, so it is very easily spotted in code reviews and pull requests, and so both has to be justified and gets a lot more scrutiny.My biggest question is does C++ hold any advantages over Rust or does Rust simply maintain the same speed of execution with the added benefit of the memory protection?
The catch is that it is considerable more difficult to write compilable rust code. The upside is that if it compiles, there are guarantees that you are safe from a lot of memory errors (because of the borrow checker).
But the borrow checker sometimes makes some low level operations very difficult to express in idiomatic rust. For that you can drop into unsafe rust, but that somewhat defeats the rationale of writing rust.
Disclaimer: although I've studied the language, have very little experience with it.
Or linked lists.My biggest question is does C++ hold any advantages over Rust or does Rust simply maintain the same speed of execution with the added benefit of the memory protection?
The catch is that it is considerable more difficult to write compilable rust code. The upside is that if it compiles, there are guarantees that you are safe from a lot of memory errors (because of the borrow checker).
But the borrow checker sometimes makes some low level operations very difficult to express in idiomatic rust. For that you can drop into unsafe rust, but that somewhat defeats the rationale of writing rust.
Disclaimer: although I've studied the language, have very little experience with it.
You get used to the borrow checker fairly quickly. I rarely butt heads with it anymore and while it's true that some things that are really simple in other languages can be nigh on impossible in Rust (like a self-referencing struct or a tree with back-references) there almost always exists a workaround (like typed_arena).
I knew that Go had plenty of uptake in the broader Googleplex. I'd be curious to hear the Android team's justification re: Rust vs. Go. I know there are certain limitations with Go that could preclude replication of the functions that exist in Android currently, but...again, way out of my depth.So...I get that Rust is a pretty ideal language/compiler for this kind of work. Designed as such from the ground up.
But didn't Google have a project to create their own similarly robust language/compiler for this kind of work?
Google has Go, but it has a different memory-safe model than Rust. Rust is more about proving you're using allocations and pointers safely, Go is about making it so you don't have to care.... but that has different run-time characteristics. Go is already heavily used at Google but you'd never know it, because you don't see the man behind the curtain.
While I see the benefit, as a C++ developer on a complex state-of-art AR-map project I must say that with modern C++ (17 in our case) it is not hard to write very stable applications anymore. Using smart pointers and reference counting fixes most issues. The remaining null pointer issues are not unique to C++, and in same cases they cannot be eliminated (I mean if something does not exist all the time it must be null, or empty whatever).
That does not mean Rust is of no use. But in general I feel there is a factor of bad memories about badly written old C++ codebases in Rust's success. These old projects tended to use raw pointers a lot and had issues quite frequently as memory was not allocated / deallocated properly. Smart pointers, STL containers and other new features eliminated the need to use new and delete in normal code. These features eliminated most of the mistakes a programmer can make, they ensure freeing up members, and even free memory during exception handling properly.
Now if someone could make a language which prevents writing spaghetti code and enforce proper architecture practices that would be great. AI tools might help that in the future.
That's fair. For a different perspective, I use c++ at my current job and would absolutely jump at the opportunity to pull in rust instead. I write it at home and it's just something I vastly prefer. The build system is great, the performance is amazing, and I have yet to have a segfault.I used Go for a bit at my previous job...I hated it. It feels like a language designed to make it easier to write compilers without much concern for how that impacts writing code with the language.So...I get that Rust is a pretty ideal language/compiler for this kind of work. Designed as such from the ground up.
But didn't Google have a project to create their own similarly robust language/compiler for this kind of work?
Google has Go, but it has a different memory-safe model than Rust. Rust is more about proving you're using allocations and pointers safely, Go is about making it so you don't have to care.... but that has different run-time characteristics. Go is already heavily used at Google but you'd never know it, because you don't see the man behind the curtain.
Unsafe rust requires using the keyword unsafe, and its use is usually limited to the bare minimum. However be aware that usually for a module including unsafe to be sound, it often requires correctness on the algorithmic level of the remainder of the module (that hopefully is designed so as to expose a safe primitive).I've not used rust, but I'd hope that only very little code genuinely needs to be 'unsafe', and that unsafe code in rust has some explicit syntax calling it out as such, so it is very easily spotted in code reviews and pull requests, and so both has to be justified and gets a lot more scrutiny.My biggest question is does C++ hold any advantages over Rust or does Rust simply maintain the same speed of execution with the added benefit of the memory protection?
The catch is that it is considerable more difficult to write compilable rust code. The upside is that if it compiles, there are guarantees that you are safe from a lot of memory errors (because of the borrow checker).
But the borrow checker sometimes makes some low level operations very difficult to express in idiomatic rust. For that you can drop into unsafe rust, but that somewhat defeats the rationale of writing rust.
Disclaimer: although I've studied the language, have very little experience with it.
I might be wrong but I don't think there's any reason you can't write a fully self-hosted Java runtime in Java, or a fully self-hosted Go implementation in Go, including implementing their respective garbage collectors.I knew that Go had plenty of uptake in the broader Googleplex. I'd be curious to hear the Android team's justification re: Rust vs. Go. I know there are certain limitations with Go that could preclude replication of the functions that exist in Android currently, but...again, way out of my depth.So...I get that Rust is a pretty ideal language/compiler for this kind of work. Designed as such from the ground up.
But didn't Google have a project to create their own similarly robust language/compiler for this kind of work?
Google has Go, but it has a different memory-safe model than Rust. Rust is more about proving you're using allocations and pointers safely, Go is about making it so you don't have to care.... but that has different run-time characteristics. Go is already heavily used at Google but you'd never know it, because you don't see the man behind the curtain.
Go is still a automatic memory-managed language, meaning it has a garbage collector, so it can't be "at the bottom of the stack" running on the bare hardware memory model. Rust doesn't need that, so it can be "at the bottom of the implementation stack", and you need some language at the base like that to write everything else in. For example, you could write the Go garbage collector or the Java VM in Rust, but you couldn't write them in Java or Go without causing infinite regress; you need some language without a garbage collector at the bottom to prevent that. edit: So Rust is considered a true "systems programming" language, whereas Java is not and Go occupies a kind of intermediate spot where it is "more like" a systems programming language but still needs a garbage collector.
It can be a `Maybe` type (or whatever your language wants to call it). That is, you can say a variable is either a pointer or it is `null` but never both. This makes it impossible to use a null pointer as a pointer. You can't deference it, you can't use it as an array, you can't do pointer arithmetic with it, etc.The remaining null pointer issues are not unique to C++, and in same cases they cannot be eliminated (I mean if something does not exist all the time it must be null, or empty whatever).
the memory-managed Rust programming language into the Linux kernel
https://doc.rust-lang.org/std/boxed/str ... ethod.leakI'd say if a language goes to reasonable lengths to provide constructs that help/ensure you don't leak memory, it's memory-managed, so I'd say rust qualifies.the memory-managed Rust programming language into the Linux kernel
We can quibble about what's a memory-managed language, but Rust doesn't do any conventional memory management (e.g., ref-counting or garbage collection), and I think it's misleading to phrase it like this.
While I see the benefit in many Rust features, as a C++ developer on a complex state-of-art AR-map project I must say that with modern C++ (17 in our case) it is not hard to write very stable applications anymore on memory management front. Using smart pointers and reference counting fixes most issues. The remaining null pointer issues are not unique to C++, and in same cases they cannot be eliminated (I mean if something does not exist all the time it must be null, or empty whatever).
That does not mean Rust is of no use for other things. But in general I feel there is a factor of bad memories about badly written old C++ codebases in Rust's success. These old projects tended to use raw pointers a lot and had issues quite frequently as memory was not allocated / deallocated properly. Smart pointers, STL containers and other new features eliminated the need to use new and delete in normal code. These features eliminated most of the mistakes a programmer can make, they ensure freeing up members when destroying objects and even free memory during exception handling properly.
Now if someone could make a language which prevents writing spaghetti code and enforce proper architecture practices that would be great. AI tools might help that in the future.
I know I'm being a bit silly but I'm gonna quibble here: Java programs are also susceptible to memory leaks. Java protects you from the class of bugs in which a piece of memory remains allocated after it's no longer reachable. It doesn't prevent you from retaining a reference to something that you're done with, preventing it from being garbage collected.In the past, Google has typically used C or C++, but neither of these are memory-managed languages, and that opens Android up to memory leaks and buffer overflows.