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: Arnd Bergmann <arnd at arndb dot de>
- To: Alan Stern <stern at rowland dot harvard dot edu>
- Cc: Rabin Vincent <rabin at rab dot in>, linux-arm-kernel at lists dot infradead dot org, linux-usb at vger dot kernel dot org, Ulrich Weigand <Ulrich dot Weigand at de dot ibm dot com>, linux-kernel at vger dot kernel dot org, gcc at gcc dot gnu dot org, Peter Maydell <peter dot maydell at linaro dot org>
- Date: Thu, 28 Apr 2011 16:16:40 +0200
- Subject: Re: ARM unaligned MMIO access with attribute((packed))
- References: <Pine.LNX.4.44L0.1104280934080.2108-100000@iolanthe.rowland.org>
On Thursday 28 April 2011, Alan Stern wrote:
> > The compiler does not complain, it just silently assumes that it needs
> > to do byte accesses. There is no way to tell the compiler to ignore
> > what it knows about the alignment, other than using inline assembly
> > for the actual pointer dereference. Most architectures today do that,
> > but on ARM it comes down to "*(u32 *)status_reg = temp".
>
> Ah -- so the compiler associates the alignment attribute with the data
> value and not with the variable's type? I didn't know that.
The behavior here is unspecified because the underlying typecase
is not valid. Gcc apparently uses some heuristics trying to do
the right thing, and in recent versions that heuristic seems to
have changed.
Arnd