Subject: Re: alignment crash in v6 ipfilter when receiving on gif
To: Greg Troxel <firstname.lastname@example.org>
From: David Laight <email@example.com>
Date: 07/11/2007 19:38:26
On Tue, Jul 10, 2007 at 12:47:55PM -0400, Greg Troxel wrote:
> I think Martin is right that i6addr_t must be aligned to 64 bits and
> thus the compiler assumes it is after a cast and is correct to coalesce
> two 32-bit compares to a 64-bit compare.
> + struct in6_addr ip6_src;
> + /*
> + * There is no guarantee that ip6 is aligned to 64 bits,
> + * and gcc uses 64-bit loads because ip6_t contains
> + * pointers and thus must be 64-bit aligned.
> + */
> + memcpy(&ip6_src, &ip6->ip6_src,
> + sizeof(struct in6_addr));
Unless we force a function call for memcpy, the compiler can still
assume that the source is 64bit aligned and ensure that the target
is 64bit aligned and to 64bit operations for the copy!
IMHO this whole 'optimisation' in gcc sucks.
Having badly aligned pointers to structures is all too common in
David Laight: firstname.lastname@example.org