From: Kevin Wolf <kwolf@redhat.com>
To: Anatol Pomozov <anatol.pomozov@gmail.com>
Cc: Richard Henderson <rth@twiddle.net>,
Eduardo Habkost <ehabkost@redhat.com>,
qemu-devel@nongnu.org, Paolo Bonzini <pbonzini@redhat.com>,
Alexander Graf <agraf@suse.de>
Subject: Re: [Qemu-devel] How to make ELF headers/symbol sections available for multiboot?
Date: Thu, 3 Aug 2017 10:39:56 +0200 [thread overview]
Message-ID: <20170803083956.GD4456@dhcp-200-186.str.redhat.com> (raw)
In-Reply-To: <CAOMFOmVN74ghnqWGyfxHB_LqcSLC8XzRkrk88VXaPh4JRvYRNQ@mail.gmail.com>
Am 03.08.2017 um 00:00 hat Anatol Pomozov geschrieben:
> Hello Richard
>
> Thank you for this useful information. I still learning about ELF and
> a lot of things are still unclear for me.
>
> On Mon, Jul 31, 2017 at 11:20 AM, Richard Henderson <rth@twiddle.net> wrote:
> > On 07/31/2017 10:21 AM, Anatol Pomozov wrote:
> >> ELF sections info is needed for an OS to map address space properly.
> >
> > No, ELF *program header* info is needed for an OS to map the address space
> > properly. For example:
> >
> > $ readelf -hl vmlinux-4.9.0-3-5kc-malta
>
> Thanks for this information about program headers. I reread elf_ops.h
> and now I see that QEMU loads all PT_LOAD segments. I wonder why GRUB
> bootloader loads also sections that are not in this segment (e.g. GRUB
> loads content of .shstrtab into target's memory despite my elf does
> not keep it in PT_LOAD segment).
Remember that what we're talking about isn't primarily an ELF loader,
but a Multiboot loader. Multiboot can work without ELF (e.g. with flat
binaries) if bit 16 in the Multiboot header flags is set and the
additional header fields are correctly provided. However, if you are
loading an ELF binary, then Multiboot specifies that the bootloader
makes use of the ELF headers and you don't have to set bit 16 in the
header.
If ELF says that some things have to be loaded (and bit 16 is clear),
then the bootloader will load them. If Multiboot says that additional
things can or have to be loaded, it will load those, too. The section
headers are only one example of additional data that Multiboot provides.
It also loads additional modules, provides the e820 memory map, etc.,
none of which are described by ELF.
> What ELF specification says about it? Does it tell a loader to load
> only PT_LOAD segments? In this case bootloaders should follow it as
> well and current QEMU behavior is correct.
The current behaviour of QEMU is correct because it doesn't set bit 5 in
the flags field of the Multiboot info struct, i.e. it doesn't advertise
that the section headers are available, so it doesn't have to provide
it.
It is also not feature complete, because a full Multiboot implementation
would implement this and advertise bit 5. Adding the feature would be
useful because there are guest kernels that can make use of it.
> But multiboot expects section headers info and .shstrtab section to be
> loaded to the target memory. I believe I need to modify my linker
> script and add this information into the loadable segment.
No. First of all, you don't even need this information to find the start
and end of the kernel code. Second, if a Multiboot loader loads this, it
doesn't have to be in a loadable segment. This is more like debug
information, not like an inherent part of the program.
> Here is my current linker script:
>
> ======================
> ENTRY(start)
>
> SECTIONS {
> . = 1M;
>
> .text : {
> KEEP(*(.data.multiboot))
> *(.text .text*)
> }
>
> .rodata : {
> *(.rodata .rodata*)
> }
>
> .data : {
> *(.data .data.*)
> }
>
> .bss : {
> __bss_start = .;
> *(.bss .bss*)
> . = ALIGN(8);
> __bss_end = .;
> }
> }
> =======================
>
> With my linker script only .text .rodata .data and .bss are included
> into the loadable segment.
>
>
> So my questions: how to tell the linker to include "section headers"
> and ".shstrtab" section into loadable segment? Once it is done I can
> try to modify QEMU to pass its addresses to the target.
Requiring section headers to be contained in a loadable segment wouldn't
be a correct implementation of the Multiboot feature.
Kevin
next prev parent reply other threads:[~2017-08-03 8:40 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-28 21:28 [Qemu-devel] How to make ELF headers/symbol sections available for multiboot? Anatol Pomozov
2017-07-30 21:42 ` Eduardo Habkost
2017-07-31 6:25 ` Alexander Graf
2017-07-31 11:27 ` Kevin Wolf
2017-07-31 17:21 ` Anatol Pomozov
2017-07-31 18:20 ` Richard Henderson
2017-08-02 22:00 ` Anatol Pomozov
2017-08-02 22:45 ` Richard Henderson
2017-08-03 8:39 ` Kevin Wolf [this message]
2017-08-04 4:53 ` Anatol Pomozov
2017-08-08 15:04 ` Kevin Wolf
2017-08-17 20:54 ` Anatol Pomozov
2017-09-11 18:48 ` Anatol Pomozov
2017-09-11 18:49 ` Anatol Pomozov
2017-08-01 14:06 ` Kevin Wolf
2017-07-31 8:50 ` Peter Maydell
2017-07-31 13:04 ` Richard Henderson
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=20170803083956.GD4456@dhcp-200-186.str.redhat.com \
--to=kwolf@redhat.com \
--cc=agraf@suse.de \
--cc=anatol.pomozov@gmail.com \
--cc=ehabkost@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=rth@twiddle.net \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).