[uClinux-dev] ARM. allignment needed?

Friedrich, Lars lars.friedrich at wago.com
Wed Aug 3 16:19:54 EDT 2005


> >> 1. Structs must be aligned on ARM, right (4 bytes?)?
> > No.(Although life tends to be easier.)
> That means that a kernel module using arbitrary size structs
> will work ok, right?

No. It means that a kernel module using arbitrary size structs
might work.

> I don't get it. Compiler tends to align my structs to 4-byte.
> Is this done to help the processor?

The processor never has problems. It's usually the software that
doesn't like it when the processor generates an exception or that
doesn't know how to do 4-byte aligned accesses on unaligned data
without screwing up. So the compiler does it to help the software
developer.

> If i use packed, processor won't have any problems?

packed reduces the alignment to the smallest possible value,
usually 1 byte. It will help you if you have a problem with
aligned structures. If you need to align a structure, the
attribute is 'aligned'.

> So, what do you propose? Is attribute packed gonna solve my problem
>(if this is my problem)?

If you don't know the problem, how shall I know it or even know how
to solve it?

> Generally, should i use packed all over my code?

How shall I know without knowing the code? But generally,
no attribute is needed. Attribute/pragma specifiers for the
compiler are always for the 'not general' case.

> P.S. I have no experience in ARM (generally embedded).

This is not an ARM only issue.

> P.S.2 How do is alignment check enabled/disabled?

This should be explained in the hardware reference manual of your
processor/SoC.

Best regards,
Lars Friedrich



More information about the uClinux-dev mailing list