Professional Documents
Culture Documents
Linker and Loader
Linker and Loader
Linker and Loader
A loader is a system program, which takes the object code of a program as input and prepares it
for execution.
Allocation - The loader determines and allocates the required memory space for the program to
execute properly.
Linking -- The loader analyses and resolve the symbolic references made in the object modules.
Relocation - The loader maps and relocates the address references to correspond to the newly
Loading - The loader actually loads the machine code corresponding to the object modules into the
Types Of Loader
Compile-and-Go Loaders:
A compile and go loader is one in which the assembler itself does the processes of compiling then
The assembly process is first executed and then the assembler causes a transfer to the first
No additional routines are required to load the compiled code into the memory.
It becomes increasingly difficult to handle large number of segments when the input code is
written in a variety of HLL say one routine in pascal and one in FORTRAN and so on.
Such loader make designing modular programs and systems near impossible.
Absolute Loader
The assembler generates the object code equivalent of the source program bu the output is punched
The function of the loader is to read these cads and load them into memory specified by the
1.Allocation
2.Linking
3.Relocation
4.Loading
Since more core memory is available to the user there is no memory limit.
loaded.
When subroutines are referenced, the programmer must specify their address whenever they are
called.
Relocation loader
Loaders that allow for program relocation are called relocating loaders/relative loaders.
In the first method, a modification record is used to describe each part of the object code that
There is one modification record for each calue that must be changed during relocation.
Each modification record specifies the starting address and length of the field whose value is to be
altered.
On a machine that primarily uses direct addressing and hads a fixed instruction format, a different
rechnique is used.
The text records are same as before except that there is a relocation bit with each word of object
code.
These relocation bits are gathered together into a bit mask following a length indicator in each text
record.
If the bit is set to 1, the programs's starting address must be added to the word when program is
relocated.
If bit is 0, then no modification is necessary. The bits for unused words are also set to 0.
The BSS loader permits the usage of multiple subroutine segments or code pats and only one data
Each routine is assembled seperately and this transferred to the loader with appropriate informatin
relating to relocation and references among the subroutine along with the actual text.
The instructions, which depend on the address where the code is loaded, are termed address
sensitive instructions.
Let an application program 'A' consists of a set of program units. A program units interacts with
another by using the adresses latter's instructions and data in its own instructions. To enable this, the
program units must contain public defintions and external references. A public definition in a program
unit may be reference in others. An external reference is a reference to symbol, which is not defined
EXTRN and ENTRY statements are used to deeal with the above cases. ENTRY statement lists the
public definitions of program unit, whcih may be referenced in other program units. EXTRN statement
lists the symbols to which the external references are made in the program units.
Before executing the program A, for each of its program units, every external reference shoyld bound
to the correct link time address. This is called "LINKING".Once it is linked, it is said to be resolved.
A binary program is a machine language program consisting of a set of program units, such that each
program unit has been relocateed to the memory area starting at its link origin and linking has bee
Usually, the linking loaders can incorporate subroutines from a library into the program being
executed. This facility allows the programmeer to use the library routines as if they were a part of the
programming language. Fetching, linking and loading are done automatically. This is called automatic
library call/library search. For this reason, a record of all the external symbols that are refered to but
One way to do this would be enter the symbols from each refer record into the symbol table. When
the definiton is found, the address is entered. At the end of pass1, the symbols that remain
undefiened are called unresolved external references. The loader finds these by searching the
libraries. Since these subroutines may contain more external references, the search process must be
The library actually contain compiled versions of the routines so they can be searched using their
define records. Since this procedures is inefficient, a file structure is used for this purpose. This
structure contains directory that has the name of each subroutine and a pointer to its address within
the file.
Only one copy of the routine is stored even if there is more than one entry point. In such cases, all the
names that can be used to call the routine are entered but their pointers point to the same routine.
Loader Options
Some of the loader options that may be specified by the users are:
INCLUDE program name. This option allows the selection of the alternate sources of input. The
above command will tell the lader to read the specified program from the library and treat it as if it
DELETE control section name. This option allows the user to delete eternal symbols or control
sections. The delete command will tell the loader to delete the named control section from the set of
the external references. The above command tells the loader to search the library EXLIB before
NOCALL SQRT This option allows the users to execute ressolving some external references. The
above command tells the loader that the references to SQRT are to remain unresolved.
Linkage Editors
A linkage editor produces a linked version for the program called an executable image, which is
written to a file for later execution.
Dynamic Linking
Dynamic linking allows an object module toinclude only the information that is require at load time to
execute a program.
There are two types of dynamic linking, they are Load time dynamice linking and Run time dynamic
linking.