I find it hard to believe that this page hasn't existed before...
In its most general sense, a linker is a program which does takes one or more files containing ObjectCode, aggregates them together, and does something useful with the resulting aggregation. The input files can be explicitly specified (corresponding to the user's program), or system libraries which are implicitly included. The "does something useful" part can be generation of a resulting object file or executable, execution of the resulting aggregation, or both. In addition, the "something useful" can include a significant optimization phase.
In some cases (DynamicCompilation) linkers subsume much of the functionality of compilers. The runtime engine of a scripting language may do everything a traditional compiler and linker would do - parsing and semantic analysis of the program text, optimization, generation of machine code or an IntermediateForm?, combining the result with other libraries, and execution of the final program.
Many other terms are used to refer to specific categories of linkers, or programs which include linker functionality:
- A static linker reflects the traditional use of the term: a program which takes as input one or more object files and/or libraries, and produces an object file or executable as a result. (Here the difference between "object file" and "executable" is that the former may have unresolved symbols, whereas the latter should not (but see remarks on dynamic linkers below), and the latter contains the necessary machinery for direct execution by the OS). Linkers of this sort typically operate on machine code for the underlying CPU.
- A loader is a program which takes an executable file, loads it into memory, and executes it. Traditional loaders perform no additional linking, or might link to a fixed set of well-defined system libraries. Often times, the loader is part of the OperatingSystem kernel rather than a stand-alone program.
- A dynamic linker is a more advanced form of loader which contains full linker functionality - it can resolve undefined symbols in an executable (which are now permitted in systems with dynamic linkers) with symbols defined in an arbitrary set of SharedLibrarys.
- Most VirtualMachines contain linker functionality, as non-trivial programs are typically spread across multiple files and incorporate libraries from other sources.
The classic text on the subject is the
LinkersAndLoadersBook
CategoryLinker, CategorySoftwareTool