0% found this document useful (0 votes)
24 views3 pages

Understanding Linkers in Computing

A linker is a program that combines one or more object files generated by a compiler into a single executable program, resolving symbols in the process. It can also handle dynamic linking, which postpones the resolution of some symbols until runtime, allowing for efficient library usage but introducing potential compatibility issues. The document discusses various aspects of linkers, including their functions, types of symbols, and the differences between linking and loading.

Uploaded by

Dheeraj Tamrakar
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views3 pages

Understanding Linkers in Computing

A linker is a program that combines one or more object files generated by a compiler into a single executable program, resolving symbols in the process. It can also handle dynamic linking, which postpones the resolution of some symbols until runtime, allowing for efficient library usage but introducing potential compatibility issues. The document discusses various aspects of linkers, including their functions, types of symbols, and the differences between linking and loading.

Uploaded by

Dheeraj Tamrakar
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Linker (computing) - Wikipedia, the free encyclopedia [Link]

org/wiki/Linker_(computing)

From Wikipedia, the free encyclopedia

In computer science, a linker or link editor is a program that takes one


or more objects generated by a compiler and combines them into a
single executable program.

In IBM mainframe environments such as OS/360 this program is known


as a linkage editor.

On Unix variants the term loader is often used as a synonym for linker.
Other terminology was in use, too. For example, on SINTRAN III the
process performed by a linker (assembling object files into a program)
was called loading (as in loading executable code onto a file)[1].
Because this usage blurs the distinction between the compile-time
process and the run-time process, this article will use linking for the
former and loading for the latter. However, in some operating systems An illustration of the linking
the same program handles both the jobs of linking and loading a process. Object files and static
program; see dynamic linking. libraries are assembled into a
new library or executable.

1 Overview
2 Dynamic linking
3 Relaxation
4 References
5 See also
6 External links

Computer programs typically comprise several parts or modules; all these parts/modules need not be
contained within a single object file, and in such case refer to each other by means of symbols. Typically, an
object file can contain three kinds of symbols:

defined symbols, which allow it to be called by other modules,


undefined symbols, which call the other modules where these symbols are defined, and
local symbols, used internally within the object file to facilitate relocation.

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. Some linkers do not include the whole library in
the output; they only include its symbols that are referenced from other object files or libraries. 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. This may involve relocating
code that assumes a specific base address to another base. Since a compiler seldom knows where an object
will reside, it often assumes a fixed base location (for example, zero). Relocating machine code may involve
re-targeting of absolute jumps, loads and stores.

1 of 3 1/6/2011 12:29 AM
Linker (computing) - Wikipedia, the free encyclopedia [Link]

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 offering 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 executable.

See also: Dynamic linker

Many operating system environments allow dynamic linking, that is the postponing of the resolving 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 binary.
If an error 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 platform as "DLL Hell", an incompatible updated DLL will break
executables that depended on the behavior of the previous DLL.
A program, together with the libraries it uses, might be certified (eg as to correctness, documentation
requirements, or performance) as a package, but not if components can be replaced. (This also argues
against automatic OS updates in critical systems; in both cases, the OS and libraries form part of a
qualified environment.)

As the compiler has no information on the layout of objects in the final output, it cannot take advantage of
shorter or more efficient instructions that place a requirement on the address of another object. For example,
a jump instruction can reference an absolute address or an offset from the current location, and the offset
could be expressed with different lengths depending on the distance to the target. By generating the most
conservative instruction (usually the largest relative or absolute variant, depending on platform) and adding
relaxation hints, it is possible to substitute shorter or more efficient instructions during the final link. This
step can be performed only after all input objects have been read and assigned temporary addresses; the
relaxation pass subsequently re-assigns addresses, which may in turn allow more relaxations to occur. In
general, the substituted sequences are shorter, which allows this process to always converge on the best
solution given a fixed order of objects; if this is not the case, relaxations can conflict, and the linker needs to
weight the advantages of either option.

1. ^ BRF-LINKER User Manual. ND-60.196.01. 08/84.

David William Barron, Assemblers and Loaders. 1972, Elsevier.


C. W. Fraser and D. R. Hanson, A Machine Independent Linker. Software-Practice and Experience
12, 4 (April 1982).
IBM Corporation, Operating System 360, Linkage Editor, Program Logic Manual, 1967 [1]

2 of 3 1/6/2011 12:29 AM
Linker (computing) - Wikipedia, the free encyclopedia [Link]

