All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Jan Beulich" <JBeulich@novell.com>
To: Keir Fraser <Keir.Fraser@cl.cam.ac.uk>
Cc: xen-devel@lists.xensource.com
Subject: Re: [PATCH] i386 linux: make 32-bit PAE kernel work when built with newer gcc
Date: Tue, 14 Mar 2006 13:40:31 +0100	[thread overview]
Message-ID: <4416C7CF.76F0.0078.0@novell.com> (raw)
In-Reply-To: <9230e631fd895788ac861ef7099efe97@cl.cam.ac.uk>

>The compiler is certainly allowed to reorder those updates. The 
>constraints on a conforming implementation of C99 are pretty weak, and 
>don't say anything about obeying the rules for access/update ordering 
>on non-volatile objects. Whether gcc reorders such updates is another 
>matter. :-)

I'm not sure this is correct - the standard, in section 5.1.2.3, says

"Accessing a volatile object, modifying an object, modifying a file, or calling a function
that does any of those operations are all side effects, which are changes in the state of
the execution environment. Evaluation of an expression may produce side effects. At
certain specified points in the execution sequence called sequence points, all side effects
of previous evaluations shall be complete and no side effects of subsequent evaluations
shall have taken place."

As we're talking about modifying an object, this being considered a side-effect means it
must have been carried out by the time the ; is (logically) reached.

>If I build the following with -O2 on x86/64 gcc 4.1, the compiler 
>removes the first update of x. If I take a signal after the update of 
>y, the signal handler can see y==2, z!=2 but also x!=2, which disobeys 
>the semantics of the C99 abstract machine semantics:
>int x, y, z;
>void foo(void) { x = 2; y = 2; z = 2; x = 0; }

I believe it doing so is permitted by the fact that a signal here can only come from outside of
the program (the compiler can prove that none of these accesses can fault, at least not in
the sense the program cares about), and the standard doesn't care about 'outside'. If you
inserted a function call after the update to y, I'm sure the compiler would leave the first
write to x.

>Really it's safer just to include the barrier(), and makes our ordering 
>requirement explicit in the code.

It might still be safer, I agree, to prevent broken compiler versions to do bad.

Jan

  reply	other threads:[~2006-03-14 12:40 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-03-13 16:40 [PATCH] i386 linux: make 32-bit PAE kernel work when built with newer gcc Jan Beulich
2006-03-14 10:09 ` Keir Fraser
2006-03-14 10:40   ` Jan Beulich
2006-03-14 11:53     ` Keir Fraser
2006-03-14 12:40       ` Jan Beulich [this message]
2006-03-14 14:06         ` Keir Fraser
2006-03-14 14:31           ` Jan Beulich
2006-03-14 14:39             ` Keir Fraser
2006-03-17 10:19 ` Keir Fraser
2006-03-17 11:35   ` Jan Beulich
2006-03-17 11:51     ` Keir Fraser
2006-03-17 12:28       ` Jan Beulich
2006-03-17 13:24         ` Keir Fraser
2006-03-17 13:37           ` Jan Beulich
  -- strict thread matches above, loose matches on Subject: below --
2006-03-14 12:15 Petersson, Mats

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4416C7CF.76F0.0078.0@novell.com \
    --to=jbeulich@novell.com \
    --cc=Keir.Fraser@cl.cam.ac.uk \
    --cc=xen-devel@lists.xensource.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.