Binary translation (of code)
Message: 3
Date: Sun, 08 May 2011 21:41:15 +0200
From: Llu?s <[email protected]>
To: [email protected]
Subject: Re: [Qemu-devel] Binary translation (of code)
Message-ID: <[email protected]>
Content-Type: text/plain; charset=utf-8
Quoted 3 lines · Tarmo Pikaro
Hi !
Quoted 2 lines
Quoted 2 lines
I think self-modifying?code is kinda rare case - it's made typically for protection againt?hackers , and?typically on pc side. Nintendo?roms
probably
Quoted 6 lines
Quoted 5 lines
Quoted 2 lines
don't use this kind of
protection.It doesn't have to be protection, for example GCC generates trampolines to stack when using nested functions.
Quoted 7 lines
Ok, so apparently we will have some challenges on the way.
I guess some sort of mutation - qemu + recompiler could be done as well...
It would be much easier to ship an executable containing both the guest application and qemu, so that executing it starts qemu with a pre-defined configuration and runs the guest binary.
- Binary recompilation would allow faster execution than emulated code
- qemu constantly changes (based on amount of patches provided in this mail list) - in order to keep image+qemu working - simplest way is to convert into
executable. Btw - qemu could be used as a bootstrap to image as well. :-)
- And finally modular "emulation" - it would be possible to recompile individual .dll to another os.
Side effects would be:
- More difficult to debug - since mapping to original binary image should be somehow
maintained - if register dump helps anyhow the developer.
--
Have a nice day!
Tarmo.
Quoted 5 lines · Tarmo Pikaro
Quoted 3 lines
It would be much easier to ship an executable containing both the guest application and qemu, so that executing it starts qemu with a pre-defined configuration and runs the guest binary.
- Binary recompilation would allow faster execution than emulated code
Digital Equipment Corp (DEC) did a lot of work with static binary recompilation in the early 1990's, converting VAX VMS applications to Alpha VMS. It's quite possible to do if you spend enough time on it, and have a well defined application environment.
That said, Hewlett Packard (HP) has done a very similar amount of work with dynamic binary recompilation of PA-RISC HP/UX to IA-64 HP/UX, and achieved similar results to what DEC achieved.
There has been a *lot* of papers about dynamic recompilation over the last decade or two. I believe that the general consensus is that -- with the addition of dynamic profiling -- dynamic recompilation allows faster execution than static recompilation.
A lot of this is stuff that QEMU doesn't do. But the gist is, you add profiling information to basic blocks as you translate them. This first compilation pass is very quick and dirty, producing only moderately poor translated code. As the program runs, a profile is collected that allows the emulation environment to identify portions of the program that should be compiled again, with much higher optimization. The thing that allows this dynamic compilation to produce code that runs faster than static compilation is that the VM can make simplifying assumptions about how a portion of the program acts (either discovered from the profile, or a true guess) and check those assumptions before the translated code is executed. If the assumptions turn out to be invalid, then the VM can fall back to the original quick compilation, or re-compile the portion of the program without the assumptions.
If you're truly interested, a fair portion of these sorts of papers are written in the context of Java Virtual Machines. But the techniques apply equally well to any dynamic compilation process.
r~
P.S: I seem to recall reading that HP had done some testing of their PA-RISC dynamic recompiler, producing PA-RISC output too. The recompiled programs could then run on the same hardware as the original program. The recompiled programs ran faster than the originals, due to the techniques described.
Quoted 5 lines · Tarmo Pikaro
Quoted 3 lines
It would be much easier to ship an executable containing both the guest application and qemu, so that executing it starts qemu with a pre-defined configuration and runs the guest binary.
- Binary recompilation would allow faster execution than emulated code
QEMU does precisely that, using a JIT. You wouldn't obtain much more performance by generating a pre-translated binary instead of using QEMU's JIT. And that's without taking into account the difficulties associated with the static binary analysis that would be required (as others have already pointed to you to in previous mails).
Quoted 5 lines
- qemu constantly changes (based on amount of patches provided in this mail list) - in order to keep image+qemu working - simplest way is to convert into
executable. Btw - qemu could be used as a bootstrap to image as well. :-)
Maybe you didn't understand what I was saying. Think of it as a self-extracting executable that contains both a specific qemu binary, as well as the guest binary you want to execute. When you execute that bundle, it transparently extracts both components (qemu + the guest application) and starts qemu to execute that application.
Still, this is a poor approach from the software maintenance point of view, and falls into the kind of strategies that windows application developers use (bundle private copies of each library the application is going to use).
Quoted 2 lines
- And finally modular "emulation" - it would be possible to recompile individual .dll to another os.
I suppose you meant another architecture, as recompiling to another OS makes no sense on the general case (can have a completely different set of syscalls).
Still, I don't see the point of translating a single library instead of the whole application (specially when you have access to a library compiled for you target architecture, or even better access to the source code to compile that library to whatever target you desire).
Quoted 5 lines
Side effects would be:
- More difficult to debug - since mapping to original binary image should be somehow
maintained - if register dump helps anyhow the developer.
As others have told you, qemu already has an interface to allow gdb to debug the guest application.
Lluis
Signature · 4 lines
"And it's much the same thing with knowledge, for whenever you learn something new, the whole world becomes that much richer." -- The Princess of Pure Reason, as told by Norton Juster in The Phantom Tollbooth