Fundamentals of Shared Libraries from creation to versioning, ldconfig, and live upgrades

 

Chapter 41: Fundamentals of Shared Libraries
Master shared libraries in Linux — from creation to versioning, ldconfig, and live upgrades
6
Tutorial Files
18+
Code Examples
60+
Interview Q&A
Free
EmbeddedPathashala

What Are Shared Libraries?

A shared library (also called a dynamic library or DSO — Dynamic Shared Object) is a compiled object file that is loaded into memory at run time and can be shared by multiple programs simultaneously. Unlike static libraries, shared library code lives in a single copy in memory, saving RAM and disk space.

This chapter covers the internals of how Linux creates, names, installs, versions, and upgrades shared libraries. Understanding this is essential for any Linux systems programmer, embedded developer, or BLE/driver developer who ships reusable code.

Static vs Shared Library — Memory Layout
Static Library (.a) Shared Library (.so)
Code is copied into each executable at link time.

Every binary is self-contained.

Changes require re-linking all programs.

Code lives in one .so file on disk.

Multiple programs share one copy in RAM.

Update the library → all programs benefit.

⚠ Larger binaries, no live patching ✔ Smaller binaries, easy updates

Key Terms You Will Learn
soname real name linker name ldconfig /etc/ld.so.cache /etc/ld.so.conf -fPIC -shared -Wl,-soname compatible change incompatible change major version minor version live upgrade LD_LIBRARY_PATH

Tutorial Files in This Series

📦 Part 1 — ldconfig: The Library Cache Manager

Learn what ldconfig does, how /etc/ld.so.cache works, how soname symlinks are managed automatically, and how to use the -n option for private libraries.

ldconfig tasks /etc/ld.so.conf /etc/ld.so.cache soname symlinks -N / -X / -n options Private libraries 3 Code Examples
🔄 Part 2 — Compatible vs Incompatible Library Changes

Understand exactly when a library change is backward-compatible (minor version bump) versus when it breaks ABI and requires a new major version.

ABI compatibility rules Function signature changes Struct layout changes API additions Padding technique Version decision guide 3 Code Examples
⬆ Part 3 — Upgrading Shared Libraries (Live Upgrade)

Step-by-step guide to installing minor and major version upgrades of a shared library while programs are already running — zero downtime upgrades.

Minor version upgrade Major version upgrade ldconfig auto-update Symlink management Live running programs Full upgrade workflow 3 Code Examples
🏗 Part 4 — Object Libraries: Static vs Shared

What are .a and .so files, how are they built, what tools (ar, nm, readelf, objdump) are used, and when should you choose each type?

ar command ranlib -fPIC explained nm / readelf / ldd PLT & GOT intro Static vs Shared decision 3 Code Examples
⚙ Part 5 — Dynamic Linking Internals

How ld-linux.so loads libraries at startup, lazy vs eager binding, LD_PRELOAD for function interposition, LD_DEBUG for diagnostics, and library constructors/destructors.

ld-linux.so startup sequence PLT/GOT mechanics RTLD_LAZY vs RTLD_NOW LD_PRELOAD LD_DEBUG Constructors/Destructors 3 Code Examples
🔌 Part 6 — dlopen API: Runtime Dynamic Loading

Load shared libraries explicitly at runtime using dlopen/dlsym/dlclose/dlerror — the foundation of plugin systems, codec loaders, and driver hot-loading.

dlopen / dlsym / dlclose dlerror RTLD_LAZY / RTLD_NOW RTLD_GLOBAL / RTLD_LOCAL Plugin architecture Reference counting 3 Code Examples

Start Learning Now!

All tutorials are free. No login required.

Begin Part 1 → EmbeddedPathashala Home

Leave a Reply

Your email address will not be published. Required fields are marked *