Linker and Loader

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

Loader & its Functions

 A loader is a system program, which takes the object code of a program as input and prepares it

for execution.

 Loader Function : The loader performs the following functions :

 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

allocated memory space during execution.

 Loading - The loader actually loads the machine code corresponding to the object modules into the

allocated memory space and makes the program ready to execute.

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

place the assembled instruction inthe designated memory loactions.

 The assembly process is first executed and then the assembler causes a transfer to the first

instruction of the program.

 E.G. WATFOR FORTRAN compiler

 This loading scheme is also called assmble-and-go.

Advantages of Compile-and-go loaders:


 Simple and easier to implement.

 No additional routines are required to load the compiled code into the memory.

Dis advantages of Compile-and-go loaders:

 Wastage im memory spave due to the presence of the assembler.

 There is a need to re-assemble the code every time it is to be run.

 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

on to the cads forming the object decks instead of loading in memory.

The function of the loader is to read these cads and load them into memory specified by the

assembler. The four functions as performed in and absolute loader are :

1.Allocation

2.Linking

3.Relocation

4.Loading

Advantages of Absolute Loader:

 Simple, easy to design and implement.

 Since more core memory is available to the user there is no memory limit.

Dis advantages of Absolute Loader:


 The programmer must specifically tell the assembler the address where the program is to be

loaded.

 When subroutines are referenced, the programmer must specify their address whenever they are

called.

Machine Dependent Features

Relocation loader

 Loaders that allow for program relocation are called relocating loaders/relative loaders.

 There are two methods for this purpose.

 In the first method, a modification record is used to describe each part of the object code that

must be changed when the program is relocated.

 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.

 It then describes the modification to be performed.

 This method is not well suited for all machine architectures,

 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

segmet, which is in common with the others.

 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.

Program linking loader

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

in the program unit containing the reference.

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

performed for each external reference in the program units.

Machine Independent Features


Automatic Library Search

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

not defined must be kept.

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

repeated till all references are resolved.

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

were part of the primarily loader imput.

 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

programs being loaded.


 LIBRARY EXLIB This option allows the user to automatically include library subroutines to satisfy

the external references. The above command tells the loader to search the library EXLIB before

searching the standard libraries.

 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.

You might also like