Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do programs support i386 and ppc at the same time?

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?

like image 847
Léo Léopold Hertz 준영 Avatar asked Jul 19 '09 00:07

Léo Léopold Hertz 준영


2 Answers

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.

like image 158
Jared Oberhaus Avatar answered Nov 10 '22 00:11

Jared Oberhaus


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.

like image 25
zaius Avatar answered Nov 10 '22 00:11

zaius