Linker (computing) 2026-11-05
A linker (computing) is a program that combines compiled or assembled components and connects references to their definitions. It reads object files and libraries, resolves named symbols, and applies relocation (computing) when locations become known. A typical output is an executable program or a shared software library.[ref]
Suppose one source file calls square and another defines it. Their object files can be produced separately; the linker (computing) matches the call's unresolved symbol to the definition and arranges the final reference. A missing definition can therefore cause a link-time failure even when each source file compiled successfully. Some references can instead be resolved when a shared software library is loaded.
Linking (computing) 2026-11-05
Linking combines separately produced program components and resolves references between them. A linker (computing) reads object files and library archives, assigns or adjusts locations through relocation (computing), and connects references to their definitions. GNU ld describes these as its central operations.[ref]
For example, one object file contains a call to a procedure defined in a second object file. The first compiler invocation can leave a symbolic reference; linking supplies the connection once both components are available. A missing definition or conflicting definitions can cause an error even when both source files compiled separately. Depending on the toolchain, some connections are completed before execution and others when a shared software library is loaded.
Relocation (computing) 2026-11-05
Relocation (computing) adjusts references in program components to match the addresses assigned during linking or loading. A relocation record identifies a place to patch, a target symbol and an architecture-dependent rule for computing the replacement. Moving a section changes the addresses associated with its contents, even when their relative arrangement stays fixed.[ref]
In an illustrative absolute-address rule, a symbol address and addend produce . In a relative rule defined using reference address , they may produce . If , and , the latter gives an offset of . Actual instruction encodings specify the precise reference point, scaling and allowed range, so a linker (computing) must apply the relocation type's rule rather than blindly adding one constant everywhere.