This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: ARM unaligned MMIO access with attribute((packed))
- From: Russell King - ARM Linux <linux at arm dot linux dot org dot uk>
- To: Richard Guenther <richard dot guenther at gmail dot com>
- Cc: Arnd Bergmann <arnd at arndb dot de>, Peter Maydell <peter dot maydell at linaro dot org>, gcc at gcc dot gnu dot org, linux-usb at vger dot kernel dot org, linux-kernel at vger dot kernel dot org, Ulrich Weigand <Ulrich dot Weigand at de dot ibm dot com>, linux-arm-kernel at lists dot infradead dot org
- Date: Wed, 2 Feb 2011 17:09:59 +0000
- Subject: Re: ARM unaligned MMIO access with attribute((packed))
- References: <201102021700.20683.arnd@arndb.de> <AANLkTin6qEeN7XZuwePNWqS8i_aDY586V+sOqgD5pPQA@mail.gmail.com>
On Wed, Feb 02, 2011 at 05:51:27PM +0100, Richard Guenther wrote:
> > I would suggest fixing this by:
> >
> > 1. auditing all uses of __attribute__((packed)) in the Linux USB code
> > and other drivers, removing the ones that are potentially harmful.
> >
> > 2. Changing the ARM MMIO functions to use inline assembly instead of
> > direct pointer dereference.
> >
> > 3. Documenting the gcc behavior as undefined.
>
> The pointer conversions already invoke undefined behavior as specified by the
> C standard (6.3.2.3/7).
Just to be clear: you are not saying that the ARM implementation is
undefined.
What you're saying is that converting from a pointer with less strict
alignment requirements to a pointer with more strict alignment
requirements is undefined.
IOW:
unsigned long *blah(unsigned char *c)
{
return (unsigned long *)c;
}
would be undefined, but:
unsigned char *blah(unsigned long *c)
{
return (unsigned char *)c;
}
would not be.
If you're saying something else, please explain with reference to the
point in the C standard you quote above.