From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1jcTL8-0003lc-FN for mharc-grub-devel@gnu.org; Sat, 23 May 2020 08:33:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52936) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jcTL6-0003lP-I7 for grub-devel@gnu.org; Sat, 23 May 2020 08:33:20 -0400 Received: from relay01.mx.bawue.net ([193.7.176.67]:45328 helo=smtp.bawue.net) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jcTL5-0006Ak-0f for grub-devel@gnu.org; Sat, 23 May 2020 08:33:19 -0400 Received: from n-dimensional.de (p5b17584c.dip0.t-ipconnect.de [91.23.88.76]) (Authenticated sender: pdim@bawue.de) by smtp.bawue.net (Postfix) with ESMTPSA id F02232013D for ; Sat, 23 May 2020 14:33:12 +0200 (CEST) Date: Sat, 23 May 2020 14:33:11 +0200 From: Hans Ulrich Niedermann To: grub-devel@gnu.org Subject: Re: Multiboot2 on aarch64: Alignment of ELF Headers Message-ID: <20200523143311.59a4a174@n-dimensional.de> In-Reply-To: <137012c26d6e5be3fd7d95a2ebaa89167f3879a2.camel@monkeyircd.org> References: <20200523124316.68a51221@n-dimensional.de> <137012c26d6e5be3fd7d95a2ebaa89167f3879a2.camel@monkeyircd.org> X-Mailer: Claws Mail 3.17.5 (GTK+ 2.24.32; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Virus-Scanner: SAV Dynamic Interface 2.6.0, Engine: 3.77.1, SAV: 5.75 (90A0ABD) on relay01.mx.bawue.net using milter-sssp 0.1.0 X-Virus-Scan: Found to be clean. Received-SPF: pass client-ip=193.7.176.67; envelope-from=hun@n-dimensional.de; helo=smtp.bawue.net X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/23 06:17:28 X-ACL-Warn: Detected OS = Linux 3.11 and newer [fuzzy] X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 23 May 2020 12:33:20 -0000 On Sat, 23 May 2020 12:21:27 +0100 Chris Plant via Grub-devel wrote: > On Sat, 2020-05-23 at 12:43 +0200, Hans Ulrich Niedermann wrote: > > On Fri, 22 May 2020 17:23:35 +0100 > > Chris Plant via Grub-devel wrote: > > > > > I'm continuing to work on Multiboot2 support on aarch64, and I'm > > > looking at the alignment of the ELF headers which are passed > > > through > > > MB2. > > > > At the risk of me sounding stupid... > > > > Having read the MB2 specs quite thoroughly in the past few months, I > > still have no idea what "ELF headers" being "passed through MB2" > > could > > be about. The MB2 spec defines a MB2 header consisting of a four MB2 > > header magic fields and a set of MB2 header tags. > > > > The only thing ELF related I could find there is the MB2 header > > address > > tag which duplicates some information from ELF (if OS image is in > > ELF format) or contains address information (if OS image is in > > non-ELF format). Is that what you are talking about? > > Yes, this is what I'm talking about. I'm using the MB2 tag (type 9) > to see where the ELF section headers are. Ah. So the type 9 you are referring to is the "ELF-Symbols" boot information tag (i.e. information the bootloader communicates to the OS image), not an MB2 header tag (information the OS image communicates to the bootloader). I am catching up with you, finally. > Apologies, I've not been clear enough and rambled too much. The issue > I see is nothing to do with grub's MB2 implementation, but instead in > the way grub is loading the ELF section headers. > > The ELF section headers appear to be loaded on a 4 byte alignment not > an 8 byte alignment. You can read the 4 byte members of the ELF > header structure fine, but not the 8 byte members as they are aligned > to 4 bytes. > > So, my question is, should grub load the ELF headers to an 8 byte > alignment, or should the OS be prepared for them to be aligned to 4 > byte? The 64bit part of the ELF spec appears to specifically made such that 64bit values are aligned to 64bit boundaries (I have taken a look at https://en.wikipedia.org/wiki/Executable_and_Linkable_Format for an overview). Therefore, loading an ELF64 image with its many 64bit values to an address not aligned to 8 byte boundaries sounds to me like a probable oversight going back to ELF32 days and thus a bug for ELF64, unless someone has a very good argument to the contrary. Uli