I know this may sound really naive but I'm new to low level programming. I was wondering if the binaries that we build use a certain set of instructions to talk to CPU (amd64, arm64 etc), why can't we edit the binary and change the calls to make the call in the certain ISA we want?<p>I know that's possible with recompiling from the source code, for example with Go, but I was wondering why can't we do this for arbitrary binaries? Are the calls not apparent in the binary form? From what I can tell Rosetta 2 does a similar thing when you run amd64 app on M1 for the first time[1]. What prevents us to have such a tool for all architectures? For example, I'd like to run an arbitrary amd64 binary on a RISC-V core without recompiling the source code.<p>[1]: https://www.computerworld.com/article/3597949/everything-you-need-to-know-about-rosetta-2-on-apple-silicon-macs.html
It works for simple cases. Things that make it complicated are:<p>- Only executable code should be translated, data shouldn't be. Sometimes (like with jump tables) they are ambiguous.<p>- Different CPUs have different memory consistency models for parallel threads, leading to race conditions when translating<p>- Special instruction sets like AVX can be hard to translate<p>- Anything with a JIT compiler (including most web browsers) needs special handling.<p>That said, qemu works for the great majority of emulated & host CPUs.