([Link]
D.W. Jones, Assembly Language as Object Code. Software-Practice and Experience 13, 8 (August
1983)
John R. Levine: Linkers and Loaders, Morgan-Kauffman, ISBN 1-55860-496-0
Leon Presser, John R. White: Linkers and Loaders. ACM Computing Surveys, Volume 4, Number 3,
September 1972, pp.149-167 [2] ([Link]
[Link])
Norman Ramsey, Relocating Machine Instructions by Currying. (1996) [3]
([Link]
David Salomon, Assemblers and Loaders. 1993 [4] ([Link]
/[Link])

Dynamic library
GNU linker
Library
Name decoration
Object file
Relocation
Relocation table
Prelinking
Static library

Ian Lance Taylor's Linkers blog entries ([Link]


/search?q=site%[Link]%2Fblog%2Farchives+%22linkers+part%22)
Linkers and Loaders by Sandeep Grover ([Link]
Another Listing of Where to Get a Complete Collection of Free Tools for Assembly Language
Development ([Link]
GoLink: a free linker for Windows programming ([Link]
Retrieved from "[Link]
Categories: Compilers | Computer libraries | Programming language implementation

This page was last modified on 27 August 2010 at 15:05.


Text is available under the Creative Commons Attribution-ShareAlike License; additional terms may
apply. See Terms of Use for details.
Wikipedia® is a registered trademark of the Wikimedia Foundation, Inc., a non-profit organization.

3 of 3 1/6/2011 12:29 AM

Common questions

Powered by AI

Dynamic linking postpones the resolution of some undefined symbols until a program is run, allowing shared libraries to be used, which can be updated independently of the executables relying on them. This reduces storage, as libraries aren't duplicated in every binary, and allows all dependent programs to benefit from library updates without recompilation. However, issues such as DLL Hell can arise, where updated libraries break dependent executables. Programs might also require certification of correctness and performance, which can complicate dynamic updates .

"DLL Hell" refers to the problems that arise when different programs rely on dynamic link libraries (DLLs) that are updated to incompatible versions. In dynamic linking, programs share DLLs to avoid redundancy and ease updates. However, when a DLL is updated in a way that breaks expected behavior, all programs depending on it can malfunction. This is specifically relevant in environments where replacing or upgrading libraries is common without recompiling dependent programs .

Relaxation in linking refers to the process of substituting shorter or more efficient instruction sequences after all input objects have been assigned temporary addresses. This involves replacing initially conservative instructions with more optimized versions, potentially adjusting addresses multiple times. The aim is to achieve the most efficient instruction sequence, minimizing code size and improving performance. This process can recursively adjust addresses and instruction lengths, converging to the best solution while considering trade-offs between conflicting relaxations .

Position-independent executables (PIEs) are designed to execute at any memory address, which helps avoid address conflicts during execution. In environments with virtual memory where each program runs in its own address space, PIEs prevent conflicts from multiple programs loading at the same base address by not requiring specific absolute addresses. This eliminates the need for an additional relocation pass when loading a program into memory .

Compilers often assume a fixed base location for objects, such as zero, because they lack information on where in memory the object will ultimately reside. This can create challenges, such as the need to adjust absolute jumps or load/store instructions when the program is loaded into different memory addresses. The linker addresses these challenges by relocating machine code, re-targeting addresses as necessary to ensure the program runs correctly in its allocated address space .

Linkers rearrange code to fit within the address space by relocating code segments that assume specific base addresses to new locations. This involves adjusting absolute jumps, loads, and stores to point to the correct memory locations as determined by the final layout of the executable. Such rearrangements can optimize memory usage and prevent conflicts while maintaining program correctness. They ensure that all references within the code correctly resolve to the intended data or function entries even after spatial adjustments during linking .

A linker is responsible for combining one or more object files generated by a compiler into a single executable program. It resolves symbols that reference parts of the program located in different object files, arranges the program's objects in memory, and may involve relocating code assuming specific base addresses to make it executable .

Automatic OS updates, while ensuring systems stay up-to-date with security and performance improvements, introduce trade-offs in environments using dynamic libraries. Updating libraries might disrupt certified systems where program correctness and performance have been verified against specific library versions. Automatic updates could replace library components, potentially causing incompatibilities or undesired behavior changes in programs relying on these libraries. In critical systems, maintaining a qualified environment with consistent components is essential, arguing against automatic updates .

Libraries are collections of precompiled code that can be used by multiple programs, avoiding duplication and reducing code size. During linking, linkers handle libraries by selectively including only the required symbols referenced by the program, rather than integrating complete libraries. This allows linkers to optimize the final executable and ensure necessary functionalities are consistent and available without inflating the program size unnecessarily .

In linking, symbols refer to identifiers for variables or functions used across different modules of a program. There are defined symbols, which are accessible by other modules; undefined symbols, which reference symbols defined elsewhere; and local symbols, used internally for relocation. During linking, the linker resolves these symbols by matching undefined symbols with their corresponding definitions across object files and ensuring references are correctly pointed to the memory locations of the defined symbols, creating a unified executable program .

You might also like