login
Header Space

 
 

Is gcc thread-unsafe?

Score:
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: Linux Kernel Mailing List <linux-kernel@...>, Linus Torvalds <torvalds@...>, Kleen, Andi <ak@...>
Date: Wednesday, October 24, 2007 - 11:24 pm

Hi,

Andi spotted this exchange on the gcc list. I don't think he's
brought it up here yet, but it worries me enough that I'd like
to discuss it.

Starts here
http://gcc.gnu.org/ml/gcc/2007-10/msg00266.html

Concrete example here
http://gcc.gnu.org/ml/gcc/2007-10/msg00275.html

Basically, what the gcc developers are saying is that gcc is
free to load and store to any memory location, so long as it
behaves as if the instructions were executed in sequence.

I guess that dynamically allocated memory and computed pointers
are more difficult for gcc to do anything unsafe with, because
it is harder to tell if a given function has deallocated the
memory. However even that could theoretically happen in future
if the compiler can work out the address comes from a global
variable or is not changed intermediately.

Linux makes extensive use of both trylocks and interruptible
locks (ie. which automatically result in divergant code paths,
one of which holds the lock, the other doesn't). However there
are also other code paths which will either hold a particular
lock or will not hold it, depending on context or some flags
etc. barrier() doesn't help.

For x86, obviously the example above shows it can be miscompiled,
but it is probably relatively hard to make it happen for a non
trivial sequence. For an ISA with lots of predicated instructions
like ia64, it would seem to be much more likely. But of course
we don't want even the possibility of failures.

The gcc guys seem to be saying to mark everything volatile that
could be touched in a critical section. This is insane for Linux.

Any thoughts?
-
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Is gcc thread-unsafe?, Nick Piggin, (Wed Oct 24, 11:24 pm)
Re: Is gcc thread-unsafe?, Phillip Susi, (Wed Oct 31, 6:10 pm)
Re: Is gcc thread-unsafe?, Linus Torvalds, (Thu Oct 25, 10:55 am)
Re: Is gcc thread-unsafe?, Ismail , (Thu Oct 25, 6:26 pm)
Re: Is gcc thread-unsafe?, Jeff Garzik, (Thu Oct 25, 6:56 pm)
Re: Is gcc thread-unsafe?, Jeff Garzik, (Thu Oct 25, 7:04 pm)
RE: Is gcc thread-unsafe?, David Schwartz, (Thu Oct 25, 5:42 pm)
Re: Is gcc thread-unsafe?, Nick Piggin, (Thu Oct 25, 7:22 pm)
Re: Is gcc thread-unsafe?, Andrew Haley, (Fri Oct 26, 7:59 am)
Re: Is gcc thread-unsafe?, Andrew Haley, (Fri Oct 26, 7:59 am)
Re: Is gcc thread-unsafe?, Chris Friesen, (Fri Oct 26, 1:39 pm)
Re: Is gcc thread-unsafe?, Pekka Enberg, (Thu Oct 25, 11:12 am)
Re: Is gcc thread-unsafe?, Andi Kleen, (Thu Oct 25, 3:15 am)
Re: Is gcc thread-unsafe?, Nick Piggin, (Thu Oct 25, 6:49 pm)
Re: Is gcc thread-unsafe?, Andi Kleen, (Thu Oct 25, 7:09 pm)
Re: Is gcc thread-unsafe?, Nick Piggin, (Thu Oct 25, 7:43 pm)
Re: Is gcc thread-unsafe?, Andi Kleen, (Thu Oct 25, 7:55 pm)
Re: Is gcc thread-unsafe?, Nick Piggin, (Thu Oct 25, 7:57 pm)
Re: Is gcc thread-unsafe?, Linus Torvalds, (Thu Oct 25, 7:14 pm)
Re: Is gcc thread-unsafe?, Andi Kleen, (Thu Oct 25, 7:16 pm)
Re: Is gcc thread-unsafe?, Linus Torvalds, (Thu Oct 25, 7:32 pm)
Re: Is gcc thread-unsafe?, Andi Kleen, (Thu Oct 25, 7:42 pm)
Re: Is gcc thread-unsafe?, Willy Tarreau, (Fri Oct 26, 12:57 am)
Re: Is gcc thread-unsafe?, Linus Torvalds, (Thu Oct 25, 7:57 pm)
Re: Is gcc thread-unsafe?, Zachary Amsden, (Thu Oct 25, 9:15 pm)
Re: Is gcc thread-unsafe?, linux-os (Dick Johnson), (Thu Oct 25, 7:58 am)
Re: Is gcc thread-unsafe?, Andi Kleen, (Thu Oct 25, 8:16 am)
Re: Is gcc thread-unsafe?, Arjan van de Ven, (Wed Oct 24, 11:46 pm)
Re: Is gcc thread-unsafe?, Nick Piggin, (Wed Oct 24, 11:58 pm)
RE: Is gcc thread-unsafe?, David Schwartz, (Thu Oct 25, 12:29 am)
Re: Is gcc thread-unsafe?, Nick Piggin, (Thu Oct 25, 12:47 am)
Re: Is gcc thread-unsafe?, Samuel Tardieu, (Thu Oct 25, 5:44 am)
Re: Is gcc thread-unsafe?, Andi Kleen, (Thu Oct 25, 5:55 am)
Re: Is gcc thread-unsafe?, Arjan van de Ven, (Thu Oct 25, 12:35 am)
speck-geostationary