TheTank20
TheTank20

Reputation: 91

Is it possible to have PowerPC, x86_64, and ARM64 in the same macOS application?

I'm wondering if it's possible for a single application to support PowerPC, Intel x86, and Apple Silicon ARM64 at once, disregarding practical limitations (like compatibility from 10.4 Tiger to 14 Sonoma).

This is more of a thought than anything, not worth getting PearPC or QEMU out to test it.

Upvotes: 4

Views: 134

Answers (1)

Gordon Davisson
Gordon Davisson

Reputation: 125708

Yes it is, since macOS supports Mach-O universal ("fat") binaries, which can contain an arbitrary number of different binaries for different architectures. For an actual example, check out TinyClock:

$ file /Applications/TinyClock.app/Contents/MacOS/TinyClock 
/Applications/TinyClock.app/Contents/MacOS/TinyClock: Mach-O universal binary with 5 architectures: [i386:Mach-O executable i386] [x86_64:Mach-O 64-bit executable x86_64] [ppc64:Mach-O executable ppc64] [ppc:Mach-O executable ppc] [arm64:Mach-O 64-bit executable arm64]
/Applications/TinyClock.app/Contents/MacOS/TinyClock (for architecture i386):  Mach-O executable i386
/Applications/TinyClock.app/Contents/MacOS/TinyClock (for architecture x86_64):Mach-O 64-bit executable x86_64
/Applications/TinyClock.app/Contents/MacOS/TinyClock (for architecture ppc64): Mach-O executable ppc64
/Applications/TinyClock.app/Contents/MacOS/TinyClock (for architecture ppc):   Mach-O executable ppc
/Applications/TinyClock.app/Contents/MacOS/TinyClock (for architecture arm64): Mach-O 64-bit executable arm64

Building executables like this is actually fairly easy. Some build tools, like Xcode, will let you select what architectures you want (though AIUI the current version only lets you select x86_64 and arm64). But if that's not an option (or doesn't support all the architectures you want), you can just compile for each architecture separately and use lipo -create to combine the executables. You may need to do that anyway, since you may need different compilers and also to build different architectures against different SDKs to support the OS versions that support those different architectures.

Further reading: Apple dev docs on "Building a Universal macOS Binary", Falko's Blog on "Building a fat / universal library for macOS", TenFourFox Development's blog on "The Super Duper Universal Binary" (which includes up to 17 binaries, each optimized for a different subarchitecture).

If you want to get really extreme, I think it'd be possible to also support pre-OS-X versions of Mac OS, on both PPC and 68k architectures, by adding a resource fork to the file that included both 68k "CODE" resources and PPC Code Fragment Manager resources (though the actual PPC code fragments would have to be in the data fork -- but I think you could hide them within the Mach-O universal binary, maybe as an additional fake binary with a nonexistent architecture ID). See chapter 7 of Apple's "Mac OS Runtime Architectures - For System 7 Through Mac OS 9".

Upvotes: 6

Related Questions