Android and compatibility with deprecated armv7 instructions

Russell King - ARM Linux linux at arm.linux.org.uk
Fri Jul 4 02:34:02 PDT 2014


On Fri, Jul 04, 2014 at 10:21:54AM +0100, Måns Rullgård wrote:
> Ard Biesheuvel <ard.biesheuvel at linaro.org> writes:
> >>> foo:
> >>> @ args = 0, pretend = 0, frame = 0
> >>> @ frame_needed = 0, uses_anonymous_args = 0
> >>> @ link register save eliminated.
> >>>     mov ip, r0
> >>>     ldmia r1, {r0, r1, r2, r3}
> >>>     stmia ip, {r0, r1, r2, r3}
> >>>     bx lr
> >>>
> >>> won't it take just a single cast from some unaligned char* to struct
> >>> bar* to trigger this?
> >>
> >> Is this even allowed by the C ABI?
> 
> No.

Sort of.  It isn't that legal, but we /do/ have bits of kernel code
(particularly networking) which /do/ make use of this.  Whether it's
legal or not really doesn't come into it.

It falls into the same class as the additional padding of structures
which caused soo much pain in the early days, where many people used
structures to define the layout of data passed between different
systems, expecting (eg) a three char struct to have a size of 3 rather
than 4.

The general rule for "portable" userspace has traditionally been "if it
works on x86, then the code is correct."  Unfortunately, you can do lots
of things on x86 which aren't legal C.

> > The point is not whether the C ABI allows it, the point is whether
> > a) the current 32-bit ARM kernel allows it, and
> 
> Unfortunately, it does.  In my opinion, adding the unaligned emulation
> code was a mistake, and turning it on by default was a bigger mistake.

Different people have differing opinions, and the decision was made
more than 14 years ago.  Hindsight is also a wonderful tool that we
could all use, but the problem is that's non-causal, so unless you
have a tardis or a time machine...

-- 
FTTC broadband for 0.8mile line: now at 9.7Mbps down 460kbps up... slowly
improving, and getting towards what was expected from it.



More information about the linux-arm-kernel mailing list