Live data from Hacker News

Undefined Behavior in 2017

blog.regehr.org

101–110 of 120 posts

Re: Undefined Behavior in 2017

#101
post #83
post #68

Earlier quoted context omitted.

I can't tell if this is satirical, but to be clear, you're proposing to disallow addition?

You could test whether overflow is going to happen first. Or use a math library that explicitly overflows with predictable results.

I know very few languages that do that. Even Rust doesn't when compiled for release. All for performance reasons.

Re: Undefined Behavior in 2017

#102
post #83

Earlier quoted context omitted.

You could test whether overflow is going to happen first. Or use a math library that explicitly overflows with predictable results.

I know very few languages that do that. Even Rust doesn't when compiled for release. All for performance reasons.

Some additional points:

* It's not UB in Rust, it's guaranteed to be two's compliment overflow.

* It's still a "program error" and debug builds are required to panic.

* Non-debug builds are allowed to either panic or do the overflow, for performance reasons, as you mention. If it was feasible to always panic we'd do that; the current wording allows us to change it to do so in the future if it becomes feasible.

* If you want to do a checked add, you can, it's just not the default.

Re: Undefined Behavior in 2017

#103
post #97
post #78

Earlier quoted context omitted.

They do it, but the performance culture among C devs doesn't appreciate enabling them. https://gcc.gnu.org/onlinedocs/gcc-7.1.0/gcc/Object-Size-Che... https://gcc.gnu.org/onlinedocs/gcc-7.1.0/gcc/Pointer-Bounds-... I bet not much UNIX software compiled with gcc enables them. Android is probably the only OS that does make use of them. https://android-developers.googleblog.com/2017/04/fortify-in...

The performance culture isn't just C. Far from it. Rust was susceptible to Stack Clash because they ripped out their existing stack probing to gain a few percent increase in performance. The article for this thread literally says, "For many use cases ASan is the better choice because it has much less overhead." IME Valgrind does a _much_ better job of detecting memory issues, partly because ASan only detects issues d…

> Rust was susceptible to Stack Clash because they ripped out their existing stack probing to gain a few percent increase in performance.

Citation please?

I thought Rust used guard pages, and that stack probing was something that it was moving towards, not something that was being ripped out.

Re: Undefined Behavior in 2017

#104
post #97

Earlier quoted context omitted.

The performance culture isn't just C. Far from it. Rust was susceptible to Stack Clash because they ripped out their existing stack probing to gain a few percent increase in performance. The article for this thread literally says, "For many use cases ASan is the better choice because it has much less overhead." IME Valgrind does a _much_ better job of detecting memory issues, partly because ASan only detects issues d…

> Rust was susceptible to Stack Clash because they ripped out their existing stack probing to gain a few percent increase in performance. Citation please? I thought Rust used guard pages, and that stack probing was something that it was moving towards, not something that was being ripped out.

Rust used guard pages, but was still vulnerable to attacks based on jumping over the guard page, which is the same issue that Stack Clash exploited in C programs. The ideal fix for that is stack probing, which Rust is indeed moving towards. However, in the past, Rust had a different fix: it would add a bit to all function prologues that explicitly checked for running out of stack space - based on LLVM split stack support, and a remnant of when (even further in the past) Rust actually used split stacks. The explicit check also protected against jumping over the guard page, but was much more expensive than stack probing, and also caused issues with embedded use cases. The plan was to replace it with stack probing, but things dragged on and it was removed before the replacement was ready.

Re: Undefined Behavior in 2017

#105
post #83

Earlier quoted context omitted.

You could test whether overflow is going to happen first. Or use a math library that explicitly overflows with predictable results.

I know very few languages that do that. Even Rust doesn't when compiled for release. All for performance reasons.

I might have lost the point in this long thread, but I'm pretty sure the suggestion was just to add it as an optional flag.

Re: Undefined Behavior in 2017

#106
post #92

Earlier quoted context omitted.

I think it's the compilers that have perverted the language to such an extent that it's become ridiculously difficult to understand, and so it's the compilers that must change back to being less obtuse and adversarial. The C standard even suggests, when defining undefined behaviour, that one of the possible options is "behaving during translation or program execution in a documented manner characteristic of the envir…

