Skip to content

Mach-O Reference

LC_SYMTAB

LC_SYMTAB — the symbol and string tables

LC_SYMTAB is the load command that locates a Mach-O file's classic symbol table: an array of nlist entries plus the string table their names point into. It is what nm and a linker read.

What it is

LC_SYMTAB is a short, fixed-size load command that tells a tool where the file's symbol table and string table live. It does not contain the symbols itself — only four offsets into the file.

Fields

FieldMeaning
cmdLC_SYMTAB (0x2).
cmdsize24 bytes — the command is fixed size.
symoffFile offset of the first nlist entry.
nsymsNumber of symbol-table entries.
stroffFile offset of the string table.
strsizeSize of the string table in bytes.

The symbol and string tables normally sit inside the __LINKEDIT segment at the end of the file.

The nlist entry

Each of the nsyms entries is an nlist_64 (or nlist on 32-bit files):

FieldMeaning
n_strxOffset into the string table for the symbol's name (0 = no name).
n_typeType byte: external bit N_EXT, the N_TYPE field (N_UNDF, N_SECT, N_ABS, N_INDR), and debug (N_STAB) bits.
n_sect1-based section number the symbol is defined in, or NO_SECT.
n_descExtra flags (weak references, library ordinals, and so on).
n_valueThe symbol's address — or 0 for an undefined symbol.

A symbol is defined when its N_TYPE is N_SECT (it lives in a section) or N_ABS; it is undefined (imported from a dynamic library) when N_TYPE is N_UNDF. Debugging stabs (N_STAB set) are a separate, older channel and are usually filtered out when counting real symbols.

How a parser reads it

Walk the load commands until LC_SYMTAB, then read nsyms entries starting at symoff. For each entry, the name is the NUL-terminated string at stroff + n_strx. Dynamic-linking metadata — which symbols are local, which are external definitions, and which are undefined imports — is further organised by LC_DYSYMTAB, which indexes into this same table.