Getting rid of Unaligned Accesses (UA)
Maciej W. Rozycki
macro at linux-mips.org
Thu May 22 20:24:14 UTC 2008
On Thu, 22 May 2008, Jay Estabrook wrote:
> > It might be a good question to ask at a GCC list.
>
> Well, I tried asking one Alpha GCC guru, but never got a reply; I've
> been reluctant to try them all, so I tried here first... ;-}
This is what the list is for -- if somebody feels like willing to
investigate the problem, they will reply. At the very worst you will be
ignored, which may be annoying, but not exactly a disaster either (it
happened for me in the past too, yet I am still alive :-) ).
> > How's vp defined?
>
> Pointer to a UNION of different datatypes, so the pointer may be asked
> to point to anything from a char to a double.
Then GCC is allowed to assume the alignment of the data pointed to will
be that of the member of the union requiring the largest. And will
eagerly do so. ;-)
> > Well, __attribute__((packed)) used to be the usual way to ask GCC to
> > assume the worst when it comes to alignment while keeping the data size
> > intact. It has worked for years and if it got broken at any point, then
> > it is a bug in GCC.
>
> Doesn't the "packed" normally get applied to a struct?
Both struct and union definitions.
> In this case, since it's a UNION, what would "packed' mean?
With such a definition in scope:
union { int i; } __attribute__((packed)) *foo;
accesses to foo->i will be treated as unaligned by GCC. Verified to work
correctly with my Alpha/Linux-targeted cross-compiler which is 4.1.2 too,
except self-built, as you can imagine. ;-)
Maciej
More information about the axp-list
mailing list