[U-Boot] [PATCH] fat: fix unaligned errors

Mike Frysinger vapier at gentoo.org
Fri Jan 2 23:42:04 CET 2009


On Friday 02 January 2009 17:20:47 Wolfgang Denk wrote:
> In message <vapier at gentoo.org> you wrote:
> > From: Bryan Wu <bryan.wu at analog.com>
> >
> > A couple of buffers in the fat code are declared as an array of bytes. 
> > But it is then cast up to a structure with 16bit and 32bit members. 
> > Since GCC assumes structure alignment here, we have to force the buffers
> > to be aligned according to the structure usage.
>
> ...
>
> > +__u8 get_vfatname_block[MAX_CLUSTSIZE] __attribute__
> > ((aligned(sizeof(__u16))));
>
> ...
>
> > +__u8 get_dentfromdir_block[MAX_CLUSTSIZE] __attribute__
> > ((aligned(sizeof(__u32))));
>
> ...
>
> > +__u8 do_fat_read_block[MAX_CLUSTSIZE] __attribute__
> > ((aligned(sizeof(__u32))));
>
> What makes you sure that a 16 resp. 32 bit alignment is sufficient,
> and that gcc does not decide to align such structures even stricter?

read the structures in question.  the largest member is 16bit/32bit.  i really 
dont know what other alignment gcc could randomly generate.

> Wouldn't it make more sense to use "__alignof__ ()" here to be on the
> safe side?

i found no such alignment attribute in the gcc docs which is why i suggested 
Bryan use aligned(sizeof(...)).
http://gcc.gnu.org/onlinedocs/gcc-4.3.2/gcc/Function-Attributes.html
http://gcc.gnu.org/onlinedocs/gcc-4.3.2/gcc/Variable-Attributes.html
http://gcc.gnu.org/onlinedocs/gcc-4.3.2/gcc/Type-Attributes.html
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 835 bytes
Desc: This is a digitally signed message part.
Url : http://lists.denx.de/pipermail/u-boot/attachments/20090102/1ce92c0d/attachment.pgp 


More information about the U-Boot mailing list