From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1bB86h-00016K-8K for mharc-grub-devel@gnu.org; Thu, 09 Jun 2016 18:07:19 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48722) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bB86f-00016A-Sv for grub-devel@gnu.org; Thu, 09 Jun 2016 18:07:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bB86b-00021k-JW for grub-devel@gnu.org; Thu, 09 Jun 2016 18:07:16 -0400 Received: from ppsw-43.csi.cam.ac.uk ([131.111.8.143]:56643) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bB86b-000211-DU for grub-devel@gnu.org; Thu, 09 Jun 2016 18:07:13 -0400 X-Cam-AntiVirus: no malware found X-Cam-ScannerInfo: http://www.cam.ac.uk/cs/email/scanner/ Received: from host-92-20-240-11.as13285.net ([92.20.240.11]:50218 helo=[192.168.1.6]) by ppsw-43.csi.cam.ac.uk (smtp.hermes.cam.ac.uk [131.111.8.159]:587) with esmtpsa (PLAIN:amc96) (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) id 1bB86Y-00079b-p6 (Exim 4.86_36-e07b163) (return-path ); Thu, 09 Jun 2016 23:07:11 +0100 Subject: Re: [MULTIBOOT2 DOC PATCH 08/10] multiboot2: Add C structure alignment and padding consideration section To: Daniel Kiper , grub-devel@gnu.org, xen-devel@lists.xenproject.org References: <1465504244-17175-1-git-send-email-daniel.kiper@oracle.com> <1465504244-17175-9-git-send-email-daniel.kiper@oracle.com> Cc: arvidjaar@gmail.com, eric.snowberg@oracle.com, jgross@suse.com, konrad.wilk@oracle.com, phcoder@gmail.com, seth.goldberg@oracle.com From: Andrew Cooper Message-ID: <1c1e54de-2f19-20b6-b8c8-229619b95038@citrix.com> Date: Thu, 9 Jun 2016 23:07:12 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.1.1 MIME-Version: 1.0 In-Reply-To: <1465504244-17175-9-git-send-email-daniel.kiper@oracle.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Sender: Andrew Cooper X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 131.111.8.143 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 09 Jun 2016 22:07:18 -0000 On 09/06/2016 21:30, Daniel Kiper wrote: > Signed-off-by: Daniel Kiper > --- > 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. > +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. ~Andrew