From: Daniel Kiper <daniel.kiper@oracle.com> To: Andrew Cooper <andrew.cooper3@citrix.com> Cc: jgross@suse.com, grub-devel@gnu.org, arvidjaar@gmail.com, phcoder@gmail.com, eric.snowberg@oracle.com, seth.goldberg@oracle.com, xen-devel@lists.xenproject.org Subject: Re: [MULTIBOOT2 DOC PATCH 08/10] multiboot2: Add C structure alignment and padding consideration section Date: Fri, 10 Jun 2016 19:58:08 +0200 [thread overview] Message-ID: <20160610175808.GF5490@olila.local.net-space.pl> (raw) In-Reply-To: <1c1e54de-2f19-20b6-b8c8-229619b95038@citrix.com> On Thu, Jun 09, 2016 at 11:07:12PM +0100, Andrew Cooper wrote: > On 09/06/2016 21:30, Daniel Kiper wrote: > > Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com> > > --- > > doc/multiboot.texi | 17 +++++++++++++++++ > > 1 file changed, 17 insertions(+) > > > > diff --git a/doc/multiboot.texi b/doc/multiboot.texi > > index c81b2ea..bf02a1b 100644 > > --- a/doc/multiboot.texi > > +++ b/doc/multiboot.texi > > @@ -1384,6 +1384,7 @@ document, but are included for prospective operating system and boot > > loader writers. > > > > @menu > > +* C structure alignment and padding consideration:: > > * Notes on PC:: > > * BIOS device mapping techniques:: > > * Example OS code:: > > @@ -1391,6 +1392,22 @@ loader writers. > > @end menu > > > > > > +@node C structure alignment and padding consideration > > +@section C structure alignment and padding consideration > > + > > +Many C compilers try to optimize memory accesses aligning structure > > "by aligning" > > > +members properly. Usually they reach the goal by adding some padding. > > What does "properly" mean here? The default padding will be specified > by the default ABI the compiler conforms to. Right. I do not want to go into the details in this section and duplicate anything which is much better described somewhere else. So, that is why I use "properly" here. However, if you think that it can be phrased better then drop me a line. > > +This is very useful thing in general. However, if you try to mix assembler > > +with C or use C to implement structure low level access this behavior > > +may lead, at least, to quite surprising results. Hence, compiler should > > +be instructed to not optimize such accesses. Usually it is done by special > > +attribute added to structure definition, e.g. GCC compatible sources use > > +@samp{__attribute__ ((__packed__))} for this purpose. However, this is not > > +required if it is known that its members are properly aligned and compiler > > +does not do any optimization. Very good example of this is shown below in > > +@file{multiboot2.h} file. > > I am not sure what you are trying to say. Do you refer to whole paragraph or last sentence? In general I would like to say that guys should pay attention to proper usage of struct construct in C and be aware that bad things may happen when they introduce new tags structs without __packed__ attribute. However, they also should be aware that __packed__ is not always required. And tag structs in multiboot2.h file does not contain __packed__ attribute because they are build in proper way. I hope that helps. Daniel _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel
next prev parent reply other threads:[~2016-06-10 17:58 UTC|newest] Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top [not found] <1465504244-17175-1-git-send-email-daniel.kiper@oracle.com> 2016-06-09 20:30 ` [MULTIBOOT2 DOC PATCH 01/10] multiboot2: Remove redundant if Daniel Kiper 2016-06-09 20:30 ` [MULTIBOOT2 DOC PATCH 02/10] multiboot2: Clarify meaning of information request header tag Daniel Kiper 2016-06-09 21:14 ` Andrew Cooper 2016-06-09 20:30 ` [MULTIBOOT2 DOC PATCH 03/10] multiboot2: Fix description of EFI boot services tag Daniel Kiper 2016-06-09 20:30 ` [MULTIBOOT2 DOC PATCH 04/10] multiboot2: Add description of support for EFI boot services Daniel Kiper 2016-06-09 20:30 ` [MULTIBOOT2 DOC PATCH 05/10] multiboot2: Add description of EFI image handle tags Daniel Kiper 2016-06-09 20:30 ` [MULTIBOOT2 DOC PATCH 06/10] multiboot2: Add description of support for relocatable images Daniel Kiper 2016-06-09 21:36 ` Andrew Cooper 2016-06-10 17:36 ` Daniel Kiper 2016-06-09 20:30 ` [MULTIBOOT2 DOC PATCH 07/10] multiboot2: Say that memory maps may not be available on EFI platforms Daniel Kiper 2016-06-09 21:37 ` Andrew Cooper 2016-06-09 20:30 ` [MULTIBOOT2 DOC PATCH 08/10] multiboot2: Add C structure alignment and padding consideration section Daniel Kiper 2016-06-09 22:07 ` Andrew Cooper [not found] ` <1c1e54de-2f19-20b6-b8c8-229619b95038@citrix.com> 2016-06-10 17:58 ` Daniel Kiper [this message] 2016-06-09 20:30 ` [MULTIBOOT2 DOC PATCH 09/10] multiboot2: Add me to authors Daniel Kiper 2016-06-09 20:30 ` [MULTIBOOT2 DOC PATCH 10/10] multiboot2: Bump version to 2.0 Daniel Kiper [not found] ` <1465504244-17175-2-git-send-email-daniel.kiper@oracle.com> 2016-06-09 21:02 ` [MULTIBOOT2 DOC PATCH 01/10] multiboot2: Remove redundant if Andrew Cooper [not found] ` <1465504244-17175-5-git-send-email-daniel.kiper@oracle.com> 2016-06-09 21:31 ` [MULTIBOOT2 DOC PATCH 04/10] multiboot2: Add description of support for EFI boot services Andrew Cooper
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=20160610175808.GF5490@olila.local.net-space.pl \ --to=daniel.kiper@oracle.com \ --cc=andrew.cooper3@citrix.com \ --cc=arvidjaar@gmail.com \ --cc=eric.snowberg@oracle.com \ --cc=grub-devel@gnu.org \ --cc=jgross@suse.com \ --cc=phcoder@gmail.com \ --cc=seth.goldberg@oracle.com \ --cc=xen-devel@lists.xenproject.org \ --subject='Re: [MULTIBOOT2 DOC PATCH 08/10] multiboot2: Add C structure alignment and padding consideration section' \ /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
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).