* [Qemu-devel] [PATCH] Make the ELF loader aware of backwards compatibility
@ 2009-02-28 15:03 Alexander Graf
2009-02-28 15:30 ` Blue Swirl
0 siblings, 1 reply; 7+ messages in thread
From: Alexander Graf @ 2009-02-28 15:03 UTC (permalink / raw)
To: qemu-devel; +Cc: Alexander Graf
Most 64 bit architectures I'm aware of support running 32 bit code
of the same architecture as well.
So x86_64 can run i386 code easily and ppc64 can run ppc code.
Unfortunately, the current checks are pretty strict. So you can only
load e.g. an x86_64 elf binary on qemu-system-x86_64, but no i386 one.
This can get really annoying. I first encountered this issue with
my multiboot patch, where qemu-system-x86_64 was unable to load an
i386 elf binary because the elf loader rejected it.
The same thing happened again on PPC64 now. The firmware we're loading
is a PPC32 elf binary, as it's shared with PPC32. But the platform is
PPC64.
Right now there is a hack for this in the ppc cpu.h definition, that
simply sets the type to PPC32 in system emulation mode. While that
works fine for the firmware, it's no good if you also want to load a
PPC64 kernel with -kernel.
So in order to solve this mess, I figured the easiest way is to make
the elf loader aware of platforms that are backwards compatible. For
now I was only sure that x86_64 does i386 and ppc64 does ppc32, but
maybe there are other combinations too.
This patch is a prerequisite for having a working -kernel option on
PPC64.
Signed-off-by: Alexander Graf <alex@csgraf.de>
---
elf_ops.h | 17 +++++++++++++++--
target-ppc/cpu.h | 2 +-
2 files changed, 16 insertions(+), 3 deletions(-)
diff --git a/elf_ops.h b/elf_ops.h
index feea12f..485442a 100644
--- a/elf_ops.h
+++ b/elf_ops.h
@@ -194,8 +194,21 @@ static int glue(load_elf, SZ)(int fd, int64_t address_offset,
glue(bswap_ehdr, SZ)(&ehdr);
}
- if (ELF_MACHINE != ehdr.e_machine)
- goto fail;
+ switch (ELF_MACHINE) {
+ case EM_PPC64:
+ if (EM_PPC64 != ehdr.e_machine)
+ if (EM_PPC != ehdr.e_machine)
+ goto fail;
+ break;
+ case EM_X86_64:
+ if (EM_X86_64 != ehdr.e_machine)
+ if (EM_386 != ehdr.e_machine)
+ goto fail;
+ break;
+ default:
+ if (ELF_MACHINE != ehdr.e_machine)
+ goto fail;
+ }
if (pentry)
*pentry = (uint64_t)(elf_sword)ehdr.e_entry;
diff --git a/target-ppc/cpu.h b/target-ppc/cpu.h
index 80ee76c..4fc06c3 100644
--- a/target-ppc/cpu.h
+++ b/target-ppc/cpu.h
@@ -67,7 +67,7 @@
#define TARGET_HAS_ICE 1
/* Load a 32 bit BIOS also on 64 bit machines */
-#if defined (TARGET_PPC64) && defined(CONFIG_USER_ONLY)
+#if defined (TARGET_PPC64)
#define ELF_MACHINE EM_PPC64
#else
#define ELF_MACHINE EM_PPC
--
1.5.3.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [PATCH] Make the ELF loader aware of backwards compatibility
2009-02-28 15:03 [Qemu-devel] [PATCH] Make the ELF loader aware of backwards compatibility Alexander Graf
@ 2009-02-28 15:30 ` Blue Swirl
2009-02-28 15:40 ` Andreas Färber
2009-03-11 23:32 ` Alexander Graf
0 siblings, 2 replies; 7+ messages in thread
From: Blue Swirl @ 2009-02-28 15:30 UTC (permalink / raw)
To: qemu-devel; +Cc: Alexander Graf
On 2/28/09, Alexander Graf <agraf@suse.de> wrote:
> Most 64 bit architectures I'm aware of support running 32 bit code
> of the same architecture as well.
For Sparc64 this is only true for userland, kernel level code is not
compatible at all. Sparc64 kernel can run Sparc64 and Sparc32
binaries, but a Sparc32 kernel will crash on Sparc64.
> /* Load a 32 bit BIOS also on 64 bit machines */
> -#if defined (TARGET_PPC64) && defined(CONFIG_USER_ONLY)
> +#if defined (TARGET_PPC64)
> #define ELF_MACHINE EM_PPC64
> #else
> #define ELF_MACHINE EM_PPC
The comment should be removed with the hack.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [PATCH] Make the ELF loader aware of backwards compatibility
2009-02-28 15:30 ` Blue Swirl
@ 2009-02-28 15:40 ` Andreas Färber
2009-02-28 15:58 ` Blue Swirl
2009-03-11 23:32 ` Alexander Graf
1 sibling, 1 reply; 7+ messages in thread
From: Andreas Färber @ 2009-02-28 15:40 UTC (permalink / raw)
To: qemu-devel; +Cc: Alexander Graf
Am 28.02.2009 um 16:30 schrieb Blue Swirl:
> On 2/28/09, Alexander Graf <agraf@suse.de> wrote:
>> Most 64 bit architectures I'm aware of support running 32 bit code
>> of the same architecture as well.
>
> For Sparc64 this is only true for userland, kernel level code is not
> compatible at all. Sparc64 kernel can run Sparc64 and Sparc32
> binaries, but a Sparc32 kernel will crash on Sparc64.
Same for ppc. To install Linux, you need to type "install64" at the
prompt, the default "install" crashes on a G5.
Andreas
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [PATCH] Make the ELF loader aware of backwards compatibility
2009-02-28 15:40 ` Andreas Färber
@ 2009-02-28 15:58 ` Blue Swirl
0 siblings, 0 replies; 7+ messages in thread
From: Blue Swirl @ 2009-02-28 15:58 UTC (permalink / raw)
To: qemu-devel; +Cc: Alexander Graf
On 2/28/09, Andreas Färber <andreas.faerber@web.de> wrote:
>
> Am 28.02.2009 um 16:30 schrieb Blue Swirl:
>
>
> > On 2/28/09, Alexander Graf <agraf@suse.de> wrote:
> >
> > > Most 64 bit architectures I'm aware of support running 32 bit code
> > > of the same architecture as well.
> > >
> >
> > For Sparc64 this is only true for userland, kernel level code is not
> > compatible at all. Sparc64 kernel can run Sparc64 and Sparc32
> > binaries, but a Sparc32 kernel will crash on Sparc64.
> >
>
> Same for ppc. To install Linux, you need to type "install64" at the prompt,
> the default "install" crashes on a G5.
Not exactly. I guess it's possible to construct a dual PPC32/PPC64
kernel for 32 bit mode because even though the MMUs are not
compatible, instruction sets are. But Sparc32 supervisor instructions
do wildly different things on a Sparc64.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [PATCH] Make the ELF loader aware of backwards compatibility
2009-02-28 15:30 ` Blue Swirl
2009-02-28 15:40 ` Andreas Färber
@ 2009-03-11 23:32 ` Alexander Graf
2009-03-13 17:32 ` Blue Swirl
2009-03-13 21:17 ` Blue Swirl
1 sibling, 2 replies; 7+ messages in thread
From: Alexander Graf @ 2009-03-11 23:32 UTC (permalink / raw)
To: qemu-devel; +Cc: Blue Swirl
On 28.02.2009, at 16:30, Blue Swirl wrote:
> On 2/28/09, Alexander Graf <agraf@suse.de> wrote:
>> Most 64 bit architectures I'm aware of support running 32 bit code
>> of the same architecture as well.
>
> For Sparc64 this is only true for userland, kernel level code is not
> compatible at all. Sparc64 kernel can run Sparc64 and Sparc32
> binaries, but a Sparc32 kernel will crash on Sparc64.
>
>> /* Load a 32 bit BIOS also on 64 bit machines */
>> -#if defined (TARGET_PPC64) && defined(CONFIG_USER_ONLY)
>> +#if defined (TARGET_PPC64)
>> #define ELF_MACHINE EM_PPC64
>> #else
>> #define ELF_MACHINE EM_PPC
>
> The comment should be removed with the hack.
I agree.
Any functional issues with this patch? -kernel for ppc64 still doesn't
work with current SVN :-).
Alex
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [PATCH] Make the ELF loader aware of backwards compatibility
2009-03-11 23:32 ` Alexander Graf
@ 2009-03-13 17:32 ` Blue Swirl
2009-03-13 21:17 ` Blue Swirl
1 sibling, 0 replies; 7+ messages in thread
From: Blue Swirl @ 2009-03-13 17:32 UTC (permalink / raw)
To: Alexander Graf; +Cc: qemu-devel
On 3/12/09, Alexander Graf <alex@csgraf.de> wrote:
>
> On 28.02.2009, at 16:30, Blue Swirl wrote:
>
>
> > On 2/28/09, Alexander Graf <agraf@suse.de> wrote:
> >
> > > Most 64 bit architectures I'm aware of support running 32 bit code
> > > of the same architecture as well.
> > >
> >
> > For Sparc64 this is only true for userland, kernel level code is not
> > compatible at all. Sparc64 kernel can run Sparc64 and Sparc32
> > binaries, but a Sparc32 kernel will crash on Sparc64.
> >
> >
> > > /* Load a 32 bit BIOS also on 64 bit machines */
> > > -#if defined (TARGET_PPC64) && defined(CONFIG_USER_ONLY)
> > > +#if defined (TARGET_PPC64)
> > > #define ELF_MACHINE EM_PPC64
> > > #else
> > > #define ELF_MACHINE EM_PPC
> > >
> >
> > The comment should be removed with the hack.
> >
>
> I agree.
>
> Any functional issues with this patch? -kernel for ppc64 still doesn't work
> with current SVN :-).
The elf_check_arch macro that linux-user uses could be cleaner
approach. But this is OK as the first step, so I'll commit this
shortly.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [PATCH] Make the ELF loader aware of backwards compatibility
2009-03-11 23:32 ` Alexander Graf
2009-03-13 17:32 ` Blue Swirl
@ 2009-03-13 21:17 ` Blue Swirl
1 sibling, 0 replies; 7+ messages in thread
From: Blue Swirl @ 2009-03-13 21:17 UTC (permalink / raw)
To: Alexander Graf; +Cc: qemu-devel
On 3/12/09, Alexander Graf <alex@csgraf.de> wrote:
>
> On 28.02.2009, at 16:30, Blue Swirl wrote:
>
>
> > On 2/28/09, Alexander Graf <agraf@suse.de> wrote:
> >
> > > Most 64 bit architectures I'm aware of support running 32 bit code
> > > of the same architecture as well.
> > >
> >
> > For Sparc64 this is only true for userland, kernel level code is not
> > compatible at all. Sparc64 kernel can run Sparc64 and Sparc32
> > binaries, but a Sparc32 kernel will crash on Sparc64.
> >
> >
> > > /* Load a 32 bit BIOS also on 64 bit machines */
> > > -#if defined (TARGET_PPC64) && defined(CONFIG_USER_ONLY)
> > > +#if defined (TARGET_PPC64)
> > > #define ELF_MACHINE EM_PPC64
> > > #else
> > > #define ELF_MACHINE EM_PPC
> > >
> >
> > The comment should be removed with the hack.
> >
>
> I agree.
>
> Any functional issues with this patch? -kernel for ppc64 still doesn't work
> with current SVN :-).
Thanks, applied.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2009-03-13 21:17 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-02-28 15:03 [Qemu-devel] [PATCH] Make the ELF loader aware of backwards compatibility Alexander Graf
2009-02-28 15:30 ` Blue Swirl
2009-02-28 15:40 ` Andreas Färber
2009-02-28 15:58 ` Blue Swirl
2009-03-11 23:32 ` Alexander Graf
2009-03-13 17:32 ` Blue Swirl
2009-03-13 21:17 ` Blue Swirl
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).