Skip to content

Mach-O Reference

mach_header_64

The Mach-O header (mach_header_64)

Every Mach-O file starts with a header giving its magic number, CPU type, file type and the count and size of the load commands that follow. It's the first thing a parser reads.

What it is

A Mach-O file opens with a fixed-size header. On 64-bit files it is mach_header_64; on 32-bit files, mach_header. It tells a loader (and a parser) what the file is before any of its contents are read.

Fields

FieldMeaning
magic0xFEEDFACF (64-bit) or 0xFEEDFACE (32-bit); byte-swapped variants mark the opposite endianness.
cputype / cpusubtypeThe architecture, e.g. x86_64 or arm64.
filetypeWhat the file is: MH_EXECUTE, MH_DYLIB, MH_BUNDLE, MH_OBJECT, MH_DSYM…
ncmdsNumber of load commands that follow the header.
sizeofcmdsTotal bytes of all load commands.
flagsAttributes such as MH_PIE, MH_TWOLEVEL, MH_DYLDLINK.
reserved64-bit only; padding.

Reading order

The header is immediately followed by ncmds load commands, filling sizeofcmds bytes. A parser reads the header, then walks exactly that many commands. The magic value also tells the parser the file's endianness and word size, which it needs before interpreting any further field.

Fat (universal) binaries

A universal binary is not a Mach-O header at all at offset 0 — it starts with a fat_header (0xCAFEBABE) listing architecture slices, each of which is a complete Mach-O with its own mach_header_64.