Manually Run Rosetta 2 on x86 Binary

apple-siliconrosettauniversal-binaries

I wrote a very simple C program and my goal is to build an x86-only binary and then run that binary on an Apple Silicon Mac and have Rosetta 2 translate it into a Universal 2 binary. I want to look at the Rosetta 2-translated binary specifically; I'm not looking to build a Universal 2 app myself (that would be trivial).

I attempted to run the program through Terminal ($ ./helloworld) and even stick it inside of a .app, put it in the Applications folder, and double-click it. In both cases, the program runs correctly, but according to $ file helloworld, the binary is still x86-only (Rosetta 2 didn't add an arm64 executable).

Any idea how to force Rosetta 2 to translate a binary?

Best Answer

If you've written a program in C, simply compile the program twice, using Mac's version of gcc, and then use lipo to combine them into one program.

See https://developer.apple.com/documentation/xcode/building_a_universal_macos_binary for Apple's explanation of the process to create a universal Binary (containing both x86_64 and ARM64)