display | more...
Mach-O is an code object file format just like PEF, xcoff, a.out, EXE and others.

Mach-O can be of the following types:
MH_EXECUTE - an executable object file
MH_FVMLIB - a fixed vm shared library file
MH_OBJECT - a relocatable object file
MH_PRELOAD - a preloaded executable file
MH_CORE - a core file
MH as you might have presumed, stands for a Mach Header.
The first 4 bytes (magic) of the Mach-O file are 0xfeedface :-)) I guess that beats the 'joy!' magic of the PEF format. This is followed by an indentifier for a CPU architecture (say, for example x86), which is followed by an identifier for the exact CPU type (such as 486). Next comes the before-mentioned object type.

Next comes a concept that makes Mach-O superior to other object file formats. We get two 4-byte integers that indicate the number of load commands followed by their overall size.

The number of load commands varies from file to file, still it is a small program for Mach microkernel and dyld that instructs them on how to assemble the object file. The format goes into a great complexity here, but for starters, here is a list of supported commands with a short description (taken from mach-o/loader.h):

#define LC_SEGMENT     0x1   /* file segment to be mapped */
#define LC_SYMTAB      0x2   /* link-edit stab symbol table info
(obsolete) */
#define LC_SYMSEG      0x3   /* link-edit gdb symbol table info */
#define LC_THREAD      0x4   /* thread */
#define LC_UNIXTHREAD  0x5   /* UNIX thread (includes a stack) */
#define LC_LOADFVMLIB  0x6   /* load a fixed VM shared library */
#define LC_IDFVMLIB    0x7   /* fixed VM shared library id */
#define LC_IDENT       0x8   /* object identification information
(obsolete) */
#define LC_FVMFILE      0x9   /* fixed VM file inclusion */ 

LC stands for Load Command.

Log in or register to write something here or to contact authors.