Getting rid of alignment faults in userspace
Paul Brook
paul at codesourcery.com
Fri Jun 17 22:53:21 UTC 2011
> >> There is still going to be a small cost even in hardware fixup so this
> >> is very much worth solving despite it's "becoming invisible" because the
> >> chips are hiding / solving it already.
> >
> > But I believe that h/w feature is turned off in Linux by default. You
> > have to add noalign to the kernel command line to enable.
>
> I think you'll find the hardware fixups are enabled by default on CPUs
> with that design, quite possibly it can't be turned off.
The situation is much more complicated than that. There are two completely
different models for misaligned accesses (v6 and pre-v6). v7 cores are only
required to support the former.
However even under the v6 model some instructions will fault on misaligned
addresses, and the CPU may be configured to fault many others. The exact
behavior depends on the particular instruction chosen by the compiler. I
don't know whether Linux currently knows how to enable alignment checking on
v6/v7 hardware.
> int main(int argc, char * argv[])
> {
>
> char buf[8];
> void *v = &buf[1];
> unsigned int *p = (unsigned int *)v;
This does not (reliably) do what you expect. The compiler need not align buf.
Paul
More information about the ubuntu-devel
mailing list