Loader and Types of Loader

You might also like

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

1. Loader and Types of Loader.

Ans. A loader is a program that loads an executable file into memory and prepares it for execution. The
loader is typically part of the operating system and is responsible for allocating memory for the program,
resolving references between the program and any shared libraries or system components it depends on,
and initializing the program's data and stack segments.
The main tasks of the loader are:
i. Memory allocation: The loader allocates memory for the program's code, data, and stack
segments. The amount of memory required is determined by the size of the executable file and
the program's requirements.
ii. Relocation: The loader modifies the program's code and data segments to adjust the addresses
of symbols to reflect their final location in memory. This ensures that all the references to
symbols are correct and can be executed correctly.
iii. Linking: The loader resolves any references between the program and shared libraries or
system components it depends on. This involves loading the necessary libraries into memory
and linking them to the program.
iv. Initialization: The loader initializes the program's data and stack segments and transfers control
to the program's entry point.
Once the loader has completed its tasks, the program is ready to be executed. The operating system
transfers control to the program's entry point, which begins executing the program's code.
The loader is an important component of the operating system, as it allows executable files to be loaded
and executed in a reliable and secure manner. Without the loader, it would be much more difficult for
programs to be executed on modern computing systems.
Types of Loader are-
I. Compile and go Loader: A compile and go loader, also known as a just-in-time (JIT) compiler, is
a type of loader that dynamically compiles and executes code at runtime. With a compile and
go loader, the code is compiled and optimized on the fly as the program is being executed,
rather than being compiled ahead of time and stored in an executable file.
The main tasks of the compile and go loader are:
i. Code compilation: The compile and go loader compiles the code on the fly, as it is being
executed. This involves translating the program's source code into machine code, optimizing the
code for performance, and generating executable code.
ii. Code optimization: The compile and go loader optimizes the code for performance, using
techniques such as just-in-time compilation, which involves identifying frequently executed
code paths and compiling them ahead of time, and dynamic recompilation, which involves
recompiling code that has been executed multiple times to improve performance.
iii. Execution: Once the code has been compiled and optimized, the compile and go loader
executes the code in memory. The code is executed as if it had been compiled and stored in an
executable file.
II. General loader:
A general loader is a program that loads an executable file into memory and prepares it for execution.
Unlike a specialized loader, which is designed for a specific type of executable file or system, a general
loader is designed to work with a wide range of executable file formats and operating systems.
The main tasks of the general loader are:
i. File format detection: The general loader detects the format of the executable file and
determines the appropriate loader for that file format.
ii. Memory allocation: The loader allocates memory for the program's code, data, and stack
segments. The amount of memory required is determined by the size of the executable file and
the program's requirements.
iii. Relocation: The loader modifies the program's code and data segments to adjust the addresses
of symbols to reflect their final location in memory. This ensures that all the references to
symbols are correct and can be executed correctly.
iv. Linking: The loader resolves any references between the program and shared libraries or system
components it depends on. This involves loading the necessary libraries into memory and
linking them to the program.
v. Initialization: The loader initializes the program's data and stack segments and transfers control
to the program's entry point.
III. Absolute loader:
An absolute loader is a type of loader that is used to load an executable program into memory when the
program's memory address is known in advance. The absolute loader is called "absolute" because the
memory address of the program is fixed, or absolute, and does not change during the loading process.
The main tasks of the absolute loader are:
i. Memory allocation: The absolute loader allocates memory for the program's code, data, and
stack segments. The amount of memory required is determined by the size of the executable
file and the program's requirements.
ii. Relocation: The loader modifies the program's code and data segments to adjust the addresses
of symbols to reflect their final location in memory. In the case of an absolute loader, the
addresses are fixed, and so there is no need for relocation.
iii. Linking: The loader resolves any references between the program and shared libraries or system
components it depends on. Because the memory address of the program is known in advance,
there is no need for linking.
iv. Initialization: The loader initializes the program's data and stack segments and transfers control
to the program's entry point.

2. What is Bootstrap Loader?


Ans. The bootstrap loader is also a system program in the computer’s read-only memory (ROM). This
loader gets activated as soon as you switch on your computer. It reads your computer’s hard disk and loads
the operating system onto the main memory.

You might also like