|
A lot of emulators essentially do this on the fly, but it's borderline impossible to get something that works in 100% of situations, and doing it on a compiled program might need a lot of metadata to be possible at all. The biggest problem is that instructions are variable-sized, a given sequence of bytes could represent multiple valid instruction sequences depending on where in the sequence you start execution, and jumps are to arbitrary locations in memory. Together, these create a ton of problems for figuring out what to do in cases like jump tables where the program might be expected to compute a jump offset from the current instruction pointer. There are ways around that, like generating address translation tables, but they're much slower and consume much more memory than if you had compiled for that architecture in the first place, and it only works if you have enough information to determine where each instruction starts and are much more complicated if the program ever does nasty things like jumping into the middle of an instruction.
|
# ¿ Aug 6, 2015 16:17 |
|
|
# ¿ May 15, 2024 12:02 |
|
feedmegin posted:Only on x86! Barring stuff like Thumb, most RISC architectures use 32-bit-wide instructions that are 4-byte aligned. Also, how difficult any of this is also very dependent on the functionality needed by the original program. Jumping into the middle of an instruction or even just rewriting code at runtime is the kind of thing that seriously increases the complexity of translating the code while not usually being required. Signals and memory behavior are other places that may require serious performance sacrifices to emulate accurately. A lot of programs may require emulating extremely quirky behavior to work properly.
|
# ¿ Aug 6, 2015 19:19 |