views:

143

answers:

2

I would like to know how you can support i386 and ppc architectures for programs at /bin.

I run for instance

bin  $ file amber

I get

amber: setgid Mach-O universal binary with 2 architectures
amber (for architecture i386):  Mach-O executable i386
amber (for architecture ppc):   Mach-O executable ppc

How do programs support i386 and ppc in the source code?

In other words, which components can you remove, for instance, in /bin/amber if you remove the support of ppc -architecture?

+6  A: 

It's called a Universal binary. In short, the executable contains both types of executable code. Apple has a published document describing how developers should build their applications to run on either platform.

The executable lipo can be used to remove either version of the executable from the file. If you want your executables to contain only one version, you can use lipo to achieve this.

Be aware that there is more than just ppc and i386, although these are the "safest" architectures to choose for a Universal binary. Read the manpage for arch; there you can see that a modern OSX binary is likely to contain any of ppc, ppc64, i386 or x86_64. There are many more listed, but they exist there for completeness.

Jared Oberhaus
+4  A: 

It's called a fat binary.

There's a copy of the native code for both architectures in the binary. The binary format and the operating system have to support it, so it can know where to look in the file for the correct code.

zaius