public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Mike Frysinger <vapier@gentoo.org>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] fat: fix unaligned errors
Date: Fri, 2 Jan 2009 20:47:08 -0500	[thread overview]
Message-ID: <200901022047.09037.vapier@gentoo.org> (raw)
In-Reply-To: <20090102234850.611588387CDB@gemini.denx.de>

On Friday 02 January 2009 18:48:50 Wolfgang Denk wrote:
> In message <200901021742.05363.vapier@gentoo.org> you wrote:
> > > > +__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.
>
> It is not (only) the size of the "largest" member in a struct which
> determins global alignment, but also the size of the struct itself.
>
> See for example
> http://gcc.gnu.org/onlinedocs/gcc-4.3.2/gcc/Type-Attributes.html
>
> Read especially this part:
>
> 	In the example above, if the size of each short is 2 bytes,
> 	then the size of the entire struct S type is 6 bytes. The
> 	smallest power of two which is greater than or equal to that
> 	is 8, so the compiler sets the alignment for the entire struct
> 	S type to 8 bytes.

i was not aware of this, thanks for the highlight

> > > 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
>
> Maybe you should have searched for the (IMHO pretty obvious) term
> "Alignment" as well, i.e. look at
> http://gcc.gnu.org/onlinedocs/gcc-4.3.2/gcc/Alignment.html#Alignment
>
> Quote:
>
> 	The keyword __alignof__ allows you to inquire about how an
> 	object is aligned, or the minimum alignment usually required
> 	by a type. Its syntax is just like sizeof.

well i guess we cant all be "Wolfgang Denk"s
-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/b1503012/attachment-0001.pgp 

  reply	other threads:[~2009-01-03  1:47 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-02  0:54 [U-Boot] [PATCH] fat: fix unaligned errors Mike Frysinger
2009-01-02  9:32 ` Remy Bohmer
2009-01-02 10:16   ` Mike Frysinger
2009-01-02 22:20 ` Wolfgang Denk
2009-01-02 22:42   ` Mike Frysinger
2009-01-02 23:48     ` Wolfgang Denk
2009-01-03  1:47       ` Mike Frysinger [this message]
2009-01-03  1:47       ` [U-Boot] [PATCH v2] " Mike Frysinger
2009-01-24  1:03         ` Wolfgang Denk

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200901022047.09037.vapier@gentoo.org \
    --to=vapier@gentoo.org \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox