[U-Boot] packed attribute problem

Wolfgang Denk wd at denx.de
Mon Oct 4 14:56:36 CEST 2010


Dear Reinhard Meyer,

In message <4CA9CC04.5020800 at emk-elektronik.de> you wrote:
>
> In a non-packed struct an int will never be unaligned
> (unless you use an unaligned pointer to the whole struct)

Which may happen for example when overlaying such a struct on top of
some I/O buffer.

> In a packed struct an int might be unaligned, so it
> _might_ make sense for the compiler to handle that
> differently on ARM. Assume you overlay (bad idea anyway)

In a packed struct, where the struct itself is located with
sufficient alignment, and where all previous elements in the struct
are sufficiently aligned (like in the example I gave), it is NOT
possible that such unaligment happens.

> a packed structure over some communication data stream
> thats is byte oriented. On most architectures that would
> work (besides obvious endianess issues) but on ARM it would
> (without raising an exception) malfunction.

Keep in mind that the compiler knows the start address of the struct,
and the alignment of the elements. It could easily determine that no
unaligned accesses can result.

With the same logic you would have to enforce byte accesses for the
not-packed structs as well, as theese might be accessed through a not
sufficiently aligned pointer.

> 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!

We do agree on this statement. GCC on ARM is a strange beast.

Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
"The whole problem with the world is  that  fools  and  fanatics  are
always so certain of themselves, but wiser people so full of doubts."
- Bertrand Russell


More information about the U-Boot mailing list