TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Ask HN: Why can't we replace instructions in a binary for different ISAs?

2 pointsby monusover 4 years ago
I know this may sound really naive but I&#x27;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&#x27;t we edit the binary and change the calls to make the call in the certain ISA we want?<p>I know that&#x27;s possible with recompiling from the source code, for example with Go, but I was wondering why can&#x27;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&#x27;d like to run an arbitrary amd64 binary on a RISC-V core without recompiling the source code.<p>[1]: https:&#x2F;&#x2F;www.computerworld.com&#x2F;article&#x2F;3597949&#x2F;everything-you-need-to-know-about-rosetta-2-on-apple-silicon-macs.html

1 comment

tlbover 4 years ago
It works for simple cases. Things that make it complicated are:<p>- Only executable code should be translated, data shouldn&#x27;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 &amp; host CPUs.
评论 #25357419 未加载