David Dyck @ Tue, 12 Feb 2008 23:34:25 -0800 (PST)

> On Feb 12, 2008 8:07 PM, Oleg Verych  wrote:
>
>> Daniel Drake is author of the driver for _wireless_ chip[1]. After
>> recognizing his ignorance, he wrote this[0]:
>>
>> [0] http://lwn.net/Articles/260456/
>
> In the above article Daniel discussed the use of __attribute__((packed))
> and he stated that
>      " ...the compiler is aware

Stop.

[^]
> Daniel's statement that the compiler can support access to unaligned 
> variables may seem confusing compared to the mspgcc manual
>     http://mspgcc.sourceforge.net/manual/x214.html

You are repeating doc link, i've posted earlier in thread. That link is
*the* description of what msp430 GCC does -- no magic WRT unaligned
access in generated asm, and asm doesn't report errors. This is why i've
made a citation "catch you out" from there.

Linux kernel is kind of different. It uses GCC for big-iron hardware (ARM
included). Also it uses ICC (from Intel). So, they have both userspace
(application) and compiler issues with unaligned access. While latter
just may have bugs in the *magic*[0], former is problem of the application
programmers (e.g. SIGKILL, data corruption, etc.[1])

(tnx 2 google)
[0] http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14782
    http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16407
    http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23539

[1] http://www.aleph1.co.uk/oldsite/armlinux/book/afaq.html
    http://lecs.cs.ucla.edu/wiki/index.php/XScale_alignment

By using msp430 toolchain (C, asm), decision must be made by designers of
SoC, how to deal with that: manual align, access wrappers, fix toolchain,
whatever.

>      of the alignment constraints and will generate extra instructions to 
> perform
>      the memory access in a way that does not cause unaligned access. Of 
> course,
>      the extra instructions obviously cause a loss in performance compared to 
> the
>      non-packed case, so the packed attribute should only be used when 
> avoiding
>      structure padding is of importance. ..."
>
>      (He also gives some workarounds that might help WenZhan Song and
>       others to create portable code.)

(again, not for bare metal embedded, it is just for one's information)

[^]
> This article
>     
> http://mail.millennium.berkeley.edu/pipermail/tinyos-help/2006-February/014755.html
> refers to the manual and states:
>     "This is why the packed attribute is very, very bad for the msp430."

Now, let's see that stuff about "packed".

Note, that "packed" means "that the minimum required memory be used to
represent the type" (gcc info ref.) -- i.e. no padding. There is nothing
said about alignment. Consider http://lkml.org/lkml/2006/12/6/212
.

Alignment of members as well as whole structure is arbitrary. That's why
mspgcc have "packed" attribute, but it's without (implicit for many
developers) magic.

Thus, the only problem for newcomers is that info the mspgcc manual is
just a tip of the iceberg. TI have no or little info on that, compiler
vendors do magic.

Maybe mspgcc assembler must just warn about known unaligned access in the
code, or docs must have more refs on the subject, or something already
done in development tree?

--
-o--=O`C
 #oo'L O
<___=E M


Reply via email to