Re: Getting rid of alignment faults in userspace
> >> 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
> int main(int argc, char * argv)
> char buf;
> void *v = &buf;
> unsigned int *p = (unsigned int *)v;
This does not (reliably) do what you expect. The compiler need not align buf.