Skip to content

Mach-O Reference

LC_LOAD_DYLIB

LC_LOAD_DYLIB — linked dynamic libraries

Each LC_LOAD_DYLIB records one dynamic library the image depends on, with its install name and version. Weak, re-export and upward variants change how the dependency is treated.

What it is

A Mach-O image lists each shared library it links against with a dedicated load command. The common one is LC_LOAD_DYLIB; several variants share the exact same structure and differ only in how dyld treats the dependency.

The dylib_command

FieldMeaning
cmdThe variant (see below).
cmdsizeCommand length, including the padded name.
dylib.nameOffset to the install name string (e.g. /usr/lib/libSystem.B.dylib).
dylib.timestampBuild timestamp (usually 2, a placeholder, today).
dylib.current_versionThe library's version, packed as X.Y.Z in 16.8.8 bits.
dylib.compatibility_versionThe oldest version this image can run against.

The name is stored as an lc_str: an offset, relative to the start of the command, to a NUL-terminated string that fills the rest of cmdsize.

The variants

CommandMeaning
LC_LOAD_DYLIBA normal, required dependency.
LC_LOAD_WEAK_DYLIBWeak: if the library is missing, undefined symbols become null instead of failing the load.
LC_REEXPORT_DYLIBThe image re-exports the library's symbols as its own (umbrella frameworks).
LC_LOAD_UPWARD_DYLIBAn upward dependency, used to break mutual-dependency cycles.
LC_LAZY_LOAD_DYLIBLoaded on first use rather than at launch.
LC_ID_DYLIBNot a dependency — a library's own install name and version. Present only in MH_DYLIB files.

Versions

current_version and compatibility_version are 32-bit numbers decoded as major.minor.patch using a 16-bit major and two 8-bit fields — so 0x054f2803 reads as 1359.40.3. The dynamic linker refuses to load a library whose current_version is lower than the compatibility_version an image was built against. Undefined symbols these libraries supply appear in the image's symbol table as N_UNDF entries.