Skip to content

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:

  1. Checks if the dylib is already loaded — if yes, increment its load count, return.
  2. If in the shared cache, use its PrebuiltLoader (instant).
  3. Otherwise, mmap the file, create a JustInTimeLoader.
  4. Recursively load the dylib's dependencies.
  5. Apply chained fixups for the new dylib.
  6. Run its static initializers.
  7. Return a handle.
apple-oss-distributions/dylddyld/Loader.cppThe dlopen path through dyld's Loader infrastructure.View on GitHub(line )

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.