Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why can I run x86 binary on ARM?

I recently compiled a C program I wrote with gcc on my x86 intel MacBook – I downloaded this binary onto my M1 MacBook and it seems to run fine… This challenges my understanding because I figured it had to be complied for a specific instruction set (x86 in this case).. I wonder if there is some software layer in my MacBook automatically ‘assembling’ the x86 into ARM

Any ideas?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

MacOS contains Rosetta 2 software that does dynamic binary translation from x86, so that x86 software can be run on the M1 CPU. Not quite as efficient as code compiled directly from C to AArch64 machine code, but it works.

You can read more here:
https://developer.apple.com/documentation/apple-silicon/about-the-rosetta-translation-environment

Stack Overflow has a tag for it: .

There’s also a question on the Apple site: How does Rosetta 2 work? where answers point out that the translation is done once and cached, so it can spend significant time optimizing the translation. (For non-JITed x86 code.)

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading