Format:Mach-O/Bind and rebase opcodes
The opcode streams of LC_DYLD_INFO(_ONLY): dyld_info_command fields, REBASE_OPCODE_*, BIND_OPCODE_* and EXPORT_SYMBOL_FLAGS_* values from loader.h, how to decode them, and how they relate to chained fixups.
Overview
LC_DYLD_INFO (0x22) and LC_DYLD_INFO_ONLY (0x80000022) hold a dyld_info_command: cmd, cmdsize, then offset/size pairs (uint32 each, file offsets into __LINKEDIT) for rebase, bind, weak_bind, lazy_bind and export. The export part is a trie of exported symbols; the others are byte-code streams that tell dyld which pointers to slide (rebase) or to fill with a symbol address (bind). Newer binaries use Format:Mach-O/Chained fixups instead (LC_DYLD_CHAINED_FIXUPS plus LC_DYLD_EXPORTS_TRIE 0x80000033). A tool that finds neither load command is looking at an object file or a very old binary with a classic relocation table.
Each opcode byte is opcode | immediate: the high nibble (mask 0xF0) is the opcode and the low nibble (mask 0x0F) the immediate. ULEB128 and SLEB128 operands follow the byte.
Rebase opcodes
Types: REBASE_TYPE_POINTER 1, TEXT_ABSOLUTE32 2, TEXT_PCREL32 3.
| Opcode | Name |
|---|---|
| 0x00 | DONE |
| 0x10 | SET_TYPE_IMM |
| 0x20 | SET_SEGMENT_AND_OFFSET_ULEB (immediate = segment index) |
| 0x30 | ADD_ADDR_ULEB |
| 0x40 | ADD_ADDR_IMM_SCALED (immediate times pointer size) |
| 0x50 | DO_REBASE_IMM_TIMES |
| 0x60 | DO_REBASE_ULEB_TIMES |
| 0x70 | DO_REBASE_ADD_ADDR_ULEB |
| 0x80 | DO_REBASE_ULEB_TIMES_SKIPPING_ULEB |
Bind opcodes
Types: BIND_TYPE_POINTER 1, TEXT_ABSOLUTE32 2, TEXT_PCREL32 3. Special dylib ordinals: SELF 0, MAIN_EXECUTABLE -1, FLAT_LOOKUP -2, WEAK_LOOKUP -3. Symbol flags: WEAK_IMPORT 0x1, NON_WEAK_DEFINITION 0x8.
| Opcode | Name |
|---|---|
| 0x00 | DONE |
| 0x10 | SET_DYLIB_ORDINAL_IMM |
| 0x20 | SET_DYLIB_ORDINAL_ULEB |
| 0x30 | SET_DYLIB_SPECIAL_IMM |
| 0x40 | SET_SYMBOL_TRAILING_FLAGS_IMM (NUL-terminated name follows) |
| 0x50 | SET_TYPE_IMM |
| 0x60 | SET_ADDEND_SLEB |
| 0x70 | SET_SEGMENT_AND_OFFSET_ULEB |
| 0x80 | ADD_ADDR_ULEB |
| 0x90 | DO_BIND |
| 0xA0 | DO_BIND_ADD_ADDR_ULEB |
| 0xB0 | DO_BIND_ADD_ADDR_IMM_SCALED |
| 0xC0 | DO_BIND_ULEB_TIMES_SKIPPING_ULEB |
| 0xD0 | THREADED (immediate = subopcode: 0x00 SET_BIND_ORDINAL_TABLE_SIZE_ULEB, 0x01 APPLY) |
The threaded sub-opcodes are the older pointer-chain scheme that preceded Format:Mach-O/Chained fixups. Lazy binding (the lazy_bind stream) is consumed one entry at a time by the stub helper: each __stubs entry jumps through __la_symbol_ptr, which initially points to __stub_helper code that pushes an offset into the lazy stream. Unverified: stub helper details, written from general knowledge of dyld, not read in source in this pass.
Export trie flags
EXPORT_SYMBOL_FLAGS_KIND_MASK 0x03 (REGULAR 0, THREAD_LOCAL 1, ABSOLUTE 2), WEAK_DEFINITION 0x04, REEXPORT 0x08, STUB_AND_RESOLVER 0x10. Node encoding, read in dyld mach_o/ExportsTrie.cpp (recurseTrie, hasEntry, terminalPayloadToSymbol): a node starts with a ULEB128 terminal size; if non-zero, the next that many bytes are the terminal payload (ULEB flags, then a ULEB value, which is the offset from the image base, then extra fields by flag). Then one byte child count, then per child a NUL-terminated edge label and a ULEB offset of the child node from the start of the trie (0 is rejected as malformed). A symbol name is the concatenation of the edge labels on the path. Payload extras: REEXPORT (0x08) makes the value the dylib ordinal and is followed by a NUL-terminated imported name (empty string = same name); STUB_AND_RESOLVER (0x10) is followed by a ULEB resolver function offset; newer dyld also has an EXPORT_SYMBOL_FLAGS_FUNCTION_VARIANT flag followed by a ULEB variant table index. Unverified: the numeric value of FUNCTION_VARIANT (it is not in the xnu copy of loader.h read here).
Reversing notes
- Decode the bind stream to name every
__gotand__la_symbol_ptrslot; this recovers imported function names in a stripped binary. - The comment on export_off in loader.h wrongly says lazy binding info (copy-paste in the header); the field is the export trie.
Parent: Format:Mach-O. Related: Format:Mach-O/Load commands.
Code & repositories
- https://github.com/apple-oss-distributions/dyld @
fd8d0c4d52320ebf64db34f3cb280310d905c5ae· license: APSL-2.0 (declared by the contributor; GitHub's detector did not recognize a license file)
dyld source: mach_o/ExportsTrie.cpp (export trie node decoding), include/mach-o/fixup-chains.h, cache_builder/SubCache.cpp
Tested on: source read, not run: source read, not run: source read only · checked 2026-10-19; last activity 2026-06-18