All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hans Ulrich Niedermann <hun@n-dimensional.de>
To: grub-devel@gnu.org
Subject: Re: Multiboot2 on aarch64: Alignment of ELF Headers
Date: Sat, 23 May 2020 14:33:11 +0200	[thread overview]
Message-ID: <20200523143311.59a4a174@n-dimensional.de> (raw)
In-Reply-To: <137012c26d6e5be3fd7d95a2ebaa89167f3879a2.camel@monkeyircd.org>

On Sat, 23 May 2020 12:21:27 +0100
Chris Plant via Grub-devel <grub-devel@gnu.org> 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 <grub-devel@gnu.org> 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


  reply	other threads:[~2020-05-23 12:33 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-22 16:23 Multiboot2 on aarch64: Alignment of ELF Headers Chris Plant
2020-05-23 10:43 ` Hans Ulrich Niedermann
2020-05-23 11:21   ` Chris Plant
2020-05-23 12:33     ` Hans Ulrich Niedermann [this message]
2020-09-21 19:14       ` Chris Plant
2020-09-22  6:33         ` Krystian Hebel
2020-09-22  6:53           ` Chris Plant
2020-09-26 12:54             ` Chris Plant

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200523143311.59a4a174@n-dimensional.de \
    --to=hun@n-dimensional.de \
    --cc=grub-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.