HOME

TheInfoList




In
computing Computing is any goal-oriented activity requiring, benefiting from, or creating computing machinery. It includes the study and experimentation of algorithmic processes and development of both computer hardware , hardware and software. It has sci ...

computing
, a linker or link editor is a computer system program that takes one or more
object file An object file is a computer file containing object code In computing Computing is any goal-oriented activity requiring, benefiting from, or creating computing machinery. It includes the study and experimentation of algorithmic processes and ...
s (generated by a
compiler In computing, a compiler is a computer program that Translator (computing), translates computer code written in one programming language (the ''source'' language) into another language (the ''target'' language). The name "compiler" is primarily ...

compiler
or an
assembler Assembler may refer to: Arts and media * Nobukazu Takemura Nobukazu Takemura (竹村延和 ''Takemura Nobukazu'') is a Japanese musician and artist. Born in Hirakata, Osaka in August 1968, he became interested in music at a young age by listenin ...
) and combines them into a single
executable In computing Computing is any goal-oriented activity requiring, benefiting from, or creating computing machinery. It includes the study and experimentation of algorithmic processes and development of both computer hardware , hardware and ...
file,
library A library is a collection of materials, books or media that are easily accessible for use and not just for display purposes. It is responsible for housing updated information in order to meet the user's needs on a daily basis. A library provi ...
file, or another "object" file. A simpler version that writes its
output Output may refer to: * The information produced by a computer, see * An output state of a system, see * , the amount of goods and services produced ** in economics, the value of net output or GDP plus intermediate consumption ** in economics, ...
directly to
memory Memory is the faculty of the by which or is , stored, and retrieved when needed. It is the retention of information over time for the purpose of influencing future action. If s could not be remembered, it would be impossible for language, r ...
is called the ''loader'', though loading is typically considered a separate process.


Overview

Computer programs typically are composed of several parts or modules; these parts/modules do not need to be contained within a single
object file An object file is a computer file containing object code In computing Computing is any goal-oriented activity requiring, benefiting from, or creating computing machinery. It includes the study and experimentation of algorithmic processes and ...
, and in such cases refer to each other by means of
symbols A symbol is a mark, sign, or word In linguistics, a word of a spoken language can be defined as the smallest sequence of phonemes that can be uttered in isolation with semantic, objective or pragmatics, practical meaning (linguistics), meanin ...
as addresses into other modules, which are mapped into memory addresses when linked for execution. Typically, an object file can contain three kinds of symbols: * defined "external" symbols, sometimes called "public" or "entry" symbols, which allow it to be called by other modules, * undefined "external" symbols, which reference other modules where these symbols are defined, and * local symbols, used internally within the object file to facilitate relocation. For most compilers, each object file is the result of compiling one input source code file. When a program comprises multiple object files, the linker combines these files into a unified executable program, resolving the symbols as it goes along. Linkers can take objects from a collection called a ''
library A library is a collection of materials, books or media that are easily accessible for use and not just for display purposes. It is responsible for housing updated information in order to meet the user's needs on a daily basis. A library provi ...
'' or
runtime library In computer programming Computer programming is the process of designing and building an executable computer program to accomplish a specific computing result or to perform a specific task. Programming involves tasks such as: analysis, genera ...
. Most linkers do not include the whole library in the output; they include only the files that are referenced by other object files or libraries. Library linking may thus be an iterative process, with some referenced modules requiring additional modules to be linked, and so on. Libraries exist for diverse purposes, and one or more system libraries are usually linked in by default. The linker also takes care of arranging the objects in a program's
address space In computing Computing is any goal-oriented activity requiring, benefiting from, or creating computing machinery. It includes the study and experimentation of algorithm of an algorithm (Euclid's algorithm) for calculating the greatest common ...
. This may involve ''relocating'' code that assumes a specific
base address In computing Computing is any goal-oriented activity requiring, benefiting from, or creating computing machinery. It includes the study and experimentation of algorithmic processes and development of both computer hardware , hardware and software ...
into another base. Since a compiler seldom knows where an object will reside, it often assumes a fixed base location (for example,
zero 0 (zero) is a number A number is a mathematical object A mathematical object is an abstract concept arising in mathematics. In the usual language of mathematics, an ''object'' is anything that has been (or could be) formally defined, and ...
). Relocating machine code may involve re-targeting of absolute jumps, loads and stores. The executable output by the linker may need another relocation pass when it is finally loaded into memory (just before execution). This pass is usually omitted on
hardware Hardware may refer to: Technology Computing and electronics * Computer hardware, physical parts of a computer * Digital electronics, electronics that operate on digital signals * Electronic component, device in an electronic system used to affect e ...

hardware
offering
virtual memory In computing, virtual memory, or virtual storage is a Memory management (operating systems), memory management technique that provides an "idealized abstraction of the storage resources that are actually available on a given machine" which "cre ...

virtual memory
: every program is put into its own address space, so there is no conflict even if all programs load at the same base address. This pass may also be omitted if the executable is a
position independent In computing Computing is any goal-oriented activity requiring, benefiting from, or creating computing machinery. It includes the study and experimentation of algorithmic processes and development of both computer hardware , hardware and softw ...
executable. On some
Unix Unix (; trademarked as UNIX) is a family of multitasking, multiuser Multi-user software is computer software Software is a collection of Instruction (computer science), instructions that tell a computer how to work. This is in contrast t ...

Unix
variants, such as
SINTRAN III Sintran III is a real-time, multitasking, multi-user Multi-user software is computer software Software is a collection of Instruction (computer science), instructions and data (computing), data that tell a computer how to work. This is in ...
, the process performed by a linker (assembling object files into a program) was called '' loading'' (as in loading executable code onto a file). Additionally, in some operating systems, the same program handles both the jobs of linking and loading a program (
dynamic linking In computing Computing is any goal-oriented activity requiring, benefiting from, or creating computing machinery. It includes the study and experimentation of algorithmic processes and development of both computer hardware , hardware and softwar ...
).


Dynamic linking

Many
operating system An operating system (OS) is system software System software is software designed to provide a platform for other software. Examples of system software include operating systems (OS) like macOS, Linux, Android (operating system), Android and Mi ...

operating system
environments allow dynamic linking, deferring the resolution of some undefined symbols until a program is run. That means that the executable code still contains undefined symbols, plus a list of objects or libraries that will provide definitions for these. Loading the program will load these objects/libraries as well, and perform a final linking. This approach offers two advantages: * Often-used libraries (for example the standard system libraries) need to be stored in only one location, not duplicated in every single executable file, thus saving limited
memory Memory is the faculty of the brain A brain is an organ Organ may refer to: Biology * Organ (anatomy) An organ is a group of Tissue (biology), tissues with similar functions. Plant life and animal life rely on many organs that co-exis ...
and
disk Disk or disc may refer to: * Disk (mathematics) * Disk storage Music * Disc (band), an American experimental music band * Disk (album), ''Disk'' (album), a 1995 EP by Moby Other uses * Disc (galaxy), a disc-shaped group of stars * Disc (magazin ...
space. * If a bug in a library function is corrected by replacing the library, all programs using it dynamically will benefit from the correction after restarting them. Programs that included this function by static linking would have to be re-linked first. There are also disadvantages: * Known on the
Windows Microsoft Windows, commonly referred to as Windows, is a group of several proprietary {{Short pages monitor">https://archive.today/20200114224817/https://linker.iecc.com/ 2020-01-14 -->
* (19 pages) *


External links


Ian Lance Justin's ''Linkers'' blog entries

Linkers and Loaders
a
Linux Journal ''Linux Journal'' (''LJ'') is a monthly technology magazine A magazine is a periodical literature, periodical publication which is printing, printed in Coated paper, gloss-coated and Paint sheen, matte paper. Magazines are generally published ...
article by Sandeep Grover
Another Listing of Where to Get a Complete Collection of Free Tools for Assembly Language Development



LLD - The LLVM Linker
* {{Authority control Compilers Computer libraries Programming language implementation Utility software types