News for hackers. Stuff that matters.
Re:Boringcc: Proposal for a C compiler for secure software by tacostakohashi on Monday December 21, 2015 @02:53PM (#10773032)
I've always thought that there would be more value in exactly the opposite - a pathological C compiler (or C++ compiler, POSIX operating system, etc.). The pathological compiler would always implement undefined behavior in the most surprising, unpredictable manner - e.g., uninitialized memory would have a properly randomized value that changes from one run to the next, overflows would result in random values, etc.

That way, any programs that are made to work on the pathological implementation are largely guaranteed to rely only on standardized behavior, and work on any other standards compliant implementation.

Re:Boringcc: Proposal for a C compiler for secure software by __jal on Monday December 21, 2015 @03:07PM (#10773138)
We actually (almost) have that. It is called gcc.

A long time ago, when encountering "undefined" behavior, it would try to launch Nethack[1]. (It is valid behaviour, according to the spec.)

Seriously, ask around. There was a multi-month fat-chewing about gcc's pathological interpretation of "undefined" earlier this year on the Cryptography list, and tends to come up anywhere C programmers with an interest in security drink.

[1] http://feross.org/gcc-ownage/?1?1

Re:Boringcc: Proposal for a C compiler for secure software by _kst_ on Monday December 21, 2015 @04:18PM (#10773593)
That's inaccurate, according to the page you linked to (and to my memory of the incident).

gcc 1.17 would invoke nethack (or one of several other similar games, if available) if it saw an unrecogized #pragma directive.

According to the C standard, the behavior of a #pragma not followed by STDC is implementation-defined, not undefined -- which means that an implementation is required to document its behavior. (I presume that gcc did so.)

gcc did not play launch Nethack in response to undefined behavior in general, or in response to anything other than an unrecognized #pragma directive.

Re:Boringcc: Proposal for a C compiler for secure software by ChuckMcM on Monday December 21, 2015 @03:18PM (#10773217)
But that is the thing, undefined behavior just says that the compiler takes no position on what should happen. So a boring compiler that refuses to compile code which would have undefined behavior is sufficient. It makes idomatic C a bit more challenging but if you've read through Dan's code you know that he's all about picking a style and sticking with it. And for that set of constraints, its all defined (and boring because there is very little, if any, optimization going on insider the compiler)

So sub-optimal but predictable and safe code given that you change the preference bit to safety over speed.

Re:Boringcc: Proposal for a C compiler for secure software by ProblemFactory on Tuesday December 22, 2015 @10:50AM (#10778363)
A lot of undefined behaviour cannot be identified at compile time. For example, adding two signed integers is undefined if it overflows, but perfectly well defined if it does not.

A safe compiler will have to add checks to guard against undefined behaviour happening at runtime.

Re:Boringcc: Proposal for a C compiler for secure software by lazyjones on Monday December 21, 2015 @04:29PM (#10773662)
> a pathological C compiler

I had the same opinion at first and would agree if UB was mostly possible to avoid in meaningful programs, but it isn't. The main casualty would be the reason why this is being discussed at all: compilers need to make very specific assumptions on UB to enable some optimizations and if UB goes away, so do the optimizations. So we get the performance of the "boring" compiler anyway, just with more effort on behalf of the programmer.

DJB is (as always, I guess) right, C simply isn't really suited to optimizations based on UB. What'd be the big deal if compiler developers just stopped inflicting these on C programmers and focused on optimizing compilers for better-defined languages (with range types, specified overflow behavior etc.) instead?

Re:Boringcc: Proposal for a C compiler for secure software by xamuel on Monday December 21, 2015 @10:41PM (#10775659)
>inflicting these on C programmers

You're acting like it's unambiguously bad, but that's not true. For example, I might create a macro DEREF_AND_FREE(x) which expands to if(x)free(*x). Often times, I'll lazily use that in places where I know x isn't null. It's more readable and maintainble than splitting the macro up into two separate macros, DEREF_AND_FREE_IF_NONNULL and DEREF_AND_FREE_I_KNOW_ITS_NONNULL. These UB-based optimizations which are "inflicted" on me mean that I don't take the performance hit for my laziness.

Re:Boringcc: Proposal for a C compiler for secure software by duaneb on Monday December 21, 2015 @06:22PM (#10774338)
> What'd be the big deal if compiler developers just stopped inflicting these on C programmers and focused on optimizing compilers for better-defined languages (with range types, specified overflow behavior etc.) instead?

This is non-trivial. These definitions come with tradeoffs that fundamentally alter the language. However, this is basically what rust is.

Re:Boringcc: Proposal for a C compiler for secure software by qb45 on Monday December 21, 2015 @03:14PM (#10773199)
I don't know if it's guaranteed to bark on all possible cases of UB, but there we go:

  $ cat test.c
  int main() {
          return *(int*)0;
  }
  $ gcc test.c -fsanitize=undefined -o test
  $ ./test
  test.c:2:9: runtime error: load of null pointer of type 'int'
  Segmentation fault
I'm pretty sure I've seen similar tool based on clang as well.

And there is valgrind.

Re:Boringcc: Proposal for a C compiler for secure software by technion on Monday December 21, 2015 @07:11PM (#10774610)
A classic case for static analyzers. Clang with -Wall gives you:

    int.c:3:12: warning: indirection of non-volatile null pointer will be deleted,
      not trap [-Wnull-dereference]
Much better, scan-build:

    int.c:3:12: warning: Dereference of null pointer
    return *(int*)0;
Re:Boringcc: Proposal for a C compiler for secure software by an_d_rew on Monday December 21, 2015 @03:25PM (#10773255)
Just for the hardware-minded: dereferencing null is perfectly fine on Cortex-M processors and is well-defined.

Yes, that's hardware, but a nice place where hardware ain't C.

I'm just sayin'...

Re:Boringcc: Proposal for a C compiler for secure software by _kst_ on Monday December 21, 2015 @04:21PM (#10773606)
"Undefined behavior" means behavior that is not defined by the C standard. Things other than the C standard (secondary standards like POSIX, compiler documentation, hardware specifications, etc.) are free to define the behavior of any construct that's not defined by the language standard.

And an optimizing compiler is free to transform its generated code based on the assumption that the code's behavior is defined.

Re:Boringcc: Proposal for a C compiler for secure software by cygx on Monday December 21, 2015 @07:09PM (#10774596)
Arguably, undefined behaviour is more like 0/0 in (ordinary) mathematics than just something the C standard fails to specify (you want implementation defined for that one).

An optimizing compiler is free to transform its generated code based on the assumption that undefined behaviour never occurs.

Re:Boringcc: Proposal for a C compiler for secure software by Gibbon1 on Monday December 21, 2015 @09:37PM (#10775411)
There is of course the issue whether you want the compiler to do that. Usually optimizing one parameter in a design to the exclusion of everything else is an strong indicator that the engineers involved are functionally incompetent.
Re:Boringcc: Proposal for a C compiler for secure software by riwsky on Wednesday December 23, 2015 @11:20PM (#10787104)
Pardon the bald appeal to authority, but your assertion reminds me of a Richard Hamming quote:

""" As we say, the volume is almost all on the surface. Even in 3 dimensions the unit sphere has 7/8-ths of its volume within 1/2 of the surface. In n-dimensions there is 1–(1/2^n) within 1/2 of the radius from the surface.

This has importance in design; it means almost surely the optimal design will be on the surface and will not be inside as you might think from taking the calculus and doing optimizations in that course. The calculus methods are usually inappropriate for finding the optimum in high dimensional spaces. This is not strange at all; generally speaking the best design is pushing one or more of the parameters to their extreme—obviously you are on the surface of the feasible region of design! """

Re:Boringcc: Proposal for a C compiler for secure software by Gibbon1 on Thursday December 24, 2015 @02:05PM (#10789247)
I'm reminded of a friends bitch about his company hiring a couple of ex-bell labs video compression guys to develop video codecs. Said they spent a year and came up with a great codec. Decode speed was twice as fast as anything else. Great!! Encoding speed was about a 1000 times slower. So encoding 5 minutes of video would take 3.5 days. And thus totally unusable.

The issue is design axis's are entangled. And also figures of merit are nonlinear. Twice as whatever doesn't mean twice as good.

Re:Boringcc: Proposal for a C compiler for secure software by pekk on Tuesday December 22, 2015 @12:11AM (#10775965)
You're designing a standard for people to implement in their specific compilers, and you want to let them generate fast code... I hardly think the mere existence of "undefined behavior" indicates incompetence.
Re:Boringcc: Proposal for a C compiler for secure software by klodolph on Monday December 21, 2015 @04:07PM (#10773516)
Dereferencing NULL, in a C program, is ALWAYS undefined behavior. The fact that you are using a Cortex-M processor does not change this fact. It is spelled out very clearly in the C standard.
Re:Boringcc: Proposal for a C compiler for secure software by silon7 on Tuesday December 22, 2015 @03:03AM (#10776465)
I've used at times it to crash the program (core dump), producing a cleaner stack than abort().
Re:Boringcc: Proposal for a C compiler for secure software by astrange on Tuesday December 22, 2015 @06:28AM (#10777090)
You should use __builtin_trap(). Invoking undefined behavior lets the compiler justifiably delete the entire code path leading up to it.
Re:Boringcc: Proposal for a C compiler for secure software by masklinn on Monday December 21, 2015 @05:17PM (#10773951)
> Dereferencing NULL, in a C program, is ALWAYS undefined behavior.

1. you're not required to use C

2. an extension to the C standard can decide to define that behaviour

Re:Boringcc: Proposal for a C compiler for secure software by cygx on Monday December 21, 2015 @07:13PM (#10774620)
Also note that null pointers may not need to be represented by the all-zero bit pattern, ie the conversion

    (void*)(intptr_t)0
can in principle be more involved than a noop.
Re:Boringcc: Proposal for a C compiler for secure software by qb45 on Monday December 21, 2015 @03:39PM (#10773356)
Do you mean some quirk unique to these CPUs or do they simply have RAM mapped at this address?

The latter is nothing unusual, x86 has it as well.

Re:Boringcc: Proposal for a C compiler for secure software by amluto on Monday December 21, 2015 @05:40PM (#10774088)
I'm a bit curious how a pointer with value 0 ended up being banned by C. Specifically, on x86 real mode (which includes modern systems early in boot before switching to protected mode), there's a hardware defined data structure at address zero: the "Interrupt Vector Table".

Maybe everyone who wrote real-mode systems software either ignored that bit of the C standard, or they fudged around it (IIRC the IVT is an array and the first entry doesn't matter, so you can start a few bytes past zero), or they used assembly to access it.

Re:Boringcc: Proposal for a C compiler for secure software by tzs on Monday December 21, 2015 @06:19PM (#10774318)
In C, these two code fragments do not necessarily give the same result (assume pointers and longs are the same size):

   long zero = 0;
   struct IVT * ivt_ptr = (struct IVT *)zero;
and

   struct IVT * ivt_ptr = 0;
   /* or (struct IVT *)0 if you like that better stylistically */
The former gives you a pointer whose bits are all 0. The latter gives you a null pointer. On systems where 0 is a valid memory address the compiler should pick some other address that is not valid.

Similarly, these two are not necessarily the same:

    if ( ivt_ptr == 0 ) ...
and

    if ( ivt_ptr == (struct IVT *)zero ) ...
    /* or if ((long)ivt_ptr == zero ) ... */
0 only represents the null pointer in C when it is the constant 0.

See this for more information: http://c-faq.com/null/

Re:Boringcc: Proposal for a C compiler for secure software by qb45 on Monday December 21, 2015 @06:37PM (#10774433)
> On systems where 0 is a valid memory address the compiler should pick some other address that is not valid.

Not necessarily. Null dereference is undefined behavior so it may as well access some valid memory.

Even on platforms where 0 is a valid address, practical compilers tend to use 0 as null constant because it simplifies implementation (easy to check for null, matches the C syntax without WTFs).

This comes at the cost of making some small part of memory unusable to portable C code (nobody will believe you when you return 0 from malloc if 0 happens to be considered null), but that's fine because such memory is typically used for machine-specific, nonportable stuff anyway.

Re:Boringcc: Proposal for a C compiler for secure software by qb45 on Monday December 21, 2015 @06:00PM (#10774200)
It seems that 0 wasn't a usable address on PDP-11 so K&R decided it's fine to use it as null pointer constant.

And of course dereferencing 0 isn't impossible in practice on arches which support this. Compilers for such machines usually can be coerced to generate code which accesses 0, you just have to live with the fact that your code isn't considered "valid, portable C" anymore.

Re:Boringcc: Proposal for a C compiler for secure software by CountSessine on Monday December 21, 2015 @04:35PM (#10773693)
Like many embedded cores, Cortex-M's don't have an MMU - everyone sees physical memory. In fact, I believe that's the chief distinguishing feature of the 3 core levels - Cortex-M's have no MMU, Cortex-A's have memory paging, and I think Cortex-R's are in between and have memory segments like MIPS.

So if the board designer wired everything up to map RAM at address 0, then yes, you'd be able to dereference a pointer to address 0.

Completely beside the point, though. Dereferencing NULL is always undefined behaviour in C.

Re:Boringcc: Proposal for a C compiler for secure software by Gibbon1 on Monday December 21, 2015 @08:49PM (#10775144)
If I do a read of a 'null' pointer on the Cortex ARM I'm using it's the initial stack pointer. If you try to write to that without some special magic involving the flash controller one gets a bus fault interrupt. Behavior depends on what the ISR does.

AVR Processors don't have bus faults. Some machines I've worked on have RAM based at address zero.

Re:Boringcc: Proposal for a C compiler for secure software by masklinn on Monday December 21, 2015 @03:53PM (#10773429)
> dereferencing null is perfectly fine on Cortex-M processors and is well-defined

It's also perfectly fine on x86, in kernel memory page 0 is often mapped, the OS is the one mapping page 0 so that userland dereferencing it faults.

Re:Boringcc: Proposal for a C compiler for secure software by qb45 on Monday December 21, 2015 @04:03PM (#10773494)
Which x86 kernel maps something at 0? In Windows and Linux, the low part of virtual address space is reserved for userspace.

In fact, Linux had several privilege escalation bugs which involved putting something at 0 and executing a buggy syscall which loaded this thing due to NULL dereference and believed it's some legit internal kernel data.

Re:Boringcc: Proposal for a C compiler for secure software by 0x0 on Monday December 21, 2015 @04:49PM (#10773768)
Which was probably the reason why "mmap_min_addr" was added :) https://wiki.debian.org/mmap_min_addr
Re:Boringcc: Proposal for a C compiler for secure software by jevinskie on Monday December 21, 2015 @07:19PM (#10774649)
OS X and iOS map in __TEXT,__PAGEZERO to 0x0.* Of course, it is mapped without any protection levels so it isn't of much use except for catching most nullptr dereferences (just 4 GB of protection on x86_64!).

* Well, this is implemented by the default system toolchain. You'r particular toolchain can opt out of this behavior if they want to.

Re:Boringcc: Proposal for a C compiler for secure software by makomk on Monday December 21, 2015 @05:48PM (#10774136)
Mappings at zero are used by legacy code like 16-bit Windows applications, if I remember correctly.
Re:Boringcc: Proposal for a C compiler for secure software by noselasd on Monday December 21, 2015 @05:00PM (#10773854)
"perfectly fine" does not depend on the processor alone, it depends on the compiler. A compiler for x86 can assume dereferencing a NULL pointer is undefined behavior, and optimize your code in ways you perhaps didn't expect.

Or it could document and provide a well defined behavior of derefrencing a NULL pointer.

(e.g. gcc provides -fdelete-null-pointer-checks to control this)

Re:Boringcc: Proposal for a C compiler for secure software by masklinn on Monday December 21, 2015 @05:15PM (#10773936)
> "perfectly fine" does not depend on the processor alone, it depends on the compiler.

as(1).

Re:Boringcc: Proposal for a C compiler for secure software by cpeterso on Monday December 21, 2015 @04:26PM (#10773643)
clang warns about this particular usage of a null constant:

warning: indirection of non-volatile null pointer will be deleted, not trap [-Wnull-dereference] return (int)0; ^~~~~~~~ note: consider using __builtin_trap() or qualifying pointer with 'volatile'

Re:Boringcc: Proposal for a C compiler for secure software by qb45 on Monday December 21, 2015 @04:42PM (#10773729)
> warning: indirection of non-volatile null pointer will be deleted, not trap

That's a sweet little optimization :)

Probably the only reason they don't abort compilation at this point is that someone complained when it broke his tricky little macro which sometimes generates unreachable null dereference. Or something like that.

Re:Boringcc: Proposal for a C compiler for secure software by dxhdr on Monday December 21, 2015 @03:01PM (#10773092)
I'm not sure this would be helpful, working with any unpredictable system is a nightmare. The compiler emitting warnings of undefined behavior being utilized would be the best solution, though it would not be able to identify all scenarios. Input fuzzing would likely get you the rest of the way there.
Re:Boringcc: Proposal for a C compiler for secure software by octo_t on Monday December 21, 2015 @03:04PM (#10773110)
the problem is that the compiler assumes undefined behaviour can never happen ALL the time.

Signed integer overflow is the most common one, since it means you can hoist 32bit ints into 64bit ints so they fit in one register or similar and save hitting the stack.

Re:Boringcc: Proposal for a C compiler for secure software by derefr on Monday December 21, 2015 @04:21PM (#10773608)
I'd personally be fine with being forced to specify what sort of undefined behaviors I want to allow to be "assumed I didn't mean"; it's not a problem for me if some code refuses to compile until I e.g. type-annotate my u32s with "they're not going to overflow, don't worry."

I was about to say that "this would break a ton of other projects"—but actually, it seems like it'd be fine as long as it was an opt-in -W switch.

Re:Boringcc: Proposal for a C compiler for secure software by tacostakohashi on Monday December 21, 2015 @07:32PM (#10774731)
Emitting warnings and errors mostly works fine for undefined behaviors, the real problem is with implementation-defined behaviors.

Let's say that, on the pathological compiler, it's documented that sizeof(int) is 4, and chars are signed if the number of seconds in the current minute is even, otherwise sizeof(int) is 5 and chars are unsigned. If your code compiles and works with either setup, it's probably correct and portable.

It's not really feasible for programmers to avoid implementation-defined things like sizeof(int) varying across implementations, not is it feasible for compilers to detect assumptions made about the implementation's definition in the program. The existence of a pathological compiler would make it far easier to write programs that work across all implementations.

It's true that working with unpredictable systems is a nightmare, but that's precisely the nature of undefined and implementation-defined behavior in C. The existence of a pathological compiler would merely allow developers to work through these issues on a single machine, which would be an improvement on needing to obtain a variety of compilers and platforms test with to find these issues.

Re:Boringcc: Proposal for a C compiler for secure software by __s on Monday December 21, 2015 @06:45PM (#10774466)
It could detect all scenarios by compiling to a C virtual machine which checks for UB at runtime
Re:Boringcc: Proposal for a C compiler for secure software by haberman on Monday December 21, 2015 @03:28PM (#10773276)
If the runtime can detect undefined behavior, why do something random? Just report the undefined behavior to the user. Now you have UBSan: https://www.chromium.org/developers/testing/undefinedbehavio...
Re:Boringcc: Proposal for a C compiler for secure software by 1ris on Monday December 21, 2015 @02:57PM (#10773061)
But why? That's a way more complicated and a way less usefull.
Re:Boringcc: Proposal for a C compiler for secure software by MereInterest on Monday December 21, 2015 @03:01PM (#10773094)
Because if you have undefined behavior, you want your program to crash and burn as quickly as possible, so that you can remove the undefined behavior. What seems to be proposed by Dan Bernstein is not so much a "boring C compiler", but rather a superset of C which does not have any undefined or unspecified behavior.
Re:Boringcc: Proposal for a C compiler for secure software by kazinator on Monday December 21, 2015 @03:21PM (#10773244)
Sometimes if you have undefined behavior, you want the documented extension to happen.

Or you want the de facto widely understood behavior to happen which has happened on every compiler you've used in 30 years: at least every compiler that was for two's complement matchines. Or every compiler on which pointers to different data types were of the same size. And so on.

You also don't want to be burned by code that is relying on a common extension, when that is ported.

There is a word for the compiler approach of "we're going to optimize this based on the assumption that the program is not relying on a common extension that is technically UB".

That word is: malpractice.

For instance, it is not unusual for C code to be targetting machines in which all objects are in the same address space, such that pointers are internally like binary numbers, allowing pointers to different objects to be compared for inequality: ptr1 < ptr2 /* does ptr1 point to a lower address than ptr2 in the one big address space? /

Programmers expect this work consistently with the address structure of the machine. They don't want the expression to be somehow wrongly optimized based on the assumption that ptr1 and ptr2 must point to the same object.

Implementations must honor requirements beyond those of ISO C. Such as, for instance, behaviors that those same compilers* used to define historically in their past revisions.

If GCC has behaved a certain way for 25 years, and some code has come to depend on that, and then that is suddenly taken away, such that entire GNU/Linux distros continue to compile, but break in random places because of that detail, the fault for the regression lies 105% with the doofus who made the GCC commit. Even if that behavior is not defined by ISO C.

Re:Boringcc: Proposal for a C compiler for secure software by quotemstr on Monday December 21, 2015 @04:20PM (#10773603)
> which pointers to different data types were of the same size

Member function pointer size varies widely between ABIs.

Re:Boringcc: Proposal for a C compiler for secure software by kazinator on Monday December 21, 2015 @04:39PM (#10773709)
I suspect you're talking about "pointer to member", which doesn't exist in C; it is a C++ concept. This is not a pointer, but a kind of indirection mechanism dressed up in pointer syntax.

I've never seen C++ code which depended on the internals of pointers-to-member, or assumed they had the same size as other kinds of pointers.

A pointer to member is actually a complicated offset into an offset into some structure associated with an object's class. This offset can be "dereferenced" with respect to objects of different types in the same hierarchy, taking into account multiple inheritance and virtual bases, etc. A pointer to a Base::Foo function, can be applied against a Derived object, such that it resolves to the correct code, even though Base is the third base of Derived, and so Foo is in a totally different vtable position in Derived compared to Foo. (The pointer cannot be a blind integer offset.)

In C, we would make a struct containing function pointers, and a simple "pointer to member" would just be an integer "offsetof(our_struct_type, some_function)". Then worry about it later if someone wanted multiple inheritance. :)

Re:Boringcc: Proposal for a C compiler for secure software by quotemstr on Monday December 21, 2015 @04:42PM (#10773727)
Nevertheless, it is a kind of pointer (it's called a "pointer") with a non-uniform size. That its internal structure is composite (just like a segmented 80286 far pointer) is irrelevant.
Re:Boringcc: Proposal for a C compiler for secure software by gherkin0 on Monday December 21, 2015 @03:02PM (#10773095)
I think the idea is that any reliance on undefined behavior would blow up in your face and immediately cause a bugs, rather than working correctly with some compilers and not with others.
Re:Boringcc: Proposal for a C compiler for secure software by kazinator on Monday December 21, 2015 @03:18PM (#10773212)
The problem is that undefined behaviors are used for valid extensions. "Undefined behavior" doesn't mean "error".

For instance including a platform header like #include <fortran.h> is undefined behavior. ISO C has some requirements there: if the header is found, then the directive is replaced with the preprocessing tokens from reading that header (and so if there are syntax errors there, they have to be diagnosed, and so on). But ISO C specifies no requirements as to what <fortran.h> contains, or whether it exists. On one implementation, it might cause the rest of the translation unit to be treated as a Fortran program. On an other implementation, it might bring in some declarations related to a Fortran interoperability. On yet another, translation might stop with "header not found: fortran.h".

UB is simply "behavior upon use of a nonportable or erroneous construct, of erroneous data, or of indeterminately-valued objects for which [ISO C] imposes no requirements".

Nonportable is not necessarily erroneous!

Re:Boringcc: Proposal for a C compiler for secure software by pmjordan on Monday December 21, 2015 @03:26PM (#10773270)
There is a difference, in the standard, between undefined and implementation-defined (unspecified) behaviour though.
Re:Boringcc: Proposal for a C compiler for secure software by kazinator on Monday December 21, 2015 @03:30PM (#10773291)
There is also a difference between "implementation-defined" and "unspecified". Look it up!

The former is similar to the latter, only it must be documented. Unspecified behaviors imply some choice from among alternatives which need not be documented. (Like the order in which the argument expressions of a function are evaluated.)

Re:Boringcc: Proposal for a C compiler for secure software by tacostakohashi on Monday December 21, 2015 @03:03PM (#10773104)
Not really. There are a lot of platforms that already have a compiler that the vendor claims is standard, so being able to ensure programs rely only on the standard would make it easy to target all of these existing platforms and compiler implementations.

The "boring" compiler doesn't exist yet, and would need to be implemented on every platform that currently has a standard compiler to be as useful.

Re:Boringcc: Proposal for a C compiler for secure software by Pxtl on Monday December 21, 2015 @03:22PM (#10773246)
Um, sounds like the most appropriate response would be a low-performance C compiler/interpreter that enforces crashes on all run-time undefined behaviors, and refuses to compile for any compile-time checkable ones.
Re:Boringcc: Proposal for a C compiler for secure software by nwmcsween on Monday December 21, 2015 @07:11PM (#10774604)
Ubsan already does this, there is a flag that controls abort on UB.
Re:Boringcc: Proposal for a C compiler for secure software by pekk on Tuesday December 22, 2015 @12:12AM (#10775968)
Unfortunately, nobody will use that compiler. They will continue to use the high-performance compilers, because this is what happened decades ago.
Re:Boringcc: Proposal for a C compiler for secure software by kenko on Monday December 21, 2015 @04:32PM (#10773672)
Why is that more appropriate than just defining all the currently undefined/implementation-specific behavior?
Re:Boringcc: Proposal for a C compiler for secure software by CountSessine on Monday December 21, 2015 @04:40PM (#10773721)
IMO both approaches would be useful. One nice thing about outlawing undefined behaviour rather than defining it, though, it that you'll be writing portable code - if you have a code base that's filled with all all sorts of once-was-undefined-but-now-is-defined behaviour, you can never build that code on another compiler.
Re:Boringcc: Proposal for a C compiler for secure software by Pxtl on Monday December 21, 2015 @04:37PM (#10773698)
Because enforcing undefined behavior on this test-compiler means you can build your software on any standards-compliant compiler and have it work the same. In theory.
Re:Boringcc: Proposal for a C compiler for secure software by nickpsecurity on Monday December 21, 2015 @03:43PM (#10773376)
Funny idea but best to leave that to code analysis tools. So, your compiler works as expected and works well. That's why you use it. Other peoples' work like shit due to bugs and undefined behavior. So, a coding style plus analysis tools to reinforce it make your code work well with others' compilers while you still use The Right Thing. ;)
Re:Boringcc: Proposal for a C compiler for secure software by WalterBright on Tuesday December 22, 2015 @05:30AM (#10776889)
I used to use with C a replacement for malloc() that would initialize the memory to 0xDEADBEEF. It was amazing how many bugs were forced into the open.

These days, valgrind is a much better option for doing this.

Re:Boringcc: Proposal for a C compiler for secure software by 010a on Tuesday December 22, 2015 @12:36AM (#10776037)
Go does this in at least one way. The iteration order of maps is undefined in the language spec. The go runtime automatically and purposefully randomizes the order of items in a hash so programmers can't rely on the arbitrary ordering it may have at any time.

https://blog.golang.org/go-maps-in-action

Re:Boringcc: Proposal for a C compiler for secure software by duaneb on Monday December 21, 2015 @06:21PM (#10774333)
How is this any better than simply noting undefined behavior as an error?
Re:Boringcc: Proposal for a C compiler for secure software by ape4 on Monday December 21, 2015 @03:54PM (#10773442)
It could just crash with an error.
Re:Boringcc: Proposal for a C compiler for secure software by ZoF on Monday December 21, 2015 @03:03PM (#10773109)
This makes zero sense to me. Where would this be beneficial?

Why not just fuzz inputs if this is your goal?

Re:Boringcc: Proposal for a C compiler for secure software by tacostakohashi on Monday December 21, 2015 @03:10PM (#10773168)
That's what this is, keeping in mind that the compiler's implementation of undefined behavior is an input that should be fuzzed.

Think of, say, integer overflow. The problem is that typical compilers have a consistent (but non-standard) implementation, so it can't be fuzzed without some compiler help.

Re:Boringcc: Proposal for a C compiler for secure software by ufo on Monday December 21, 2015 @03:18PM (#10773215)
Tests can show the presence of bugs but not their absence. The idea here is to create a compiler for C (or perhaps a C dialect) so that nasty undefined behavior is guaranteed to not occur.
Re:Boringcc: Proposal for a C compiler for secure software by GFK_of_xmaspast on Monday December 21, 2015 @03:02PM (#10773099)
It's hard enough getting people to turn warnings on.
Re:Boringcc: Proposal for a C compiler for secure software by tacostakohashi on Monday December 21, 2015 @03:08PM (#10773147)
This is true - in general, a warning means the code is non-standard or ambiguous, so the compiler is falling back to some default or non-standard interpretation. Then, people come to rely on that, and, like you say, not turn warnings on. So, I say that's not a useful class of behavior, and in some cases (trying to write secure / portable software) it would be better if that didn't exist.