Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is dynamic binary translation more practical than static binary translation?

When it comes to Binary Translation (Recompilation), I have always heard that dynamic binary translation is often a much better alternative to static binary translation, but I can't ever seem to grasp why behind this. Why is it always considered that static binary translation is impossible to implement in emulation? Why is dynamic binary translation always considered more practical?

Often people compare this to the relationship between JIT (Just-In-Time) and static compilation, but this comparison would often confuse me, as both have more than practical implementations.

like image 708
jab Avatar asked May 23 '13 21:05

jab


1 Answers

This comes up when having to translate machine code from one architecture to another. Doing it statically requires being able to correctly identify the parts of the program that represent code and not get confused by bits in the binary image that are actually data. Many compilers do not make this easy, something that anybody that's every tried to decompile an executable knows well.

A simple example is a jump table that's generated from a switch statement in C, compiled into the .text segment along with the executable code. This table contains addresses, not code. Knowing to interpret these bytes as addresses requires knowing a lot about the code generator built into the compiler. Not impossible, but of course it won't work well on the code generated by another compiler. Or even a different version of the same compiler.

Not an issue with dynamic translation, you know that a chunk of bytes is code because the machine is trying to execute it.

A different consideration applies to a jitter, such a translator will never have a problem identifying code since the intermediate code was designed to make it easy. Dynamic translation is desirable in that case because it can spread the overhead of the translation over time, thus reducing pauses in the program execution. And completely avoid doing work on code that never executes.

like image 143
Hans Passant Avatar answered Sep 23 '22 16:09

Hans Passant