Subject: Re: arm, net and '__attribute__ ((__packed__))'
To: Sami Kantoluoto <sami.kantoluoto@embedtronics.fi>
From: Richard Earnshaw <Richard.Earnshaw@buzzard.freeserve.co.uk>
List: tech-net
Date: 02/05/2005 14:04:14
On Sat, 05 Feb 2005 15:48:39 +0200, Sami Kantoluoto wrote:
> Hi,
> 
> We're using the network stack and wi driver ported from NetBSD to our
> embedded operating system and I'm wondering if there's something wrong with
> missing '__attribute__ ((__packed__))'s or something. So, I noticed that
> 'sizeof(struct llc)' returned 10 (arm-elf-gcc 3.4.2). Then I removed the
> comments (and 'XXX' and '???') from 'llc_un'. Which means:
> 
> struct llc {
> 	u_int8_t llc_dsap;
> 	u_int8_t llc_ssap;
> 	union {
> 		.
> 		.
> 		.
> 	} llc_un __attribute__((__packed__));
> } __attribute__((__packed__));
> 
> This had no effect. Then I swapped 'llc_un' and
> '__attribute__((__packed__))' and it worked (sizeof(struct llc) == 8). So:
> 
> struct llc {
> 	u_int8_t llc_dsap;
> 	u_int8_t llc_ssap;
> 	union {
> 		.
> 		.
> 		.
> 	} __attribute__((__packed__)) llc_un;
> } __attribute__((__packed__));
> 
> 
> I can't believe that NetBSD has any problems with these so maybe I'm missing
> some compiler options or has NetBSD's gcc been patched or something else?
> 

NetBSD uses gcc configured with structure-size-boundary set to 8, rather 
than 32 (the default for a standard arm-elf compiler).  Which is why you 
are seeing this problem.  Try building *all* your code with 
-mstructure-size-boundary=8.

But yes, this is probably a bug in the header file.  Could you file a PR?

R.