Mach-O Reference
LC_MAINLC_MAIN and LC_UNIXTHREAD — the entry point
LC_MAIN gives an executable's entry point as a file offset; LC_UNIXTHREAD is the older form carrying a full initial register state. One of them starts the program.
What it is
Every runnable Mach-O executable (MH_EXECUTE) needs to tell the loader where
execution begins. Two load commands do this, and
a file has exactly one of them.
LC_MAIN (modern)
LC_MAIN is the entry_point_command, used by executables built for modern
macOS and iOS. dyld sets up the process and then calls the entry point.
| Field | Meaning |
|---|---|
cmd | LC_MAIN (0x28, with the LC_REQ_DYLD bit set). |
cmdsize | 24 bytes. |
entryoff | File offset of the entry point, relative to the start of the image. |
stacksize | Initial stack size, or 0 for the system default. |
Because entryoff is a file offset rather than a virtual address, it is
independent of where the image is loaded — it pairs naturally with position-
independent (MH_PIE) executables. The runtime entry is normally the C
runtime's start, which eventually calls main.
LC_UNIXTHREAD (legacy)
LC_UNIXTHREAD is the older thread_command. Instead of a single offset it
carries a full initial thread state — the register values the kernel loads
before jumping in. The program counter register (rip on x86_64, pc on
arm64) holds the entry virtual address. It is still seen in kernel images,
some static executables and older binaries.
How a parser reports it
Find whichever command is present. For LC_MAIN, report entryoff (and the
stack size if non-zero). For LC_UNIXTHREAD, read the program-counter register
out of the saved thread state to recover the entry virtual address. Dynamic
libraries and bundles have neither command — they are loaded, not launched.