Subject: RE: structure alignment on arm in NetBSD? (resend without html)
To: Valeriy E. Ushakov <uwe@stderr.spb.ru>
From: Martin Fouts <mfouts@danger.com>
List: tech-toolchain
Date: 10/16/2007 10:50:17
> From: tech-toolchain-owner@NetBSD.org=20
> [mailto:tech-toolchain-owner@NetBSD.org] On Behalf Of Valeriy=20
> E. Ushakov
> Sent: Tuesday, October 16, 2007 5:02 AM
> To: tech-toolchain@netbsd.org
> Subject: Re: structure alignment on arm in NetBSD? (resend=20
> without html)
>=20
> On Mon, Oct 15, 2007 at 18:11:09 +0000, Christos Zoulas wrote:
>=20
> > I am not sure, but the kernel structures should be fixed instead...
>=20
> As far as I understand, if ABI enforces 32-bit alignment on=20
> structs there's just no chance you can express things like=20
> the following, so I don't see how can you "fix" kernel=20
> structures for that.
>=20
> struct foo { /* common 2-bytes header */
> 	uint8_t a;
> 	uint8_t b;
> };
>=20
> struct bar { /* some 4-bytes "packet" with common header */
> 	struct foo;	/* oops, has two bytes of tail padding */
> 	uint8_t c;
> 	uint8_t d;
> };
>=20
>=20
> I guess that's why AAPCS reverted to naturally aligned structs.
>=20

A common solution to this problem is use the packed attribute to
indicate such structures and to allow the compiler to align to natural
boundaries otherwise.

It tends to aid in ABI compatibility, improves performance where the
packing would lead to poor code generation when not needed, and helps
document those structures which aren't necessarily machine independent.