The original mandate of X3J11 was to “codify common existing practice”. The published Rationale goes on to describe a number of relevant criteria, including • Existing code is important, existing implementations are not. • Avoid “quiet changes.” • Trust the programmer. • Keep the language small and simple. • Make it fast, even if it is not guaranteed to be portable. In pre-ANSI C, and C89 C interpreted in line with t…

They revised that criteria list for C11, given the current state of C induced security exploits.

"12. Trust the programmer, as a goal, is outdated in respect to the security and safety programming communities. While it should not be totally disregarded as a facet of the spirit of C, the C11 version of the C Standard should take into account that programmers need the ability to check their work."

http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2021.htm

Re: Undefined Behavior in 2017

#107
post #97
post #78

Earlier quoted context omitted.

They do it, but the performance culture among C devs doesn't appreciate enabling them. https://gcc.gnu.org/onlinedocs/gcc-7.1.0/gcc/Object-Size-Che... https://gcc.gnu.org/onlinedocs/gcc-7.1.0/gcc/Pointer-Bounds-... I bet not much UNIX software compiled with gcc enables them. Android is probably the only OS that does make use of them. https://android-developers.googleblog.com/2017/04/fortify-in...

The performance culture isn't just C. Far from it. Rust was susceptible to Stack Clash because they ripped out their existing stack probing to gain a few percent increase in performance. The article for this thread literally says, "For many use cases ASan is the better choice because it has much less overhead." IME Valgrind does a _much_ better job of detecting memory issues, partly because ASan only detects issues d…

> The performance culture isn't just C. Far from it

Sure, but it is where it is more visible, specially micro-optimizing code as it is being written, without validating if it really matters to the application's use case with a profiler.

The school of systems programming languages from Algol side, was that correctness was much more relevant than pure performance, Algol dialects for systems programming already had Rust like unsafe blocks in the mid-60's.

In Burroughs B5500 the administrator could enable which applications with unsafe modules were allowed at all to be executed, 10 years before C was invented.

Re: Undefined Behavior in 2017

#108
post #78

Earlier quoted context omitted.

They CAN accommodate all users, just have compile time options you can enter in your make file/on the command line/etc to say what level of bounds checking/etc you want compiled into your code. Hell that way even within a given project you can choose "this library I'm nervous about so I'll eat the hit on bounds checking".

They do it, but the performance culture among C devs doesn't appreciate enabling them. https://gcc.gnu.org/onlinedocs/gcc-7.1.0/gcc/Object-Size-Che... https://gcc.gnu.org/onlinedocs/gcc-7.1.0/gcc/Pointer-Bounds-... I bet not much UNIX software compiled with gcc enables them. Android is probably the only OS that does make use of them. https://android-developers.googleblog.com/2017/04/fortify-in...

That's totally fair. Flip side arguing "we shouldn't do this because people who only care about immediate performance don't want them" feels like it is ignoring some percent of people who may not feel that way, or even the possibility of using it as a way to bring more people to systems level programming but are not up to making the leap Rust currently requires (which will hopefully become less of an issue as they work on this year's roadmap, but I would certainly argue still exists right now and we won't know how successful their efforts REALLY are until they are all in place).

Re: Undefined Behavior in 2017

#110
post #78

Earlier quoted context omitted.

They do it, but the performance culture among C devs doesn't appreciate enabling them. https://gcc.gnu.org/onlinedocs/gcc-7.1.0/gcc/Object-Size-Che... https://gcc.gnu.org/onlinedocs/gcc-7.1.0/gcc/Pointer-Bounds-... I bet not much UNIX software compiled with gcc enables them. Android is probably the only OS that does make use of them. https://android-developers.googleblog.com/2017/04/fortify-in...

That's totally fair. Flip side arguing "we shouldn't do this because people who only care about immediate performance don't want them" feels like it is ignoring some percent of people who may not feel that way, or even the possibility of using it as a way to bring more people to systems level programming but are not up to making the leap Rust currently requires (which will hopefully become less of an issue as they wo…

When IBM researched RISC in the mid-70s, on the IBM 801 minicomputer, they decided to use a subset of PL/I as their mostly safe system programming language.

They implemented a botstraped optimizing compiler for it, making use of an intermediate language with multiple optimization passes.

http://rsim.cs.illinois.edu/arch/qual_papers/compilers/ausla...

It was like having LLVM in the 70's and is only one example of the research on optimizing compilers since FORTRAN was created.

Post reply on HN