Monday, October 24, 2022

System Programming -Linker and Loder

 

Loaders and Linkers

Introduction:

In this chapter we will understand the concept of linking and loading. As discussed earlier the source program is converted to object program by assembler. The loader is a program which takes this object program, prepares it for execution, and loads this executable code of the source into memory for execution.

Definition of Loader:

Loader is utility program which takes object code as input prepares it for execution and loads the executable code into the memory. Thus loader is actually responsible for initiating the execution process.

Functions of Loader:

The loader is responsible for the activities such as allocation, linking,

relocation and loading

1) It allocates the space for program in the memory, by calculating the

size of the program. This activity is called allocation.

2) It resolves the symbolic references (code/data) between the object

modules by assigning all the user subroutine and library subroutine

addresses. This activity is called linking.

3) There are some address dependent locations in the program, such

address constants must be adjusted according to allocated space, such

activity done by loader is called relocation.

4) Finally, it places all the machine instructions and data of corresponding

programs and subroutines into the memory. Thus, program now becomes

ready for execution, this activity is called loading.

What is a Linker?

A linker is an important utility program that takes the object files, produced by the assembler and compiler, and other code to join them into a single executable file. There are two types of linkers, dynamic and linkage.

 

What is a Loader?

In the world of computer science, a loader is a vital component of an operating system that is accountable for loading programs and libraries. Absolute, Direct Linking, Bootstrap and Relocating are the types of loaders.

Difference between Linker and Loader

S.No.

LINKER

LOADER

1

A linker is an important utility program that takes the object files, produced by the assembler and compiler, and other code to join them into a single executable file.

A loader is a vital component of an operating system that is accountable for loading programs and libraries.

2

It uses an input of object code produced by the assembler and compiler.

It uses an input of executable files produced by the linker.

3

The foremost purpose of a linker is to produce executable files.

The foremost purpose of a loader is to load executable files to memory.

4

Linker is used to join all the modules.

Loader is used to allocate the address to executable files.

5

It is accountable for managing objects in the program’s space.

It is accountable for setting up references that are utilized in the program.

 

 

 

 

 

 

 

 

 

Relocation: As per its need, the OS may move (i.e. relocate) one or more segments of the program from one are of the memory to another. When the program gets relocated, instructions referring to code or data in these relocated segments must also be changed. Such instructions which must be changed when relocation occurs are called as “address sensitive” instructions.

The job of OS is to adjust addresses of all such address-sensitive instructions, when OS relocated one or more program segments.

(Note: Relocation function must be carried out every time the OS relocates the program segments; Relocation is often performed by a Linker for the Loader)

Functions of a Linker

A Linker basically performs following three functions:

1. Linking Object Files:A linker links multiple relocatable object files used by a

program and generates a single .exe file that can be loaded and executed by the

Loader.

2. Resolving External References:While linking those object files, the linker

resolves inter-segment and inter-program references to generate a single

continuous executable file.

3. Relocate Symbols: A linker relocates symbols from their relative locations in

input object files to new absolute positions in the executable file.

Functions of a Linker

A Linker basically performs following three functions:

1. Linking Object Files: A linker links multiple relocatable object files used by a

program and generates a single .exe file that can be loaded and executed by the

Loader.

2. Resolving External References: While linking those object files, the linker resolves inter-segment and inter-program references to generate a single continuous executable file.

3. Relocate Symbols: A linker relocates symbols from their relative locations in input object files to new absolute positions in the executable file.

 

 

 

 

 

Types of Programs w.r.t Relocation

Based on relocation, programs can be broadly classified as:

1. Non-relocatable Programs – These are static programs whose memory area is fixed at the time of coding and remains static i.e. cannot be changed thereafter.

(For example, the OS)

2. Relocatable Programs – These programs can be relocated to different memory areas as and when memory storage is needed by the OS. With the help of relocation information in the .exe file, the linker (at compile time) or relocating loader (at run time) will perform the functions needed to relocate the program.

Self-relocatable Programs – Such programs have small part of code (or subprograms) embedded in them which handle the operations needed to relocate the program. When OS relocates some (or all) part of code, control is transferred to the “Relocating subprogram” which adjusts addresses of its address sensitive portions of the code

EXTERN Table – includes name, type and (relative) usage addresses of symbols used by a current program that has been defined externally in some other program (i.e. symbols specified by EXTERN keyword)

Program Relocation

The squares program in the previous section contains four labels. The addresses of these labels are shown in the symbol table below:

 

These addresses are used to construct the constants contained in the branch and jump instructions. The address constants stored in the instructions have two possible interpretations:

 

The actual address of a memory location, also called an absolute address;

The offset to a memory location relative to a second known location.

A relocatable program is one which can be processed to relocate it to a selected area of memory. For illustration an object module. The difference among a relocatable and a non-relocatable program is the availability of information relating to the address sensitive instructions in this. A self-relocating program is the one which can perform the relocation of its own address sensitive instructions.

 

A self-relocating program can execute into any area of memory. It is very significant in time-sharing operating system where load address of a program is likely to be different for various executions.

A Non-Relocatable program is one which cannot be made to execute in any area of storage other than the one designated for it at the time of its coding or translation.


 



No comments:

Post a Comment

XOR Problem in neural network

  XOR problem with neural networks The XOR gate can be usually termed as a combination of NOT and AND gates The linear separability of p...