Glossary
dlopen
The runtime API for loading a dylib into a process's address space. The basis of plugin architectures and conditional framework loading.
dlopen(path, mode) is the runtime API for loading a dynamic library into a process's address space, returning a handle that can be used with dlsym to find symbols.
When called, dyld:
- Checks if the dylib is already loaded — if yes, increment its load count, return.
- If in the shared cache, use its PrebuiltLoader (instant).
- Otherwise,
mmapthe file, create a JustInTimeLoader. - Recursively load the dylib's dependencies.
- Apply chained fixups for the new dylib.
- Run its static initializers.
- Return a handle.
Mode flags:
RTLD_NOW— resolve all symbols immediately.RTLD_LAZY— resolve symbols on first use (default).RTLD_GLOBAL— symbols are available to subsequent dlopens.RTLD_LOCAL— symbols scoped to this handle.
dlclose decrements the load count; when zero, dyld can unload the dylib (runs finalizers, unmaps memory).
Used heavily by plugin architectures (Final Cut Pro plugins, Photoshop plugins) and for lazy-loading optional frameworks.
See also: dyld, chained fixups, and the dyld in depth article.