Binary translation
In computing, binary translation is a form of binary recompilation where sequences of instructions are translated from a source instruction set to the target instruction set. In some cases such as instruction set simulation, the target instruction set may be the same as the source instruction set, providing testing and debugging features such as instruction trace, conditional breakpoints and hot spot detection.
The two main types are static and dynamic binary translation. Translation can be done in hardware (for example, by circuits in a CPU) or in software (e.g. run-time engines, static recompiler, emulators).
Motivation
Binary translation is motivated by a lack of a binary for a target platform, the lack of source code to compile for the target platform, or otherwise difficulty in compiling the source for the target platform.
Statically-recompiled binaries run potentially faster than their respective emulated binaries, as the emulation overhead is removed. This is similar to the difference in performance between interpreted and compiled programs in general.
Static binary translation
A translator using static binary translation aims to convert all of the code of an executable file into code that runs on the target architecture without having to run the code first, as is done in dynamic binary translation. This is very difficult to do correctly, since not all the code can be discovered by the translator. For example, some parts of the executable may be reachable only through indirect branches, whose value is known only at run-time.
One such static binary translator uses universal superoptimizer peephole technology (developed by Sorav Bansal and Alex Aiken from Stanford University) to perform efficient translation between possibly many source and target pairs, with considerably low development costs and high performance of the target binary. In experiments of PowerPC-to-x86 translations, some binaries even outperformed native versions, but on average they ran at two-thirds of native speed.[1]
Examples for static binary translations
Honeywell provided a program called the Liberator for their Honeywell 200 series of computers; it could translate programs for the IBM 1400 series of computers into programs for the Honeywell 200 series.[2]
In 2014, an ARM architecture version of the 1998 video game StarCraft was generated by static recompilation and additional reverse engineering of the original x86 version.[3][4] The Pandora handheld community was capable of developing the required tools[5] on their own and achieving such translations successfully several times.[6][7]
For instance, a successful x86-to-x64 static recompilation was generated for the procedural terrain generator of the video game Cube World in 2014.[8]
Another example is the NES-to-x86 statically recompiled version of the videogame Super Mario Bros. which was generated under usage of LLVM in 2013.[9]
In 2004 Scott Elliott and Phillip R. Hutchinson at Nintendo developed a tool to generate "C" code from Game Boy binary that could then be compiled for a new platform and linked against a hardware library for use in airline entertainment systems.[10]
In 1995 Norman Ramsey at Bell Communications Research and Mary F. Fernandez at Department of Computer Science, Princeton University developed The New Jersey Machine-Code Toolkit that had the basic tools for static assembly translation.[11]
Dynamic binary translation
Dynamic binary translation (DBT) looks at a short sequence of code—typically on the order of a single basic block—then translates it and caches the resulting sequence. Code is only translated as it is discovered and when possible, and branch instructions are made to point to already translated and saved code (memoization).
Dynamic binary translation differs from simple emulation (eliminating the emulator's main read-decode-execute loop—a major performance bottleneck), paying for this by large overhead during translation time. This overhead is hopefully amortized as translated code sequences are executed multiple times.
More advanced dynamic translators employ dynamic recompilation where the translated code is instrumented to find out what portions are executed a large number of times, and these portions are optimized aggressively. This technique is reminiscent of a JIT compiler, and in fact such compilers (e.g. Sun's HotSpot technology) can be viewed as dynamic translators from a virtual instruction set (the bytecode) to a real one.
Examples for dynamic binary translations in software
- Apple Computer implemented a dynamic translating emulator for M68K code in their PowerPC line of Macintoshes,[12] which achieved a very high level of reliability, performance and compatibility (see Mac 68K emulator). This allowed Apple to bring the machines to market with only a partially native operating system, and end users could adopt the new, faster architecture without risking their investment in software. Partly because the emulator was so successful, many parts of the operating system remained emulated. A full transition to a PowerPC native operating system (OS) was not made until the release of Mac OS X (10.0) in 2001. (The Mac OS X "Classic" runtime environment continued to offer this emulation capability on PowerPC Macs until Mac OS X 10.5.)
- Mac OS X 10.4.4 for Intel-based Macs introduced the Rosetta dynamic translation layer to ease Apple's transition from PPC-based hardware to x86. Developed for Apple by Transitive Corporation, the Rosetta software is an implementation of Transitive's QuickTransit solution.
- QuickTransit during its product lifespan also provided SPARC→x86, x86→PowerPC and MIPS→Itanium 2 translation support.
- DEC achieved similar success with its translation tools to help users migrate from the CISC VAX architecture to the Alpha RISC architecture.[citation needed]
- HP ARIES (Automatic Re-translation and Integrated Environment Simulation) is a software[13] dynamic binary translation system that combines fast code interpretation with two phase dynamic translation to transparently and accurately execute HP 9000 HP-UX applications on HP-UX 11i for HPE Integrity Servers.[14] The ARIES fast interpreter emulates a complete set of non-privileged PA-RISC instructions with no user intervention. During interpretation, it monitors the application's execution pattern and translates only the frequently executed code into native Itanium code at runtime. ARIES implements two phase dynamic translation, a technique in which translated code in first phase collects runtime profile information which is used during second phase translation to further optimize the translated code. ARIES stores the dynamically translated code in memory buffer called code cache. Further references to translated basic blocks execute directly in the code cache and do not require additional interpretation or translation. The targets of translated code blocks are back-patched to ensure execution takes place in code cache most of the time. At the end of the emulation, ARIES discards all the translated code without modifying the original application. The ARIES emulation engine also implements Environment Emulation which emulates an HP 9000 HP-UX application's system calls, signal delivery, exception management, threads management, emulation of HP GDB for debugging, and core file creation for the application.
- DEC created the FX!32 binary translator for converting x86 applications to Alpha applications.[12]
- Sun Microsystems' Wabi software included dynamic translation from x86 to SPARC instructions.
- In January 2000, Transmeta Corporation announced a novel processor design named Crusoe.[15][16] From the FAQ[17] on their web site, The smart microprocessor consists of a hardware VLIW core as its engine and a software layer called Code Morphing software. The Code Morphing software acts as a shell […] morphing or translating x86 instructions to native Crusoe instructions. In addition, the Code Morphing software contains a dynamic compiler and code optimizer […] The result is increased performance at the least amount of power. […] [This] allows Transmeta to evolve the VLIW hardware and Code Morphing software separately without affecting the huge base of software applications.
- Intel Corporation developed and implemented an IA-32 Execution Layer - a dynamic binary translator designed to support IA-32 applications on Itanium-based systems, which was included in Microsoft Windows Server for Itanium architecture, as well as in several flavors of Linux, including Red Hat and Suse. It allowed IA-32 applications to run faster than they would using the native IA-32 mode on Itanium processors.
- Dolphin (an emulator for the GameCube/Wii) performs JIT recompilation of PowerPC code to x86 and AArch64.
Examples for dynamic binary translations in hardware
- Nvidia Tegra K1 Denver translates ARM instructions over a slow hardware decoder to its native microcode instructions and uses a software binary translator for hot code.[citation needed]
See also
- Binary optimization
- Binary recompilation
- Dynamic recompilation
- Just-in-time compilation
- Instruction set simulator
- Emulator
- Virtual machine
- Comparison of platform virtualization software
- Shadow memory
References
- ↑ Bansal, Sorav; Aiken, Alex (December 2008). "Binary Translation Using Peephole Superoptimizers". pp. 177–192. https://www.usenix.org/legacy/events/osdi08/tech/full_papers/bansal/bansal.pdf.
- ↑ Honeywell Series 200 Summary Description. Honeywell. February 1966. p. 11. http://bitsavers.org/pdf/honeywell/series200/charlie_gibbs/012_Series_200_Summary_Description.pdf. "For example, the instruction repertoire of Series 200 processors is similar enough to those of several other processing systcms, viz., the IBM 1400 series, to allow automated, one-time translation of programs written for these competitive systems to a form suitable for execution on higher-performance Series 200 systems."
- ↑ "Starcraft für ARM-Handheld kompiliert" (in de). golem.de. March 10, 2014. http://www.golem.de/news/open-pandora-starcraft-fuer-arm-handheld-kompiliert-1403-105031.html.
- ↑ notaz (March 4, 2014). "StarCraft". repo.openpandora.org. http://repo.openpandora.org/?page=detail&app=package.starcraft.
- ↑ notaz (2014-03-01). "ia32rtools/". GitHub. https://github.com/notaz/ia32rtools.
- ↑ notaz (March 4, 2014). "Starcraft". openpandora.org. http://boards.openpandora.org/topic/15820-starcraft/. "The "no source, no port" rule is not completely true, you can get something similar (but not the same) as a port through static recompilation. Similar stuff was done several times by M-HT for some DOS games. The game was also converted for Android with somewhat similar approach."
- ↑ M-HT. "Warcraft: Orcs & Humans". repo.openpandora.org. http://repo.openpandora.org/?page=detail&app=warcraft_sr.
- ↑ "Practical and Portable X86 Recompilation". 2014-04-14. http://mp2.dk/blog/blog/2014/04/14/practical-and-portable-binary-recompilation/. "but then the idea of somehow using the original x86 machine code presented itself. However, for our open server, we need to support x86-64 as well, and in that case, we absolutely need emulation or recompilation. […] Static recompilation to assembler seemed like a much better option, but to keep it portable, we would need to write backends for x86, x86-64, and possibly ARM/PowerPC."
- ↑ "Statically Recompiling NES Games into Native Executables with LLVM and Go". 2013-07-07. http://andrewkelley.me/post/jamulator.html. "This article presents original research regarding the possibility of statically disassembling and recompiling Nintendo Entertainment System games into native executables."
- ↑ Elliott, Scott & Phillip Hutchinson, "System and method for trans-compiling video games", US patent 7765539, issued 2010
- ↑ "The New Jersey Machine-Code Toolkit". USENIX Association Berkeley, CA, USA. 1995. pp. 24. https://www.usenix.org/legacy/publications/library/proceedings/neworl/full_papers/ramsey.
- ↑ 12.0 12.1 "Gary Kildall, industry pioneer, dead at 52: created first microcomputer languages, disk operating systems". Microprocessor Report (MicroDesign Resources Inc. (MDR)) 8 (10). 1994-08-01. http://tech-insider.org/personal-computers/research/1994/0801.html. Retrieved 2016-11-18. "[…] Ironically, many of the techniques Gary pioneered are being rediscovered now, ten years later. Apple and DEC are touting binary recompilation as a "new" technology for porting existing software to the PowerPC or Alpha architecture. Actually, DRI introduced an 8080-to-8086 binary recompiler in the early 1980s. […]".
- ↑ Itanium Rising: Breaking Through Moore's Second Law of Computing Power. Prentice Hall PTR. 2003. ISBN 978-0-13046415-6. https://books.google.com/books?id=1hQ7ngEACAAJ. Retrieved 2015-01-09.
- ↑ "HP ARIES Dynamic Binary Translator". HP. http://h21007.www2.hp.com/portal/site/dspp/menuitem.863c3e4cbcdc3f3515b49c108973a801/?ciid=0208713ba4f02110713ba4f02110275d6e10RCRD.
- ↑ "Transmeta Crusoe Explored". Ars Technica. http://archive.arstechnica.com/cpu/1q00/crusoe/m-crusoe-1.html.
- ↑ "Transmeta's Crusoe Microprocessor". geek.com. January 20, 2000. http://www.geek.com/procspec/features/transmeta/crusoe.htm.
- ↑ "Transmeta Crusoe Processor Frequently Asked Questions FAQ". Transmeta. 2007. http://www.transmeta.com/crusoe/faq.html.
Further reading
- "Introduction to Binary Translation". Intel. 2010. http://moodle.technion.ac.il/pluginfile.php/373059/mod_resource/content/3/IntroductionToBinaryTranslation-ver2.pdf.
- "Binary Translation Using Peephole Superoptimizers". Department of Computer Science and Engineering. Indian Institute of Technology Delhi. December 2008. http://www.cse.iitd.ernet.in/~sbansal/pubs/osdi08_html/index.html.
- "IA-32 Execution Layer: a two-phase dynamic translator designed to support IA-32 applications on Itanium-based systems". Washington, DC, USA: IEEE Computer Society. 2003. pp. 191–. ISBN 978-0-7695-2043-8. http://dl.acm.org/citation.cfm?id=956550.
- "An Emulator Writer's HOWTO for Static Binary Translation". http://www.gtoal.com/sbt/.
- "FX!32: A Profile-Directed Binary Translator". IEEE Micro 18 (2): 56–64. 1998. doi:10.1109/40.671403. ISSN 0272-1732. http://www.computer.org/csdl/mags/mi/1998/02/m2056-abs.html.
- "ISAMAP: Instruction Mapping Driven by Dynamic Translation". Computer Architecture - ISCA 2010 International Workshops. Saint-Malo, France. 2010-06-23. pp. 117–. ISBN 9783642243226. https://books.google.com/books?id=U4IKBwAAQBAJ&pg=PA117.
- "Dynamic Binary Translation from x86-32 code to x86-64 code for Virtualization". Massachusetts Institute of Technology. 2009-06-20. https://core.ac.uk/download/pdf/4417669.pdf.
Original source: https://en.wikipedia.org/wiki/Binary translation.
Read more |