grub-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Multiboot2 on aarch64: Alignment of ELF Headers


From: Chris Plant
Subject: Re: Multiboot2 on aarch64: Alignment of ELF Headers
Date: Sat, 23 May 2020 12:21:27 +0100
User-agent: Evolution 3.30.5-1.1

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 <address@hidden> 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.

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 alignment of the MB2 header's isn't the problem, the problem is
> > in
> > the ELF headers which are linked through.  Some of the 8 byte wide
> > fields (specifically addr and size) in the ELF headers are not
> > aligned
> > on 8 byte boundaries, and instead can aligned on 4-byte boundaries.
> > 
> > My question is, is it preferable to state that it is possible that
> > the
> > headers may be aligned on 4 byte boundaries (and manage that
> > through
> > reading two 4-byte chunks), or to change grub code to ensure that
> > the
> > ELF headers are aligned on 8 byte boundaries and state that 8 byte
> > alignment is always the case?
> 
> As it is, the largest values in the MB2 header defined in the OS
> image
> are u32, there are no u64 values. Sorry if I am asking stupid
> questions,
> but where would u64 values come into play here in the MB2 spec? Are
> you
> redefining some MB2 header tags with u64 values instead of u32
> values?
> 
> > I think logically that it should be 8 byte aligned so that's my
> > preference, but I thought I'd ask.
> 
> If you happen to be speaking about MB2 Header Tags when you say
> "linked
> through ELF headers" and you have been modeling your boot code off
> the
> example boot.S and boot_mips.S and run into alignment issues there,
> be
> advised that the current example boot code does violate the MB2 spec:
> 
> The MB2 spec and the grub2 code both agree on the MB2 header tags
> being
> aligned to 8 byte boundaries, while the example code (both for ia32
> and
> for mips) does not align the MB2 header tags at all.

> 
> Uli
> 
> _______________________________________________
> Grub-devel mailing list
> address@hidden
> https://lists.gnu.org/mailman/listinfo/grub-devel




reply via email to

[Prev in Thread] Current Thread [Next in Thread]