This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/51628] __attribute__((packed)) is unsafe in some cases
- From: "rguenther at suse dot de" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 20 Dec 2011 11:04:37 +0000
- Subject: [Bug c/51628] __attribute__((packed)) is unsafe in some cases
- Auto-submitted: auto-generated
- References: <bug-51628-4@http.gcc.gnu.org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51628
--- Comment #6 from rguenther at suse dot de <rguenther at suse dot de> 2011-12-20 11:04:37 UTC ---
On Tue, 20 Dec 2011, ebotcazou at gcc dot gnu.org wrote:
> 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 ;-)
Huh, it's not. It's the same as a packed struct or enum type. Why
can't you strict-align people simply fix this case?
Richard.