Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1kKbsH-0007X6-Ms for mharc-grub-devel@gnu.org; Tue, 22 Sep 2020 02:34:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54266) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKbsF-0007Wx-4s for grub-devel@gnu.org; Tue, 22 Sep 2020 02:33:59 -0400 Received: from 15.mo3.mail-out.ovh.net ([87.98.150.177]:53995) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKbsB-0001GJ-0h for grub-devel@gnu.org; Tue, 22 Sep 2020 02:33:58 -0400 Received: from player770.ha.ovh.net (unknown [10.110.115.231]) by mo3.mail-out.ovh.net (Postfix) with ESMTP id 9C2B6263144 for ; Tue, 22 Sep 2020 08:33:44 +0200 (CEST) Received: from 3mdeb.com (188.147.98.2.nat.umts.dynamic.t-mobile.pl [188.147.98.2]) (Authenticated sender: krystian.hebel@3mdeb.com) by player770.ha.ovh.net (Postfix) with ESMTPSA id CF3131677460E for ; Tue, 22 Sep 2020 06:33:43 +0000 (UTC) Authentication-Results: garm.ovh; auth=pass (GARM-95G001e3ef5325-e2f6-4886-b9d9-088c315fb57f, 52E408BE4A6CFA6D322CB8E5A1ABFAEA917EEA59) smtp.auth=krystian.hebel@3mdeb.com Subject: Re: Multiboot2 on aarch64: Alignment of ELF Headers To: grub-devel@gnu.org References: <20200523124316.68a51221@n-dimensional.de> <137012c26d6e5be3fd7d95a2ebaa89167f3879a2.camel@monkeyircd.org> <20200523143311.59a4a174@n-dimensional.de> From: Krystian Hebel Message-ID: <1631d370-127e-35b9-69ba-c84bc1bd05b8@3mdeb.com> Date: Tue, 22 Sep 2020 08:33:42 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-Ovh-Tracer-Id: 11153164480819878797 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 0 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedujedrudefgdduudduucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecuhedttdenucenucfjughrpefuvfhfhffkffgfgggjtgfgsehtjeertddtfeejnecuhfhrohhmpefmrhihshhtihgrnhcujfgvsggvlhcuoehkrhihshhtihgrnhdrhhgvsggvlhesfehmuggvsgdrtghomheqnecuggftrfgrthhtvghrnhephffftedvkeevtdelteffvedufefffefhjeekhfehueekgfejjeekjeejudejtdehnecuffhomhgrihhnpeifihhkihhpvgguihgrrdhorhhgpdhgnhhurdhorhhgpdefmhguvggsrdgtohhmnecukfhppedtrddtrddtrddtpddukeekrddugeejrdelkedrvdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhhouggvpehsmhhtphdqohhuthdphhgvlhhopehplhgrhigvrhejjedtrdhhrgdrohhvhhdrnhgvthdpihhnvghtpedtrddtrddtrddtpdhmrghilhhfrhhomhepkhhrhihsthhirghnrdhhvggsvghlseefmhguvggsrdgtohhmpdhrtghpthhtohepghhruhgsqdguvghvvghlsehgnhhurdhorhhg Received-SPF: pass client-ip=87.98.150.177; envelope-from=krystian.hebel@3mdeb.com; helo=15.mo3.mail-out.ovh.net X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/22 02:33:44 X-ACL-Warn: Detected OS = Linux 3.11 and newer X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, NICE_REPLY_A=-0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no 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: Tue, 22 Sep 2020 06:33:59 -0000 On 21.09.2020 21:14, Chris Plant wrote: > On Sat, 2020-05-23 at 14:33 +0200, Hans Ulrich Niedermann wrote: >> 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. > On this basis, is the logical change to fix the definition of the "ELF- > Symbols" boot information tag, which is currently: > > struct multiboot_tag_elf_sections > { > multiboot_uint32_t type; > multiboot_uint32_t size; > multiboot_uint32_t num; > multiboot_uint32_t entsize; > multiboot_uint32_t shndx; > char sections[0]; > }; > > grub aligns this to an 8 byte boundary, but then the odd number of > uint32_t mean that sections is on a 4 byte boundary and is designed > within it's ELF defintion to be on 8 byte boundary. > > So I would propose adding a 4 byte pad between shndx and sections, so > that sections on an 8 byte boundary. This might break things until > they're recompiled but won't require any changes to code elsewhere and > I can't see how else to fix it without a new information defintion. This WILL break things until they are recompiled in every MB2 kernel, in addition to grub, every other MB2-capable bootloader and documentation. Until then, the kernel would have to somewhat guess whether it was given the old (not aligned) tag or the new one. While it may be possible as long as the padding is filled with a value that cannot appear in the first bytes of sections, the users would have to add the discovery code into kernels. MB2 is one of the most commonly used (if not the most common) boot protocols for hobby OSes. IMHO the only way out of it would be to create a new tag type and leave the old one as it is right now. This won't break current implementations, though it will pass redundant information. After some transition period we may drop the old format. > I can include this in my patch (first one, taking time and will be > terrible) to enable multiboot2 on ARM64 if this is the approach > required/desired? > > Chris > >> Uli >> >> _______________________________________________ >> Grub-devel mailing list >> Grub-devel@gnu.org >> https://lists.gnu.org/mailman/listinfo/grub-devel > > _______________________________________________ > Grub-devel mailing list > Grub-devel@gnu.org > https://lists.gnu.org/mailman/listinfo/grub-devel -- Krystian Hebel Firmware Engineer https://3mdeb.com | @3mdeb_com