From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1bB6cj-0005Jc-Vj for mharc-grub-devel@gnu.org; Thu, 09 Jun 2016 16:32:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51728) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bB6ch-0005Gm-Ln for grub-devel@gnu.org; Thu, 09 Jun 2016 16:32:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bB6cf-00022u-Mz for grub-devel@gnu.org; Thu, 09 Jun 2016 16:32:14 -0400 Received: from aserp1040.oracle.com ([141.146.126.69]:19430) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bB6cf-00022q-Ea for grub-devel@gnu.org; Thu, 09 Jun 2016 16:32:13 -0400 Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id u59KW6Pu024781 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 9 Jun 2016 20:32:06 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userv0021.oracle.com (8.13.8/8.13.8) with ESMTP id u59KW5kH000573 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 9 Jun 2016 20:32:06 GMT Received: from abhmp0017.oracle.com (abhmp0017.oracle.com [141.146.116.23]) by aserv0122.oracle.com (8.13.8/8.13.8) with ESMTP id u59KW3dU030204; Thu, 9 Jun 2016 20:32:04 GMT Received: from olila.local.net-space.pl (/10.175.235.163) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 09 Jun 2016 13:32:02 -0700 From: Daniel Kiper To: grub-devel@gnu.org, xen-devel@lists.xenproject.org Cc: andrew.cooper3@citrix.com, arvidjaar@gmail.com, eric.snowberg@oracle.com, jgross@suse.com, konrad.wilk@oracle.com, phcoder@gmail.com, seth.goldberg@oracle.com Subject: [MULTIBOOT2 DOC PATCH 08/10] multiboot2: Add C structure alignment and padding consideration section Date: Thu, 9 Jun 2016 22:30:42 +0200 Message-Id: <1465504244-17175-9-git-send-email-daniel.kiper@oracle.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1465504244-17175-1-git-send-email-daniel.kiper@oracle.com> References: <1465504244-17175-1-git-send-email-daniel.kiper@oracle.com> X-Source-IP: userv0021.oracle.com [156.151.31.71] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 141.146.126.69 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 20:32:16 -0000 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 +members properly. Usually they reach the goal by adding some padding. +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. + + @node Notes on PC @section Notes on PC -- 1.7.10.4