public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Wolfgang Denk <wd@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2] arm: Switch to -mno-unaligned-access when supported by the compiler
Date: Tue, 11 Feb 2014 15:43:49 +0100	[thread overview]
Message-ID: <20140211144349.CBF9938032B@gemini.denx.de> (raw)
In-Reply-To: <yw1xob2dakq4.fsf@unicorn.mansr.com>

Dear M?ns Rullg?rd,

In message <yw1xob2dakq4.fsf@unicorn.mansr.com> you wrote:
> 
> > We are not discussing application code here.
> 
> What does that have to do with anything.  The compiler works exactly the
> same whatever the code is for.

With application code you don't really care whether a variable is
read/written in one piece or broken down into several smaller
reads/writes - except when you notice that performance suffers.

When accessing hardware, it often makes a fundamental difference
whether you access a device register with it's correct size or not.
Usually breaking down an access into smaller ones results in crashes
or incorrect data or other errors.

> > We are dealing with low- level hardware related stuff.  When I try to
> > read from a 32 bit device register I must be absolutley sure that this
> > will be a single 32 bit transfer.  It is totally unacceptable if I
> > have to fear that the compiler might break this up into 4 byte
> > accesses behind my back.
> 
> So because you're afraid of __packed abuse, you want to make _other_
> completely valid code crash?  Would it not be preferable to make the
> actually broken code fail?  Then someone might notice and fix it.
> Furthermore, the scenario you seem worried about will still happen on
> ARMv5 and other architectures which do not support unaligned memory
> accesses.

I wonder if you actually read Albert's arguments.  I'll try to put it
in simple words for you.

No, this is not about __packed, at least not primarily.  We are
talking about code that performs unaligned accesses.  There are
architectures where the hardware supports this just fine; there are
others where you pay for this with some penalty, but it still works;
and there are yet others where it just does not work.  And we cannot
rely on the compiler to do "the right thing" because the compiler
assumes the "application" model described above, while we need the
"device access" model, i. e. something different.  And we want all
code (unless it is not inherently deeply architecture-specific) to be
working on all architectures, whether these support unaligned
accesses or not.

So I would like to adjust the default behaviour of the compiler to
raise errors or at least warnings for all such unaligned accesses
that he is capable of detecting, and I want clear runtime errors for
the rest, on all architectures. Code that causes such errors needs to
be reviewed and, normally, to be fixed.  In cases where there are
good reasons to perform unaligned accesses, these should normally
be done explicitly, without automatic help from the compiler.  Only if
there is such good reasons for unaligned accesses AND there are good
reasons not to touch the code AND we are sure it will not break on
some architectures, then we should allow the compiler to use it's
automatics.


BTW: thanks for the friendly words you found for me elsewhere.

Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
What about WRITING it first and rationalizing it afterwords?  :-)
                       - Larry Wall in <8162@jpl-devvax.JPL.NASA.GOV>

  reply	other threads:[~2014-02-11 14:43 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-04 17:05 [U-Boot] [PATCH v2] arm: Switch to -mno-unaligned-access when supported by the compiler Tom Rini
2014-02-04 17:35 ` Måns Rullgård
2014-02-10  9:24 ` Albert ARIBAUD
2014-02-10 13:21   ` Tom Rini
2014-02-10 14:57     ` Albert ARIBAUD
2014-02-10 15:14       ` Måns Rullgård
2014-02-10 15:40         ` Måns Rullgård
2014-02-10 16:12         ` Albert ARIBAUD
2014-02-10 16:21           ` Måns Rullgård
2014-02-10 16:24           ` Tom Rini
2014-02-10 17:26             ` Albert ARIBAUD
2014-02-10 18:54               ` Wolfgang Denk
2014-02-10 21:26               ` Tom Rini
2014-02-10 22:17                 ` Wolfgang Denk
2014-02-10 22:28                   ` Tom Rini
2014-02-11  8:19                     ` Wolfgang Denk
2014-02-11 12:37                       ` Måns Rullgård
2014-02-11 14:43                         ` Wolfgang Denk [this message]
2014-02-11 15:33                           ` Måns Rullgård
2014-02-11 16:37                             ` Albert ARIBAUD
2014-02-11 16:44                               ` Måns Rullgård
2014-02-11 17:11                                 ` Albert ARIBAUD
2014-02-11 17:21                                   ` Albert ARIBAUD
2014-02-12 14:35                               ` Tom Rini
2014-02-12 16:19                                 ` Albert ARIBAUD
2014-02-17 15:45                                   ` Tom Rini
2014-02-17 15:55                                     ` Albert ARIBAUD
2014-02-11 18:18                             ` Wolfgang Denk
2014-02-11 18:21                               ` Måns Rullgård
2014-02-11  8:44                     ` Albert ARIBAUD
2014-02-12 14:25                       ` Tom Rini
2014-02-12 15:51                         ` Wolfgang Denk
2014-02-10 15:21       ` Tom Rini

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=20140211144349.CBF9938032B@gemini.denx.de \
    --to=wd@denx.de \
    --cc=u-boot@lists.denx.de \
    /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