0% found this document useful (0 votes)
19 views4 pages

Types of Loader

Loaders

Uploaded by

Ishan Shivankar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
19 views4 pages

Types of Loader

Loaders

Uploaded by

Ishan Shivankar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 4

Types of Loaders

Ishan Shivankar
November 7, 2024

Types of Loaders
Loaders are essential components of an operating system, responsible for loading programs into memory and
preparing them for execution. Various types of loaders exist, each serving different purposes, depending on
requirements such as speed, flexibility, and memory management. Here, we discuss different types of loaders
with examples, advantages, and disadvantages.

1. Compile-and-Go Loader
A Compile-and-Go loader is a simple type of loader in which the source code is compiled, assembled,
and loaded directly into memory for execution. This means the compilation and loading occur in one step
without creating separate object files or an explicit loading phase.

Example:
Imagine a basic educational environment where a student writes an assembly program. When they hit “run,”
the system:

• Compiles the program,


• Immediately loads it into memory, and
• Begins execution without storing it as a separate object file.

This approach is beneficial in simple systems where the code size is small, such as basic compilers or
educational software.

Advantages:
• Simplicity: The process is direct, with no intermediate files.
• Quick Execution: As there’s no separate loading phase, the program starts running as soon as
compilation is complete.

Disadvantages:
• Memory Inefficiency: The compiler or assembler must remain in memory along with the program,
consuming space.
• Inflexible: Any change requires recompilation, which can be tedious for large programs.
• Poor Error Handling: Errors are detected only at runtime, and debugging can be challenging.

1
2. General Loader Scheme
In the General Loader Scheme, the loader is a separate entity that loads compiled object code into
memory. Programs are compiled and stored as object files on disk, and the loader retrieves and loads these
files as needed, often performing linking and relocation.

Example:
Consider a scenario where two modules, Main and Helper, are compiled separately:
1. Compiling Main and Helper produces object files (Main.obj and Helper.obj).
2. The loader reads both files, links them, resolves addresses, and loads them into memory, allowing Main
to call functions in Helper.

This modular approach is common in larger applications and operating systems.

Advantages:
• Modularity: Code can be split into modules, allowing individual testing and faster compilation.
• Efficient Memory Use: Only necessary modules are loaded, conserving memory.
• Error Detection: Errors are identified during the linking phase, allowing for better debugging.

Disadvantages:
• Complexity: Requires handling links, relocations, and symbol resolutions.
• Loading Time: The additional steps of linking and relocating slow down the loading process.

3. Absolute Loading Scheme


In an Absolute Loading Scheme, a program is compiled with specific memory addresses. The loader
places it into memory without modifying these addresses. This approach works well when the program’s
memory location is known in advance, such as in embedded systems.

Example:
Consider an embedded program intended to load at 0x2000.
• During compilation, all instructions are fixed for the address 0x2000.

• At runtime, the loader directly places the program at 0x2000 without changing any addresses.
This method is useful in scenarios where programs run in fixed memory spaces.

Advantages:
• Fast Loading: No address modification is required, making it efficient.

• Simple Implementation: Since no relocation is needed, implementation is straightforward.

Disadvantages:
• Inflexibility: Programs are restricted to a fixed memory location, limiting usability.
• No Dynamic Linking: Programs cannot share or relocate memory space.

2
4. Subroutine Linkages
Subroutine Linkages refer to the method by which systems manage and link subroutines (functions) stored
separately from the main program. The loader identifies and links subroutine addresses to the main program
to enable execution.

Example:
Suppose Main calls Calculate() stored separately.
1. The main program includes a call to Calculate().
2. The loader resolves this call by linking Main to the memory location of Calculate().
This structure supports modularity and reusability across programs.

Advantages:
• Reusability: Common functions can be shared, reducing redundancy.
• Modularity: Programs can be organized into smaller components, improving readability and main-
tainability.

Disadvantages:
• Complex Linking: Managing multiple subroutines can introduce errors.
• Memory Overhead: Extra memory is required to store linking information.

5. Relocating Loaders
A Relocating Loader is more flexible than an Absolute Loader. It can adjust program addresses to load
in different memory locations. This capability is valuable for dynamic memory management and in systems
where memory usage varies.

Example:
If a program compiled for address 0x1000 needs to load at 0x2000:
• The loader adjusts all addresses by 0x1000, effectively relocating the program.
This flexibility allows multiple programs to share memory efficiently.

Advantages:
• Flexible Memory Management: Programs can load in any available space.
• Efficient Memory Use: Enables memory sharing across programs.

Disadvantages:
• Relocation Overhead: Adjusting addresses requires additional computation.
• Complex Implementation: Keeping track of relocatable addresses adds complexity.

6. Direct Linking Loaders


A Direct Linking Loader loads and links all required modules in one step, resolving addresses and creating
a single executable in memory. This approach is efficient for complex programs where multiple modules
interact.

3
Example:
Consider a program with a main module and several libraries (e.g., Lib1, Lib2):
• The Direct Linking Loader reads all modules, resolves all addresses, and loads them into memory as
one cohesive program.

This method minimizes runtime errors due to unresolved symbols and optimizes memory use.

Advantages:
• Efficient Execution: After loading, the program is ready for execution, without additional linking
steps.
• Error Reduction: Address resolution minimizes runtime errors.

Disadvantages:
• Memory Overuse: All modules load simultaneously, which may be inefficient if some modules are
unused.
• Slower Loading: The comprehensive linking process can slow down initial loading.

You might also like