public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Daniel Jacobowitz <dan@debian.org>
To: "Richard B. Johnson" <root@chaos.analogic.com>
Cc: jt@hpl.hp.com, Albert Cahalan <albert@users.sourceforge.net>,
	linux-kernel@vger.kernel.org, Jouni Malinen <jkmaline@cc.hut.fi>
Subject: Re: Invalid compilation without -fno-strict-aliasing
Date: Wed, 26 Feb 2003 14:42:09 -0500	[thread overview]
Message-ID: <20030226194209.GA20861@nevyn.them.org> (raw)
In-Reply-To: <Pine.LNX.3.95.1030226143644.5091B-100000@chaos>

On Wed, Feb 26, 2003 at 02:40:27PM -0500, Richard B. Johnson wrote:
> On Wed, 26 Feb 2003, Daniel Jacobowitz wrote:
> 
> > On Wed, Feb 26, 2003 at 01:23:19PM -0500, Richard B. Johnson wrote:
> > > On Wed, 26 Feb 2003, Jean Tourrilhes wrote:
> > > 
> > > > On Tue, Feb 25, 2003 at 11:33:09PM -0500, Albert Cahalan wrote:
> > > > > Jean Tourrilhes writes:
> > > > > 
> > > > > > It looks like a compiler bug to me...
> > > > > > Some users have complained that when the following
> > > > > > code is compiled without the -fno-strict-aliasing,
> > > > > > the order of the write and memcpy is inverted (which
> > > > > > mean a bogus len is mem-copied into the stream).
> > > > > > Code (from linux/include/net/iw_handler.h) :
> > > > > > --------------------------------------------
> > > > > > static inline char *
> > > > > > iwe_stream_add_event(char * stream,  /* Stream of events */
> > > > > >        char * ends,  /* End of stream */
> > > > > >        struct iw_event *iwe, /* Payload */
> > > > > >        int event_len) /* Real size of payload */
> > > > > > {
> > > > > >  /* Check if it's possible */
> > > > > >  if((stream + event_len) < ends) {
> > > > > >   iwe->len = event_len;
> > > > > >   memcpy(stream, (char *) iwe, event_len);
> > > > > >   stream += event_len;
> > > > > >  } return stream;
> > > > > > }
> > > > > > --------------------------------------------
> > > > > > IMHO, the compiler should have enough context to
> > > > > > know that the reordering is dangerous. Any suggestion
> > > > > > to make this simple code more bullet proof is welcomed.
> > > > > >
> > > > > > Have fun...
> > > > > 
> > > > > Since (char*) is special, I agree that it's a bug.
> > > > > In any case, a warning sure would be nice!
> > > > > 
> > > > > Now for the fun. Pass iwe->len into this
> > > > > macro before the memcpy, and all should be well.
> > > > > 
> > > > > #define FORCE_TO_MEM(x) asm volatile(""::"r"(&(x)))
> > > > > 
> > > > > Like this:
> > > > > 
> > > > >    iwe->len = event_len;
> > > > >    FORCE_TO_MEM(iwe->len);
> > > > >    memcpy(stream, (char *) iwe, event_len);
> > > > 
> > > > 	I'll try that, that sounds absolutely clever (but I only
> > > > understand half of it).
> > > > 	Thanks a lot !
> > > > 
> > > > 	Jean
> > > > -
> > > 
> > > This does absoultely nothing with egcs-2.91.66. I also modified
> > > 
> > >  #define FORCE_TO_MEM(x) asm volatile(""::"r"(&(x)))
> > >                                            |________ this to "memory"
> > > 
> > > and it still does nothing. The result of gcc -O2 -S -o xxx xxx.c just
> > > shows:
> > > 
> > > #AP
> > > #NOAP
> > > 
> > > With no code in-between.
> > > 
> > > I also changed it to:
> > >  #define FORCE_TO_MEM(x) __asm__ __volatile__(""::"r"(&(x)))
> > > to no avail.
> > > 
> > > What's up?
> > 
> > That's "working".  Does it prevent the reordering?
> 
> It was supposed to force x, which may be cached in a register,
> to be written to memory __now__. It doesn't seem to do anything.
> I think FORCE_TO_MEM() needs to claim that it uses most all the
> registers. That will make sure that any register values get
> written to their final memory locations.

If so it wouldn't be inside the #APP/#NOAPP markers.  You didn't answer
my other question: was X in memory at the time?

You should be using something like __asm__ __volatile__ (""::"m"(x))
anyway.

-- 
Daniel Jacobowitz
MontaVista Software                         Debian GNU/Linux Developer

  reply	other threads:[~2003-02-26 19:33 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-02-26  4:33 Invalid compilation without -fno-strict-aliasing Albert Cahalan
2003-02-26 17:20 ` Jean Tourrilhes
2003-02-26 18:23   ` Richard B. Johnson
2003-02-26 19:22     ` Daniel Jacobowitz
2003-02-26 19:40       ` Richard B. Johnson
2003-02-26 19:42         ` Daniel Jacobowitz [this message]
2003-02-26 20:19           ` Richard B. Johnson
2003-02-26 21:30             ` Albert Cahalan
  -- strict thread matches above, loose matches on Subject: below --
2003-02-25 23:46 Jean Tourrilhes
2003-02-26 15:38 ` Horst von Brand
2003-02-26 16:04   ` Falk Hueffner
2003-02-26 20:47     ` Horst von Brand
2003-02-26 20:57       ` Daniel Jacobowitz
2003-02-26 22:22         ` Jakub Jelinek
2003-02-27 19:30           ` Linus Torvalds
2003-02-27 19:45             ` Daniel Jacobowitz
2003-02-27 20:00               ` Linus Torvalds
2003-02-27 20:35                 ` Daniel Jacobowitz
2003-02-27 20:38                   ` Linus Torvalds
2003-02-27 23:55                     ` H. Peter Anvin
2003-03-01  8:29                     ` Anton Blanchard
2003-02-26 17:22   ` Jean Tourrilhes
2003-02-26 21:07     ` Horst von Brand
2003-02-27  4:41       ` Daniel Phillips
2003-02-26 17:26 ` Linus Torvalds

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=20030226194209.GA20861@nevyn.them.org \
    --to=dan@debian.org \
    --cc=albert@users.sourceforge.net \
    --cc=jkmaline@cc.hut.fi \
    --cc=jt@hpl.hp.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=root@chaos.analogic.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox