[U-Boot] packed attribute problem

Wolfgang Denk wd at denx.de
Thu Oct 7 19:57:01 CEST 2010


Dear Scott Wood,

In message <20101007114634.70e0f197 at udp111988uds.am.freescale.net> you wrote:
>
> I think this gets down to how such pointers are generated -- if you
> stick with well-defined C, the compiler/ABI should be able to avoid
> generating an unaligned pointer.

It is a pretty common method to use a pointer to some struct (for
example, some form of PDU) and make it point to some I/O buffer.
Depending on I/O subsystem, pre-pended protocol headerss and such the
resulting pointer may or may not be aligned. This is something that
the compiler has zero influence on.  [Yes, of course the application
could always copy the data to a properly aligned memory region. But I
bet you would quickly complain about the poor throughput if the
network stack on your systems were implemented that way.]

> > I may be wrong here, but I cannot
> > think of any statement in the standards in this regard - it's only data
> > types that imply alignments.
> 
> Pointers point to typed data...

Yes, and these typed date can be anywhere, even on addresses that
don't match the natural alignment of these data.

> C doesn't guarantee this, and it would be broken on certain chips

Actually I consider this a deficiency in the C specification. I've
been using C since Unix Version 6, and to me it is still mostly a
high-level assembler language. I definitly do not want the compiler
to do different things than what I tell him.

> when unaligned, e.g. old ARM chips that do weird rotaty things rather
> than trap when you do an unaligned access.

I think it was acceptable for such systems to enforce the compiler (by
setting special compiler switches) to implement such extra access modes.
But doing it by default and unconditionally for all systems of that
architecture seems broken to me. It's unfair collective punishment.

But alas. That's how it is in ARM land...


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
Perl already has an IDE.  It's called Unix.
                      -- Tom Christiansen in 375bd509 at cs.colorado.edu


More information about the U-Boot mailing list