Key Points: Dynamic Linking
Static vs. Dynamic Linking
- Static Linking Challenges:
- Each program includes a complete copy of library code
- Results in significant disk and memory waste
- Updates to libraries require recompiling all programs that use them
- Simple, but inefficient use of system resources
- Benefits of Dynamic Linking:
- Library code is shared between programs
- Updates can be made without recompiling
- Reduced memory and disk usage (over static linking)
- Supports runtime loading of library code
- Implementation Requirements:
- Position-independent code (PIC) for libraries
- System support for shared memory pages
- Runtime symbol resolution
- Library version management
Dynamic Linking Mechanisms
- Global Offset Table (GOT):
- Table of function/data addresses
- One per process
- Updated at load time
- Enables position-independent code
- Procedure Linkage Table (PLT):
- Contains function stubs
- Supports lazy binding
- Reduces startup overhead
- Maintains read-only code pages
- Symbol Resolution:
- Performed by dynamic linker
- Uses library search paths
- Handles version compatibility
- Supports symbol versioning
Advanced Features
- Lazy Binding:
- Functions resolved on first use
- Reduces program startup time
- Uses PLT stub functions
- Automatically handled by dynamic linker
- Library Versioning:
- Multiple versions can coexist
- Compilers record required library versions in programs
- Symbol-level versioning possible
- Maintains backward compatibility
- Runtime Loading:
- Libraries can be loaded on demand
- Supports plugin architectures
- Uses
dlopen/dlsyminterface - Enables dynamic code extension
System Considerations
- Security Aspects:
- Library search path security
LD_PRELOADrestrictions- Protected system directories
- Signature verification on some systems
- Performance Impact:
- Small overhead from indirect calls
- Reduced memory usage through sharing
- Startup time vs. lazy binding trade-off
- Modern CPUs optimize indirect calls
- System Features:
- Library path configuration
- Version compatibility checking
- Symbol interposition support
- Debug and development tools
Remember
- Dynamic linking saves memory by sharing library code
- Indirect calls through GOT enable position-independent code
- Lazy binding reduces program startup overhead
- Library versioning maintains compatibility
- Security measures protect against malicious libraries
- Modern systems balance flexibility and performance
- Runtime loading enables powerful plugin architectures
(When logged in, completion status appears here.)