[U-Boot] [PATCH v2] arm: Switch to -mno-unaligned-access when supported by the compiler

Albert ARIBAUD albert.u.boot at aribaud.net
Tue Feb 11 17:37:55 CET 2014


Hi Måns,

On Tue, 11 Feb 2014 15:33:09 +0000, Måns Rullgård <mans at mansr.com>
wrote:

> The problem is that the current settings do
> the exact opposite.  By using -munaligned-access by default, you are
> asking the compiler to go ahead and do whatever it thinks is best, which
> is sometimes to perform an intentional unaligned access.  Exactly when
> this will happen is largely impossible to predict.

The -munaligned-access option does *not* "[ask] the compiler to go
ahead and do whatever it thinks is best", it tells it to use direct
native accesses when unaligned accesses are required, as opposed to
splitting unaligned accesses into smaller but aligned aligned native
accesses, which is what you get with -mno-unaligned-access.

> To get the behaviour you desire, the code should be compiled with
> -mno-unaligned-access.  This tells the compiler to _never_ automatically
> perform an unaligned memory access.  If it thinks an address might be
> unaligned, it will split the access.

This shows that you really have not read my argument, in which I *did*
explain why we tell the compiler *not* to split unaligned accesses into
smaller correctly aligned accesses, i.e., why -munaligned-access is
used.

> Note also that adding -mno-unaligned-access results in exactly the same
> compiler behaviour as we always had prior to gcc 4.7, which presumably
> generated usable code.

And hid potential unaligned accesses which would harm some other
platforms, because not all platforms have -m[no-]unaligned-access or
even a concept of unaligned access.

Amicalement,
-- 
Albert.


More information about the U-Boot mailing list