[Bug c/51628] __attribute__((packed)) is unsafe in some cases
ebotcazou at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Tue Dec 20 10:54:00 GMT 2011
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51628
--- Comment #5 from Eric Botcazou <ebotcazou at gcc dot gnu.org> 2011-12-20 10:52:19 UTC ---
> The point is that even if you use sth like
>
> typedef int myint __attribute__((aligned(1)));
>
> to capture the misaligned pointer to the packed structure element:
>
> myint *p = &s->i;
>
> then accesses like '*p' will still assume an _aligned_ int at 'p' for
> STRICT_ALIGNMENT targets.
>
> That's a long-long-long-standing bug and a cause of major headache for
> more modern GCCs even ...
That's a limitation rather than a bug. Clearly, on strict-alignment targets,
you must know what you're doing when you start to misalign things. As for
typedef int myint __attribute__((aligned(1)));
that's an abomination I don't even want to know of ;-)
More information about the Gcc-bugs
mailing list