Mach-O

From Wikipedia, the free encyclopedia
Jump to: navigation, search
Mach-O
Mac OS X Executable Binary icon
Filename extension none, .o, .dylib
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, Darwin 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.

Contents

[edit] 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.

[edit] 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.

[edit] 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.

[edit] See also

[edit] External links

Personal tools
Namespaces
Variants
Actions
Navigation
Interaction
Toolbox
Print/export
Languages