Mach-O Reference
LC_SEGMENT_64LC_SEGMENT_64 — segments and sections
LC_SEGMENT_64 describes a region of the file to map into memory — __TEXT, __DATA, __LINKEDIT — together with the sections inside it and the protections the segment is mapped with.
What it describes
An LC_SEGMENT_64 load command maps a contiguous region of the file into a
contiguous region of memory. A typical executable has a handful:
__TEXT— read-only, executable: machine code and constants.__DATA/__DATA_CONST— writable (or initialized-then-protected) data.__LINKEDIT— the tables dyld needs (symbols, signatures, bind info).
Key fields
| Field | Meaning |
|---|---|
segname | The 16-byte segment name (__TEXT). |
vmaddr / vmsize | Where and how large the segment is in memory. |
fileoff / filesize | Where its bytes live in the file. |
maxprot / initprot | Maximum and initial memory protections (r/w/x). |
nsects | Number of sections that follow this command. |
Sections
Right after the segment command come nsects section records. A section is
a named subdivision of a segment — __TEXT,__text (the code itself),
__TEXT,__cstring (C string literals), __DATA,__objc_classlist, and so on.
Each section record gives the section's own address, size, file offset and
alignment.
The split matters for analysis: the segment sets the memory protection a
region is mapped with (so __TEXT is non-writable), while sections tell you
what each part of that region actually contains.