Live data from Hacker News

“gcc will quietly break nearly half of all the packages that it compiles”

metzdowd.com

11–20 of 110 posts

Re: “gcc will quietly break nearly half of all the packages that it compiles”

#11
post #5

Earlier quoted context omitted.

[deleted]

Just read the email.

Actually it's still a useful question, I think.

A simple example is function argument evaluation order. If you have:

foo(bar(), baz())

A compiler is free to call these functions in either order. That means if baz relies on state mutated by bar, the program may behave differently if the compiler chooses to reorder evaluation.

Re: “gcc will quietly break nearly half of all the packages that it compiles”

#12
post #6

Since when is 40% "nearly half". Can we change the title to something like: "40% of Debian packages might break if GCC changes the way it handles undefined behavior"

> Since when is 40% "nearly half".

...always?

> "40% of Debian packages might break if GCC changes the way it handles undefined behavior"

A lot of them are silently broken today. That's the scary part.

Re: “gcc will quietly break nearly half of all the packages that it compiles”

#13
post #6

Since when is 40% "nearly half". Can we change the title to something like: "40% of Debian packages might break if GCC changes the way it handles undefined behavior"

From the article: "(the figure of 40% is a lower bound since STACK doesn't do the same level of analysis that gcc does)." So he adds a fudge factor to estimate actual breakage and comes up with "nearly half". I dunno, seems fair to me.

Re: “gcc will quietly break nearly half of all the packages that it compiles”

#14
post #6

Since when is 40% "nearly half". Can we change the title to something like: "40% of Debian packages might break if GCC changes the way it handles undefined behavior"

Because the title is a direct quote from text on the linked-to page, which is the usual HN practice when there isn't a good title from the source itself.

Re: “gcc will quietly break nearly half of all the packages that it compiles”

#15
post #6

Since when is 40% "nearly half". Can we change the title to something like: "40% of Debian packages might break if GCC changes the way it handles undefined behavior"

When has 40% not been nearly half? What is the minimum threshold for a quantity to quality as nearly half?

Re: “gcc will quietly break nearly half of all the packages that it compiles”

#16
post #11

Earlier quoted context omitted.

Just read the email.

Actually it's still a useful question, I think. A simple example is function argument evaluation order. If you have: foo(bar(), baz()) A compiler is free to call these functions in either order. That means if baz relies on state mutated by bar, the program may behave differently if the compiler chooses to reorder evaluation.

A perhaps more interesting, quite realistic example:

    lock_two_widgets(widget *a, widget *b) {
        if (a lock);
            lock(&b->lock);
        } else {
            lock(&b->lock);
            lock(&a->lock);
        }
    }

Re: “gcc will quietly break nearly half of all the packages that it compiles”

#17
The only reasonable thing to say about this was already said upthread of the page, and quoted here:

> I have worked on many programs, and whenever I found such a problem (typically called a "portability problem"), where the code was assuming something that the language did not guarantee, I fixed the program rather than bitching about the compiler.

Re: “gcc will quietly break nearly half of all the packages that it compiles”

#18
post #11

Earlier quoted context omitted.

Actually it's still a useful question, I think. A simple example is function argument evaluation order. If you have: foo(bar(), baz()) A compiler is free to call these functions in either order. That means if baz relies on state mutated by bar, the program may behave differently if the compiler chooses to reorder evaluation.

A perhaps more interesting, quite realistic example: lock_two_widgets(widget *a, widget *b) { if (a lock); lock(&b->lock); } else { lock(&b->lock); lock(&a->lock); } }

If lock calls include a memory barrier, which they should, then they cannot be reordered.

Edit: Your code has undefined behavior, unless the two pointers point to the same object, which is unlikely in a realistic example.

Re: “gcc will quietly break nearly half of all the packages that it compiles”

#19
post #11

Earlier quoted context omitted.

Actually it's still a useful question, I think. A simple example is function argument evaluation order. If you have: foo(bar(), baz()) A compiler is free to call these functions in either order. That means if baz relies on state mutated by bar, the program may behave differently if the compiler chooses to reorder evaluation.

A perhaps more interesting, quite realistic example: lock_two_widgets(widget *a, widget *b) { if (a lock); lock(&b->lock); } else { lock(&b->lock); lock(&a->lock); } }

Right, because you can get to the end of a non-void function without producing a value. The pointer comparison isn't necessarily UB.

Re: “gcc will quietly break nearly half of all the packages that it compiles”

#20
Inknow people are quick to complain about programmers relying on UB here but this really is a long standing disagreement with the gcc folk. They are language lawyers of the worst sort and do not consider security implications being a point of discussion :(
Post reply on HN