TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

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

71 pointsby reader_1000over 9 years ago

8 comments

zzalphaover 9 years ago
Headline is misleading.<p>What&#x27;s going on here is that the GCC developers feel free to change the generated code for behaviour undefined in the C spec. This means they might alter the behaviour of code since 40% of all packages in Debian (the &quot;half of all packages&quot; mentioned here) contain code whose behaviour is undefined.<p>But the poster seems to define any change in behaviour as &quot;breaking&quot; code, which is ridiculous. How much of that 40% is rare edge cases or similar, such that in reality the behaviour of the code doesn&#x27;t change in practice?<p>The follow-up email raises this exact point, noting that in the specific example of pointer overflow:<p><i>In executions where overflow does not happen, the gcc produced binary will match the behavior of the abstract machine in the C spec.</i><p>Which means that the cited static analysis, while correctly identifying code containing UB, may not actually have an issue at runtime as the condition may never occur in practice.<p>The real problem is any software that truly relies on undefined behaviour for correct operation (which, I&#x27;ll bet, is far less than the 40% cited here). That code is fundamentally non-portable to other compilers specifically because each compiler may produce semantically different output.
评论 #10444235 未加载
评论 #10443958 未加载
评论 #10444164 未加载
dengover 9 years ago
Now that&#x27;s some flawed logic here:<p>- Some paper says that 40% of Debian packages have undefined behavior in them.<p>- gcc&#x27;s optimizer is sometimes unforgiving w.r.t. undefined behavior (see also: strict aliasing), changing the intended meaning of the code.<p>- Therefore, it breaks 40% of packages.<p>And boom, there&#x27;s your clickbait headline...
copsarebastardsover 9 years ago
The only reasonable thing to say about this was already said upthread of the page, and quoted here:<p>&gt; <i>I have worked on many programs, and whenever I found such a problem (typically called a &quot;portability problem&quot;), where the code was assuming something that the language did not guarantee, I fixed the program rather than bitching about the compiler.</i>
评论 #10444103 未加载
joostersover 9 years ago
The article is just complaining about undefined behavior, and what compilers do when they encounter code not written to spec.<p>Rather than rehashing the arguments for and against it, I&#x27;d really recommend anyone interested to read these articles:<p><a href="http:&#x2F;&#x2F;blog.llvm.org&#x2F;2011&#x2F;05&#x2F;what-every-c-programmer-should-know.html" rel="nofollow">http:&#x2F;&#x2F;blog.llvm.org&#x2F;2011&#x2F;05&#x2F;what-every-c-programmer-should-...</a><p><a href="http:&#x2F;&#x2F;blog.regehr.org&#x2F;archives&#x2F;213" rel="nofollow">http:&#x2F;&#x2F;blog.regehr.org&#x2F;archives&#x2F;213</a>
the_mitsuhikoover 9 years ago
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 :(
评论 #10444134 未加载
评论 #10444106 未加载
DanWaterworthover 9 years ago
<i>Since compilers (and by &quot;compilers&quot; I mean gcc mostly) quietly break your code behind your back, you have no way of telling whether you really fixed things or not.</i><p>Compile your test suite with -fsanitize=undefined.
评论 #10443969 未加载
jacquesmover 9 years ago
Bad craftsmen blame their tools.
评论 #10444308 未加载
babuskovover 9 years ago
Since when is 40% &quot;nearly half&quot;. Can we change the title to something like:<p>&quot;40% of Debian packages might break if GCC changes the way it handles undefined behavior&quot;
评论 #10444000 未加载
评论 #10444003 未加载
评论 #10444004 未加载
评论 #10443980 未加载
评论 #10444005 未加载