public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Is gcc thread-unsafe?
@ 2007-10-25  3:24 Nick Piggin
  2007-10-25  3:46 ` Arjan van de Ven
                   ` (3 more replies)
  0 siblings, 4 replies; 61+ messages in thread
From: Nick Piggin @ 2007-10-25  3:24 UTC (permalink / raw)
  To: Linux Kernel Mailing List, Linus Torvalds, Kleen, Andi

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?

^ permalink raw reply	[flat|nested] 61+ messages in thread
[parent not found: <fa.JbRGo0cQWncrcfKHmiNdvchsA50@ifi.uio.no>]
[parent not found: <e2e108260710260729x4603211cgb68d7434ce1e54e9@mail.gmail.com>]
* Re: Is gcc thread-unsafe?
@ 2007-10-28 18:19 linux
  0 siblings, 0 replies; 61+ messages in thread
From: linux @ 2007-10-28 18:19 UTC (permalink / raw)
  To: bart.vanassche, linux-kernel; +Cc: aph, linux

Just a note on the attribute((acquire,release)) proposal:

It's nice to be able to annotate functions, but please don't forget to
provide a way to write such functions.  Ultimately, there will be an
asm() or assignment that is the acquire or release point, and GCC needs
to know that so it can compile the function itself (possibly inline).

Having just a function attribute leaves the problem that

void __attribute__((noreturn))
_exit(int status)
{
	asm("int 0x80" : : (__NR_exit) "a", (status) "b" );
}

generates a complaint about a noreturn function returning, because
there's no way to tell GCC about a non-returning statement.

^ permalink raw reply	[flat|nested] 61+ messages in thread

end of thread, other threads:[~2007-11-04 18:06 UTC | newest]

Thread overview: 61+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-10-25  3:24 Is gcc thread-unsafe? Nick Piggin
2007-10-25  3:46 ` Arjan van de Ven
2007-10-25  3:58   ` Nick Piggin
2007-10-25  4:29     ` David Schwartz
2007-10-25  4:35       ` Arjan van de Ven
2007-10-25 18:45         ` Måns Rullgård
2007-10-25  4:47       ` Nick Piggin
2007-10-25  9:40         ` Samuel Tardieu
2007-10-25  9:44         ` Samuel Tardieu
2007-10-25  9:54           ` Samuel Tardieu
2007-10-25  9:55           ` Andi Kleen
2007-10-25  7:15 ` Andi Kleen
2007-10-25 11:58   ` linux-os (Dick Johnson)
2007-10-25 12:16     ` Andi Kleen
2007-10-25 22:49   ` Nick Piggin
2007-10-25 23:09     ` Andi Kleen
2007-10-25 23:14       ` Linus Torvalds
2007-10-25 23:16         ` Andi Kleen
2007-10-25 23:32           ` Linus Torvalds
2007-10-25 23:42             ` Andi Kleen
2007-10-25 23:57               ` Linus Torvalds
2007-10-26  1:15                 ` Zachary Amsden
2007-10-26  4:57               ` Willy Tarreau
2007-10-25 23:43       ` Nick Piggin
2007-10-25 23:55         ` Andi Kleen
2007-10-25 23:57           ` Nick Piggin
2007-10-25 14:55 ` Linus Torvalds
2007-10-25 15:12   ` Pekka Enberg
2007-10-25 21:42   ` David Schwartz
2007-10-25 23:22     ` Nick Piggin
2007-10-26 11:59       ` Andrew Haley
2007-10-26 11:59       ` Andrew Haley
2007-10-26 17:39         ` Chris Friesen
2007-10-25 22:26   ` Ismail Dönmez
2007-10-25 22:56     ` Jeff Garzik
2007-10-25 23:04       ` Jeff Garzik
2007-10-31 22:10 ` Phillip Susi
     [not found] <fa.JbRGo0cQWncrcfKHmiNdvchsA50@ifi.uio.no>
     [not found] ` <fa.8qDECVaPIo7DWbjhQbyw6N5Infg@ifi.uio.no>
     [not found]   ` <fa.M4DOMggyrQmdTqekWSuw4xCxiTc@ifi.uio.no>
2007-10-25 23:27     ` Robert Hancock
     [not found] <e2e108260710260729x4603211cgb68d7434ce1e54e9@mail.gmail.com>
2007-10-26 14:40 ` Bart Van Assche
2007-10-26 15:09   ` Linus Torvalds
2007-10-26 15:34     ` Andrew Haley
2007-10-26 18:06       ` David Schwartz
2007-10-30 10:20         ` Andrew Haley
2007-11-02 15:29           ` Bart Van Assche
2007-11-02 15:38             ` Andrew Haley
2007-11-04 15:13               ` Bart Van Assche
2007-11-04 17:45                 ` Linus Torvalds
2007-11-04 17:58                   ` Andrew Haley
2007-11-04 18:06                   ` Bart Van Assche
2007-11-02 17:18             ` David Schwartz
2007-10-26 21:45     ` Giacomo Catenazzi
2007-10-26 22:24       ` Linus Torvalds
2007-10-26 15:27   ` Linus Torvalds
2007-10-26 16:28     ` Linus Torvalds
2007-10-26 17:07       ` Bart Van Assche
2007-10-26 17:12         ` Andrew Haley
2007-10-26 17:25           ` Linus Torvalds
2007-10-26 18:08         ` Alan Cox
2007-10-26 18:14           ` Linus Torvalds
2007-10-26 20:39           ` Andi Kleen
  -- strict thread matches above, loose matches on Subject: below --
2007-10-28 18:19 linux

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox