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: Mon, 10 Feb 2014 23:17:23 +0100	[thread overview]
Message-ID: <20140210221723.B3DFB380603@gemini.denx.de> (raw)
In-Reply-To: <20140210212630.GB7049@bill-the-cat>

Dear Tom,

In message <20140210212630.GB7049@bill-the-cat> you wrote:
> 
> Then gcc has a bug and you need to convince them to fix it.  What gcc
> does, as Mans has explained, and this invalidates the "lets catch
> unaligned access problems" notion, is for ARMv6 and higher say "we
> assume by default the hardware can perform native unaligned access, so
> make use of this in our optimization choices".

GCC for ARM has often perplexed me - I remember cases where it
generated 4 single-byte accesses to a u32 data type with perfectly
valid 32 bit alignment (like a device register).  Unfortunaltely I
never was able to have this considered a bug.  Everybody else thought
it was perfectly normal and it had always been like that (on ARM).

> But this part isn't true.  Or rather, it is (or may, at the whim of the
> compiler) catching every case where we say __attribute__((packed)) and
> then don't follow up ensuring that every access is then fixed up by
> hand, rather than letting the compiler do it.
>
> We've essentially picked "lets blow things up at times" over "lets keep
> an eye out for __packed being used in code, and be careful there".

I think many people use __packed without thinking.  Some code is just
horrible.  The fact that ARM code is full of examples where device I/O
is performed without compiler checking for data types is just an
indication.

I know this is bad, but do you see a way to make the compiler issue
clear warnings or errors for such "accidential" unaligned accesses?

> The problem is that __packed means we can see this problem whenever its
> used.  This is the design practice we need to be wary of, and make sure
> we're coding to an unfortunate reality rather than misoptimizing things.

__packed should be strictly forbidden everywhere except where mandated
by definitions for example of protocol implementations etc.  And even
there I tend to consider it wrong to use 32 or 16 bit types for data
fields that are misaligned (assum=ing the whole data structure is
properly aligned).

> > Regarding the EFI code, there was a patch submitted (see the thread you
> > have pointed me to) which had the proper unaligned access macros and
> > thus did not require -mno-unaligned-access for this file, and certainly
> > does not require it for the whole of ARM.
>
> Right, the EFI patch takes valid code and makes it differently valid.

Takes valid code?  But would this original code run on an architecture
where any unaligned access causes a machine check?  My understanding
is it doesn't?

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
I've got to get something inside me. Some coffee  or  something.  And
then the world will somehow be better.
                                     - Terry Pratchett, _Men at Arms_

  reply	other threads:[~2014-02-10 22:17 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 [this message]
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
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=20140210221723.B3DFB380603@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