Volatiles are often miscompiled

Programming, for all ages and all languages.
Post Reply
TylerH
Member
Member
Posts: 285
Joined: Tue Apr 13, 2010 8:00 pm
Contact:

Volatiles are often miscompiled

Post by TylerH »

Thought you guys might be interested in this: http://www.cs.utah.edu/~regehr/papers/e ... eprint.pdf.
User avatar
xenos
Member
Member
Posts: 1118
Joined: Thu Aug 11, 2005 11:00 pm
Libera.chat IRC: xenos1984
Location: Tartu, Estonia
Contact:

Re: Volatiles are often miscompiled

Post by xenos »

A paper from 2008 is not quite up to date with current compilers and standards, but still interesting to read and certainly good to know. One should keep this in mind when searching for bugs with volatile variables, and double check the compiler output in that case.
Programmers' Hardware Database // GitHub user: xenos1984; OS project: NOS
alexfru
Member
Member
Posts: 1111
Joined: Tue Mar 04, 2014 5:27 am

Re: Volatiles are often miscompiled

Post by alexfru »

XenOS wrote:A paper from 2008 is not quite up to date with current compilers and standards, but still interesting to read and certainly good to know. One should keep this in mind when searching for bugs with volatile variables, and double check the compiler output in that case.
Would you care to elaborate on how exactly it's not up to date?
FallenAvatar
Member
Member
Posts: 283
Joined: Mon Jan 03, 2011 6:58 pm

Re: Volatiles are often miscompiled

Post by FallenAvatar »

alexfru wrote:
XenOS wrote:...
Would you care to elaborate on how exactly it's not up to date?
Check the versions of the compilers used in the paper vs. current versions of the same compilers.

XenOS is right that it's something we need to look out for in specific circumstances (code not doing what we expect with volatile variables) but this is not likely to cause many bugs after *6* years of updates to compilers.

- Monk
TylerH
Member
Member
Posts: 285
Joined: Tue Apr 13, 2010 8:00 pm
Contact:

Re: Volatiles are often miscompiled

Post by TylerH »

XenOS wrote:A paper from 2008 is not quite up to date with current compilers and standards, but still interesting to read and certainly good to know. One should keep this in mind when searching for bugs with volatile variables, and double check the compiler output in that case.
Volatile wasn't exactly new in '08. It was in the original K&R C released in 1978. If the bugs hadn't been fixed in the 30 years previous, they likely weren't fixed in the 6 years following. That is, unless this paper brought the bugs to compiler devs' attention. But even then, I would guess the reason they lasted 30 years probably had something to do with the difficulty in fixing them, which would increase the likelihood they still aren't fixed.

You have to admit, it's pretty astounding that after 30 years of development (of the technology/methods, not the compilers themselves), not a single compiler got it right.
alexfru
Member
Member
Posts: 1111
Joined: Tue Mar 04, 2014 5:27 am

Re: Volatiles are often miscompiled

Post by alexfru »

tjmonk15 wrote:
alexfru wrote:
XenOS wrote:...
Would you care to elaborate on how exactly it's not up to date?
Check the versions of the compilers used in the paper vs. current versions of the same compilers.
Compiler versions aren't of much relevance, they aren't definitive. The main question is about what has changed in the language standard(s) and which version of the standard which compiler supports. Since 2008 there's been only one standard update (C++03 -> C++11 and C99 -> C11). It would be nice to hear not just that the paper is somewhat outdated, but how, it shouldn't be a huge difference (a paragraph perhaps, maybe a little more?), right?
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Volatiles are often miscompiled

Post by Combuster »

Compiler versions aren't of much relevance
Then you didn't properly read what the paper said itself:
because, as of this writing, no release incorporates fixes to all of the bugs we reported. (...) Our experiment is ongoing and we expect that within the
foreseeable future, LLVM - GCC will be effectively free of volatile and functional bugs for the programs emitted by randprog.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
bwat
Member
Member
Posts: 359
Joined: Fri Jul 03, 2009 6:21 am

Re: Volatiles are often miscompiled

Post by bwat »

alexfru wrote:Compiler versions aren't of much relevance, they aren't definitive.
Oh but they are. Upgrading is a cost/benefit question for many non-hobby projects.
alexfru wrote: The main question is about what has changed in the language standard(s) and which version of the standard which compiler supports. Since 2008 there's been only one standard update (C++03 -> C++11 and C99 -> C11).
Standards are fairly meaningless unless they're adopted. I use ANSI C so C99 and C11 have absolutely no meaning to me and I'm not alone.
As someone who has implemented an ISO standard compliant programming language, I'll say that standards are created for many reasons, many of which are non-technical.
Every universe of discourse has its logical structure --- S. K. Langer.
User avatar
xenos
Member
Member
Posts: 1118
Joined: Thu Aug 11, 2005 11:00 pm
Libera.chat IRC: xenos1984
Location: Tartu, Estonia
Contact:

Re: Volatiles are often miscompiled

Post by xenos »

tjmonk15 wrote:
alexfru wrote:Would you care to elaborate on how exactly it's not up to date?
Check the versions of the compilers used in the paper vs. current versions of the same compilers.
Exactly. Those compiler versions are really outdated. And even if these bugs existed for 30 years, they were discovered, pointed out in this article and reported:
Combuster wrote:
Compiler versions aren't of much relevance
Then you didn't properly read what the paper said itself:
because, as of this writing, no release incorporates fixes to all of the bugs we reported. (...) Our experiment is ongoing and we expect that within the
foreseeable future, LLVM - GCC will be effectively free of volatile and functional bugs for the programs emitted by randprog.
Programmers' Hardware Database // GitHub user: xenos1984; OS project: NOS
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re: Volatiles are often miscompiled

Post by Candy »

bwat wrote:Standards are fairly meaningless unless they're adopted. I use ANSI C so C99 and C11 have absolutely no meaning to me and I'm not alone.
Wow.

ANSI is just the American standards institute. The International Standards Organisation (ISO) produces documents called ISO9899 and ISO14882, which describe C and C++ in their international variants which have been the norm since 1989. That's where C99 and C11 come from - C99 is short for ISO9899:1999 and C11 is short for ISO9899:2011.

That's a pretty ignorant stance to have. Try to at least think outside of the US-centered box that you currently live in.
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: Volatiles are often miscompiled

Post by Brendan »

Hi,
Candy wrote:
bwat wrote:Standards are fairly meaningless unless they're adopted. I use ANSI C so C99 and C11 have absolutely no meaning to me and I'm not alone.
ANSI is just the American standards institute. The International Standards Organisation (ISO) produces documents called ISO9899 and ISO14882, which describe C and C++ in their international variants which have been the norm since 1989. That's where C99 and C11 come from - C99 is short for ISO9899:1999 and C11 is short for ISO9899:2011.

That's a pretty ignorant stance to have. Try to at least think outside of the US-centered box that you currently live in.
It has nothing to do with geography or standard bodies (e.g. ANSI vs. ISO); and everything to do with history. Basically; bwat prefers "old" and doesn't like "new" (and doesn't care about which standard body was responsible for "old").

Note that I'm mostly the same. I mostly learnt C from "The C Programming Language (second edition)", and haven't really bothered learning anything that was added to C since (excluding my flagrant abuse of "//" for single line comments).

Maybe one day they're release a third edition of this book, and programmers will start learning C11 (and ignore all versions of C created after that).. ;)


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
Post Reply