All Topics  
Linker

 

   Email Print
   Bookmark   Link






 

Linker



 
 
In computer science
Computer science

Computer science is the study of the theoretical foundations of information and computation, and of practical techniques for their implementation and application in computer systems....
, a linker or link editor is a program
Computer program

Computer programs are Instruction for a computer. A computer requires programs to function. Moreover, a computer program does not run unless its instructions are executed by a Central processing unit; however, a program may communicate an Algorithm#Formalization of algorithms to people without running....
 that takes one or more objects
Object file

In computer science, object code, or an object file, is the representation of code that a compiler or assembler generates by processing a source code file....
 generated by a compiler
Compiler

A compiler is a computer program that transforms source code written in a programming language into another computer language . The most common reason for wanting to transform source code is to create an executable program....
 and combines them into a single executable
Executable

In computing, an executable causes a computer "to perform indicated tasks according to encoded instruction ," as opposed to a file that only contains data ....
 program.

In IBM
IBM

International Business Machines Corporation, abbreviated IBM and nicknamed "Big Blue" , is a multinational corporation computer technology and consulting corporation headquartered in Armonk, New York, New York, United States....
 mainframe
Mainframe computer

Mainframes are computers used mainly by large organizations for critical applications, typically bulk data processing such as census, industry and consumer statistics, Enterprise Resource Planning, and financial transaction processing....
 environments such as OS/360 this program is known as a linkage editor.

On Unix
Unix

Unix is a computer operating system originally developed in 1969 by a group of American Telephone & Telegraph employees at Bell Labs, including Ken Thompson , Dennis Ritchie, Douglas McIlroy, and Joe Ossanna....
 variants the term loader
Loader (computing)

In computing, a loader is the part of an operating system that is responsible for loading programs from executables into memory, preparing them for execution and then executing them....
 is often used as a synonym for linker.






Discussion
Ask a question about 'Linker'
Start a new discussion about 'Linker'
Answer questions from other users
Full Discussion Forum



Encyclopedia


Linker
In computer science
Computer science

Computer science is the study of the theoretical foundations of information and computation, and of practical techniques for their implementation and application in computer systems....
, a linker or link editor is a program
Computer program

Computer programs are Instruction for a computer. A computer requires programs to function. Moreover, a computer program does not run unless its instructions are executed by a Central processing unit; however, a program may communicate an Algorithm#Formalization of algorithms to people without running....
 that takes one or more objects
Object file

In computer science, object code, or an object file, is the representation of code that a compiler or assembler generates by processing a source code file....
 generated by a compiler
Compiler

A compiler is a computer program that transforms source code written in a programming language into another computer language . The most common reason for wanting to transform source code is to create an executable program....
 and combines them into a single executable
Executable

In computing, an executable causes a computer "to perform indicated tasks according to encoded instruction ," as opposed to a file that only contains data ....
 program.

In IBM
IBM

International Business Machines Corporation, abbreviated IBM and nicknamed "Big Blue" , is a multinational corporation computer technology and consulting corporation headquartered in Armonk, New York, New York, United States....
 mainframe
Mainframe computer

Mainframes are computers used mainly by large organizations for critical applications, typically bulk data processing such as census, industry and consumer statistics, Enterprise Resource Planning, and financial transaction processing....
 environments such as OS/360 this program is known as a linkage editor.

On Unix
Unix

Unix is a computer operating system originally developed in 1969 by a group of American Telephone & Telegraph employees at Bell Labs, including Ken Thompson , Dennis Ritchie, Douglas McIlroy, and Joe Ossanna....
 variants the term loader
Loader (computing)

In computing, a loader is the part of an operating system that is responsible for loading programs from executables into memory, preparing them for execution and then executing them....
 is often used as a synonym for linker. 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 the same program handles both the jobs of linking and loading a program; see dynamic linking
Library (computer science)

In computer science, a library is a collection of subroutines or Class used to develop software. Libraries contain code and data that provide services to independent programs....
.

Computer programs typically comprise several parts or modules; all these parts/modules need not be contained within a single object file
Object file

In computer science, object code, or an object file, is the representation of code that a compiler or assembler generates by processing a source code 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
Library (computer science)

In computer science, a library is a collection of subroutines or Class used to develop software. Libraries contain code and data that provide services to independent programs....
. 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
Address space

In computing, an address space defines a range of discrete addresses, each of which may correspond to a physical or virtual memory register, a Node , peripheral device, disk sector or other logical or physical entity....
. This may involve relocating code that assumes a specific base address
Base address

In computing, a base address is an address serving as a reference point for other addresses.In computers using relative addressing scheme, to obtain an absolute address, the relevant base address is taken and Offset is added to it....
 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.

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
Computer hardware

A personal computer is made up of computer hardware, multiple physical components onto which can be loaded into a multitude of software that perform the functions of the computer....
 offering virtual memory
Virtual memory

Virtual memory is a computer system technique which gives an application program the impression that it has contiguous working memory , while in fact it may be physically fragmented and may even overflow on to disk storage....
 — 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.

Dynamic linking

Many operating system
Operating system

An operating system is an interface between hardware and applications; it is responsible for the management and coordination of activities and the sharing of the limited resources of the computer....
 environments allow dynamic linking
Library (computer science)

In computer science, a library is a collection of subroutines or Class used to develop software. Libraries contain code and data that provide services to independent programs....
, 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.


Relaxation

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 weigh the advantages of either option.

See also

  • Dynamic library
  • GNU linker
  • Library
    Library (computer science)

    In computer science, a library is a collection of subroutines or Class used to develop software. Libraries contain code and data that provide services to independent programs....
  • Name decoration
  • Object file
    Object file

    In computer science, object code, or an object file, is the representation of code that a compiler or assembler generates by processing a source code file....
  • Relocation
  • Relocation table
    Relocation table

    The relocation table is a list of pointers created by the linker and linked into the MSDOS .exe file. The relocation table tells the loader where these segments can be found in program image loaded into computer storage....
  • Prelinking
  • Static library
    Static library

    In computer science, a static library or statically-linked library is a set of routines, external functions and variables which are resolved in a caller at compile-time and copied into a target application by a compiler, linker, or binder, producing an object file and a stand-alone executable file....


External links