News for hackers. Stuff that matters.
Re:"Rust does not have a stable ABI" by jokoon on Thursday August 13, 2020 @06:01AM (#24141662)
Wouldn't it be possible to have a C-like language that is somewhat backward compatible with C, and have the nice security features of Rust?

I get that Rust is awesome, but I'm not certain you need to make an entire new language just to have the security stuff.

Of course it might be complicated to do, but in the end, aren't there linters or other validators that can give the same security results rust has, but with C or even C++?

Re:"Rust does not have a stable ABI" by server_bot on Thursday August 13, 2020 @06:30AM (#24141830)
These are valid questions a lot of people new to Rust have, so:

1. Rust is "backward compatible" in the sense that Rust code can use C libraries and C code can use Rust libraries - both ways via CFFI [1]. Security gaurentees only apply to the Rust code.

2. We've tired static and dynamic analysis of C to find security bugs for decades, there has been a plethora of research and commercial tools in the space. None fix the problem like Rust does [2].

[1] https://michael-f-bryan.github.io/rust-ffi-guide/ [2] https://msrc-blog.microsoft.com/2019/07/18/we-need-a-safer-s...

Re:"Rust does not have a stable ABI" by blub on Friday August 14, 2020 @03:13AM (#24154778)
Almost any language can call C functions and we don't call all languages backwards compatible with C when they can merely interoperate with it.

Objective-C and C++ are the only two languages which offer backwards compatibility. AFAIK it's complete in the case of the former and there are some limitations for the latter.

None fix the problem like Rust does, but it's worthwhile to examine why: typical companies and developers have an aversion to paying for tools and for anything which slows down development. That's why usually those tools and languages which are reasonably user-friendly are more successful. Ironically that's both an advantage and a problem for rust: it's nicer to use than some C tools, but still not user-friendly compared to alternatives like Go or Java and in some cases even C++.

Re:"Rust does not have a stable ABI" by pornel on Thursday August 13, 2020 @09:50AM (#24143288)
There is Cyclone, Checked C, Deputy. Such "C-but-weird" languages have an "uncanny valley" problem:

• "C, but safer" on its own is not very enticing. With no other benefits, it's easy not to switch, and instead promise to try harder writing standard C safely, or settle for analysis tools or sandboxes.

• People who use C often have backwards compatibility constraints. Switching to another compiler and a dialect that isn't standard C is a tough sell. You can still find C programmers who think adopting C99 is too radical.

• Programming patterns commonly used in C (rich in pointer juggling, casts, and textual macros) are inherently risky, but if you try to replace them (e.g. with generics, iterators), it stops looking like C anyway.

So "safer C" is unattractive to people who are tied to C implementations or don't want to learn a new language.

But people who do want to learn a new language and use modern tooling, don't want all the unfixable legacy baggage of C.

Rust dodges these problems by not being a "weird C". It's a clean design, with enough features to be attractive on its own, and safety is just a cherry on top.

Re:"Rust does not have a stable ABI" by Nuoji on Saturday August 15, 2020 @08:52AM (#24168499)
Cyclone was not fully realized though.

And there are languages that try to keep to C and add some minor safety improvements, eg my language C3 (subarrays/slices, contracts, all UB has runtime checks in debug builds and more)

Re:"Rust does not have a stable ABI" by jokoon on Friday August 14, 2020 @04:20AM (#24155276)
Sounds like marketing to me. It will convince young, gullible CS students, but not software engineers.
Re:"Rust does not have a stable ABI" by qppo on Thursday August 13, 2020 @10:43AM (#24143830)
I think maybe you're conflating what Rust's borrow checker does with the notion of "security." They're related in that the borrow checker does some stuff that makes it difficult to create certain bugs that can be security issues, but they're not the same.

But to answer the question, I suspect no, and if you did it would be basically re-engineering the borrow checker and forcing Rust semantics into C and C++.

I don't know if anyone has proven it, but my hunch is that borrow checking C is undecidable.

Re:"Rust does not have a stable ABI" by jdub on Thursday August 13, 2020 @06:25AM (#24141798)
1. You could possibly get closer, but you'd lose a lot. Most of Rust's "nice security features" are wildly incompatible with existing C/C++ code and inherent language features.

2. No. If C/C++ could be made safe* Rust would not exist.

* everyone agrees on this point, including the richest and largest software companies on the planet

Re:"Rust does not have a stable ABI" by dependenttypes on Thursday August 13, 2020 @07:14AM (#24142084)
> Most of Rust's "nice security features" are wildly incompatible with existing C/C++ code and inherent language features

Such as?

Re:"Rust does not have a stable ABI" by fhars on Thursday August 13, 2020 @08:23AM (#24142615)
Lifetimes and the borrow checker.
Re:"Rust does not have a stable ABI" by dependenttypes on Thursday August 13, 2020 @11:10AM (#24144122)
A linter can do that.
Re:"Rust does not have a stable ABI" by smolder on Thursday August 13, 2020 @12:43PM (#24145323)
Nope.
Re:"Rust does not have a stable ABI" by dependenttypes on Thursday August 13, 2020 @12:59PM (#24145509)
Just because you lack the ability to imagine something like that it does not mean that it is impossible. Sadly this kind of sentiment seems to be way too common in tech.
Re:"Rust does not have a stable ABI" by pirocks on Thursday August 13, 2020 @08:36PM (#24151791)
This wouldn't be possible in a practical sense. One could imagine a static analyzer of some kind which infers all lifetimes, though that would likely quickly be unworkably slow on real codebases, since you need to infer programmer intent. Additionally c static analyzers intended to catch all memory errors/UB etc. have existed for decades, and no one uses them, b/c they don't work or have too many false positives. For example did you know that until C++20 allocating an int with malloc was UB in C++? Would you want to work in a language where the linter marked every other line as UB?
Re:"Rust does not have a stable ABI" by smolder on Thursday August 13, 2020 @01:49PM (#24146063)
It is impossible given the spec and syntax of those languages, which is why Rust exists, to enable these features...
Re:"Rust does not have a stable ABI" by SAI_Peregrinus on Thursday August 13, 2020 @01:45PM (#24146019)
C lacks the information given to the compiler to do this. It can't be added without adding that to the language. So no linter can do this alone, without language changes.
Re:"Rust does not have a stable ABI" by dependenttypes on Friday August 14, 2020 @08:41AM (#24157114)
You can use _Pragma/#pragma, regardless though, you can achieve a lot of what lifetimes can without any annotation.
Re:"Rust does not have a stable ABI" by SAI_Peregrinus on Saturday August 15, 2020 @06:27PM (#24172972)
Pragmas are extensions to C, not part of the C language standard. You can add things to C, but it then ceases to be standard C and becomes GNU C or MS Visual C or early C++ or something else. But not ISO Standard C.

And yes, just about anything non-lexical lifetimes can do you can do with static analysis. But the set of things you can do with Rust includes things that need explicit lifetime annotations, which C doesn't have.

Re:"Rust does not have a stable ABI" by jdub on Thursday August 13, 2020 @10:25PM (#24152506)
If you think we could get this right in C (48 years old) and C++ (35 years old), don't you think we would have done it by now? :-)
Re:"Rust does not have a stable ABI" by dependenttypes on Friday August 14, 2020 @08:39AM (#24157093)
No, people tend to be quick to create a new language in addition to lacking imagination and thinking that it is impossible to do in C.
Re:"Rust does not have a stable ABI" by jdub on Thursday August 20, 2020 @12:54AM (#24220022)
Too quick to create a new language?! Rust was started in 2006 and announced in 2010. Its improvements are based on research done before and after C/C++ existed.

If you're the only person smart enough to solve the $64B problem so everyone can start writing safe and backwards compatible code in C/C++, please, go right ahead.

Re:"Rust does not have a stable ABI" by cttet on Friday August 14, 2020 @12:09AM (#24153254)
yes writing a mini-rust compiler in C is possible and you can write in the mini language. But the problem is: at what cost?
Re:"Rust does not have a stable ABI" by dependenttypes on Friday August 14, 2020 @08:37AM (#24157088)
This has nothing to do with what I am talking about.
Re:"Rust does not have a stable ABI" by dependenttypes on Thursday August 13, 2020 @07:12AM (#24142073)
You certainly do not even need to make a new language. Just making a new C implementation that aborts on buffer overflows for example would be enough.
Re:"Rust does not have a stable ABI" by sanxiyn on Thursday August 13, 2020 @01:03PM (#24145546)
This is an intractable problem because checking for buffer overflows requires buffer bounds and C pointers lack buffer bounds. Rust solves this by "fat pointer", pointer that knows its size, but fat pointer can't be the same size as thin pointer hence it would be backward incompatible.
Re:"Rust does not have a stable ABI" by dependenttypes on Thursday August 13, 2020 @03:01PM (#24146950)
Your C implementations lacks "buffer bounds". C by itself doesn't. There is nothing stopping a C implementation tracking the size of the data that a pointer points to (and these implementations are not even hypothetical, they actually exist right now).

> hence it would be backward incompatible

Rust is backward incompatible with C. A C implementation with fat pointers would not be backward incompatible with C. Depending on how it was implemented it could be ABI-incompatible with older C implementations but this is not necessary either.

Re:"Rust does not have a stable ABI" by pirocks on Thursday August 13, 2020 @08:30PM (#24151738)
The problem fat pointer based implementations are massively slower. Rust aims to provide safety without massive performance penalties. If one wanted safety without performance they would just use java or similar.
Re:"Rust does not have a stable ABI" by dependenttypes on Friday August 14, 2020 @08:36AM (#24157076)
> The problem fat pointer based implementations are massively slower

I am challenging that. I do not believe that a C implementation that uses fat pointers needs to be any slower than Rust.

> If one wanted safety without performance they would just use java or similar.

Or C with a safe implementation.

Re:"Rust does not have a stable ABI" by steveklabnik on Friday August 14, 2020 @09:28AM (#24157647)
Yeah like, rust also uses fat pointers. They should be equivalent. The issue is pervasiveness not speed.