Strict aliasing and chains revisited

Sebastian Huber sebastian.huber at embedded-brains.de
Tue Oct 26 14:52:03 UTC 2010


On 10/25/2010 09:38 AM, Sebastian Huber wrote:
[...]
> Ok, I changed the Chain_Control definition to:
> 
> typedef union {
>     struct {
>       Chain_Node Node;
>       Chain_Node *fill;
>     } Head;
> 
>     struct {
>       Chain_Node *fill;
>       Chain_Node Node;
>     } Tail;
> } __attribute__ ((packed)) Chain_Control;
> 
> Test suites pass on ARM, MIPS and SPARC.  One problem with this change is that
> the field names change, and this may break applications which use this internal
> API.
[...]

The test suites do not pass on SPARC.  It seems that the packed attribute also
affects the alignment requirements for the union.  If you have for example this:

struct {
	char b;
	Chain_Control chain;
};

You will have an alignment exception on SPARC since chain is not aligned
properly.  If we use this packed attribute, then we will also have to add an
alignment attribute to the union.

-- 
Sebastian Huber, embedded brains GmbH

Address : Obere Lagerstr. 30, D-82178 Puchheim, Germany
Phone   : +49 89 18 90 80 79-6
Fax     : +49 89 18 90 80 79-9
E-Mail  : sebastian.huber at embedded-brains.de
PGP     : Public key available on request.

Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.



More information about the users mailing list