[U-Boot] packed attribute problem

Detlev Zundel dzu at denx.de
Tue Oct 5 13:43:01 CEST 2010


Hi Reinhard,

[...]

>> Note that this is with GCC 4.2.2. Even GCC 4.0.0 behaves the same, so
>> this is *not* an issue with very recent tool chains.
>
> OK, for directly adressing elements inside a packed struct;
> but the original post said:
>
> "struct xyz {
> 	int	x;
> 	int	y;
> 	int	z[CONST];
> } __attribute__ ((packed));
>
> struct xyz *abc;
> u32 * status_reg = (u32 *)&abc->z[0];
>
> writel(status, status_reg);"
>
> So the "status_reg" pointer is in a completely unrelated (to the packed struct)
> "u32 *" and still the access is done like it was packed. If the
> compiler silently drags that attribute along into the "u32 *"
> THAT is really sick!

I cannot follow why you think this is sick - actually I think this is
clever.  GCC "knows" that abc points to a packed struct and it has no
clue on actual values, so it _has to assume_ it is not aligned.
status_reg is initialized as a pointer to a member of this unaligned
pointer and is thus also considered unaligned.  Seems perfectly fine to
me.

Cheers
  Detlev

-- 
BUGS:
  It is not yet possible to change operating system by writing to
  /proc/sys/kernel/ostype.
                                     -- Linux sysctl(2) man page
--
DENX Software Engineering GmbH,      MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich,  Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-40 Fax: (+49)-8142-66989-80 Email: dzu at denx.de


More information about the U-Boot mailing list