|This article relies on references to primary sources. (March 2011)|
||This article includes a list of references, but its sources remain unclear because it has insufficient inline citations. (May 2010)|
|Uniform Type Identifier||com.apple.mach-o-binary|
|Developed by||Carnegie Mellon University/Apple Inc.|
|Type of format||Binary, executable, object, shared libraries, core dump|
|Container for||ARM, SPARC, PA-RISC, PowerPC and x86 executable code, memory image dumps|
Mach-O, short for Mach object file format, is a file format for executables, object code, shared libraries, dynamically-loaded code, and core dumps. A replacement for the a.out format, Mach-O offered more extensibility and faster access to information in the symbol table.
Mach-O was once used by most systems based on the Mach kernel. NeXTSTEP, iOS and Mac OS X are examples of systems that have used this format for native executables, libraries and object code. GNU Hurd, which uses GNU Mach as its microkernel, uses ELF, and not Mach-O, as its standard binary format.
Mach-O file layout 
Each Mach-O file is made up of one Mach-O header, followed by a series of load commands, followed by one or more segments, each of which contains between 0 and 255 sections. Mach-O uses the REL relocation format to handle references to symbols. When looking up symbols Mach-O uses a two-level namespace that encodes each symbol into an 'object/symbol name' pair that is then linearly searched for by first the object and then the symbol name.
The basic structure—a list of variable-length "load commands" that reference pages of data elsewhere in the file—was also used in the executable file format for Accent. The Accent file format was in turn, based on an idea from Spice Lisp.
Multi-architecture binaries 
Under NeXTSTEP, OPENSTEP and Mac OS X, multiple Mach-O files can be combined in a multi-architecture binary. This allows a single binary file to contain code to support multiple instruction set architectures. For example, a multi-architecture binary for Mac OS X could contain both 32-bit and 64-bit PowerPC code, or could contain both 32-bit PowerPC or x86 code, or could contain 32-bit PowerPC code, 64-bit PowerPC code, 32-bit x86 code, and 64-bit x86 (x86-64) code.
Mach-O future 
With the introduction of Apple's Mac OS X 10.6 platform the Mach-O file has undergone a significant modification that causes binaries compiled on a 10.6 computer to be by default only able to run on a 10.6 computer. The difference stems from load commands that Mac OS X's linker (dyld) can not understand on previous Mac OS X versions. Another significant change to the Mach-O format is the change in how the Link Edit tables (found in the __LINKEDIT section) function. In 10.6 these new Link Edit tables are compressed by removing unused and unneeded bits of information, however Mac OS X 10.5 and earlier cannot read this new Link Edit table format. To resolve this issue, the linker flag "-mmacosx-version-min=" is heavily used and depended on. Apple, current maintainer of the Mach-O format, recommends that all developers now use this flag along with the appropriate SDK headers when creating an application/binary.
Other implementations 
For Linux, a Mach-O loader was written by Shinichiro Hamaji, http://shinh.skr.jp/slide/ldmac/001.html Missing or empty
|title= (help) that can load 10.6 binaries. As a more extensive solution based on this loader, The Darling Project aims at providing a complete environment allowing to run OS X applications on Linux.
See also 
- Emmanuel Dreyfus (September 2004), Mac OS X binary compatibility on NetBSD: challenges and implementation
- Mach-O File Format Reference (Apple Inc.)
- Darwin and Mac OS X File Formats Manual –
- Mach Object Files (NEXTSTEP documentation)
- Mach-O Dynamic Library Reference
- Mach-O Viewer