Static Linkers and Dyanmic Link Loaders

The intention of this page is to disambiguate the differences between the GNU static linker 'ld' and the GNU dynamic linker/loader 'ld.so'. There is a glossary at the end of this article which identifies many of the terms used.

= Linker vs. Loader =
 * The static linker ld is provided by the Binutils project.
 * The dynamic link loaders ld.so is provided by the GLIBC project.

These two libraries have similar function but they're run at two different times and have two separate sets of responsibilities.

The static linker is run against a series of object files following compilation. It's purpose is to link object files together into a library or executable where references to symbols from one object file to another are resolved to intra-library calls/branches. This process is called resolving relocations. A relocation is a symbol which is recognized by the linker to represent an algorithm for computing an address relative to another symbol.

The dyanmic link loader is run at application runtime. It has a number of duties:


 * When an application is executed the Kernel identifies which dynamic link loader is to be used to load the application and any external shared objects needed by the application. This dynamic link loader is executed by the kernel and given instructions to load and execute the application.
 * When an undefined external symbol reference is encountered at runtime the dynamic linker will load the necessary shared object and resolve the symbol to an address into the shared object.

= Relocations =

Relocations can serve several purposes:
 * The compiler generates object files with zero-based addressing. Relocations are used to compile several object files with initially overlapping address spaces into a single shared object with no overlapping address spaces.
 * Statically fix up inter-object file symbol or address dependencies.
 * Resolve addressing dynamically at run-time (as performed by the Loader).

= Terms =
 * Relocation
 * A symbol which maps to an algorithm and data for computing an address relative to another symbol or address.


 * Object File
 * A binary blob of executable code that represents one self contained unit of code. References to symbols in other object files are indicated via relocations.  A group of object files is put together to form a shared object.


 * Shared Object
 * A binary blob of executable code and non-executable data that contains no entry point for program execution (this is the simple explanation. Some shared objects like ld.so do indeed have an entry point).  This object must be dynamically loaded and linked at runtime to an executable.


 * Executable
 * A binary blob containing executable code and non-executable data which contains an entry point necessary to begin the execution of a program, i.e. different than a shared object.


 * Static Linker
 * Responsible for statically resolving inter-object file dependencies.


 * Dynamic Linker/Loader
 * Responsible


 * Dynamic Linker
 * See Dynamic Linker/Loader


 * Dynamic Loader
 * See Dynamic Linker/Loader


 * Loader
 * See Dynamic Linker/Loader