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

1. Linker and types of Linkers.

Ans. A linker is a program that is used to combine one or more object files generated by a compiler into a
single executable program or library. Object files are intermediate files that are generated by a compiler
during the process of translating source code into machine code. Object files contain machine code, data,
and information about symbols used in the program.
The linker's primary function is to resolve references between object files, meaning it resolves undefined
symbols that are declared in one object file but defined in another. The linker does this by examining all
the object files and their symbol tables and creating a single executable or library that can be loaded and
executed by the operating system.
In addition to resolving symbol references, the linker may also perform other tasks such as removing
unused code and data, optimizing the layout of code and data in memory, and creating relocation
information that allows the program to be loaded at different memory locations.
Linkers are typically part of the toolchain used in software development, along with compilers, assemblers,
and other tools. The linker is an important step in the process of creating an executable program or library
from source code, and it plays a crucial role in ensuring that the program runs correctly and efficiently.
There are two main types of linkers:

 Static Linker: A static linker is a program that takes one or more object files and libraries as input and
produces a self-contained executable or library as output. The linker resolves all the references
between the input files and combines them into a single file that contains all the necessary code and
data to run the program. The resulting file can be executed on any system that supports the same
processor architecture without any additional dependencies.
The static linker performs a number of tasks, including:
i. Symbol resolution: The linker resolves all the references to external symbols used in the
program. This involves searching the object files and libraries for the definition of each symbol
and creating a table of addresses for each symbol.
ii. Relocation: The linker modifies the object files to adjust the addresses of symbols to reflect
their final location in the executable or library. This ensures that all the references to symbols
are correct and can be executed correctly.
iii. Dead code elimination: The linker removes any code or data that is not used in the final
executable or library. This reduces the size of the resulting file and can improve performance.
The main advantage of static linking is that it creates a self-contained executable or library that does not
depend on any external libraries or components. This makes it easier to deploy and distribute, since the
program can be run on any system that supports the same processor architecture. However, the resulting
file size can be larger than with dynamic linking, and any updates or changes to the program require a full
recompilation and relinking.

 Dynamic Linker: A dynamic linker is a program that loads and links libraries and object files at runtime,
instead of linking them at compile time. The dynamic linker is typically included as part of the operating
system and is responsible for resolving symbols and loading libraries as needed.
When a program that uses dynamic linking is executed, the dynamic linker loads the required libraries into
memory and links them to the program. This allows multiple programs to share the same code and data,
which can reduce the memory footprint of the system. Additionally, dynamic linking can simplify the
deployment of the program, as updates to the shared libraries can be installed independently of the main
program.
The main tasks of the dynamic linker are:
i. Symbol resolution: The dynamic linker resolves all the references to external symbols used in
the program, by searching for the symbols in the shared libraries and loading them into
memory.
ii. Relocation: The dynamic linker modifies the shared libraries 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. Loading of shared libraries: The dynamic linker loads shared libraries into memory and resolves
any dependencies between them.
The main advantage of dynamic linking is that it allows programs to share code and data, which can reduce
memory usage and simplify deployment. However, dynamic linking can introduce runtime overhead due to
the need to load shared libraries and resolve symbols at runtime. Additionally, it can make the program
more dependent on external components, which can introduce compatibility issues.
2. 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-
1. 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.
The main advantage of a compile and go loader is that it can provide improved performance compared to
traditional loaders, which compile code ahead of time and store it in an executable file. By dynamically
compiling and optimizing the code as it is being executed, a compile and go loader can adapt to changing
program behavior and take advantage of runtime information to improve performance. Additionally, a
compile and go loader can support dynamic code generation, which allows programs to generate code at
runtime, rather than being limited to the code that has been compiled ahead of time. However, the initial
startup time for a program using a compile and go loader may be longer, as the code must be compiled
and optimized before it can be executed.
Advantages:
o It is very simple to implement.
o The translator is enough to do the task, no subroutines are needed.
o It is the simplest scheme of the functions of the loader.

Disadvantages:
o There is no use of the assembler but it is still there so a wastage of memory takes place.
o When source code runs multiple times the translation is also done every time. so re-translation
is happening.
o Difficult to produce an orderly modular program
o Difficult to handle multiple segments like if the source program is in a different language. eg.
One subroutine is assembly language & another subroutine is FORTRAN.

2. 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.
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 general loader is a flexible and versatile tool that can work with a wide range of executable file formats
and operating systems. However, because it is designed to work with many different formats, it may not be
as efficient or optimized as a specialized loader that is designed for a specific format or system.
Advantages:
i. The program need not be retranslated each time while running it. Thus us because initially
when source program gets executed and object program gets generated. If a program is not
modified, then the loader can make use of this object program to convert it to executable form.
ii. There is no wastage of memory because the assembler is not placed in the memory instead of
it, loader occupies some portion of the memory. And the size of the loader is smaller than
assembler so more memory is available to the user.
iii. It is possible to write source program with multiple programs and multiple languages because
the source program is first converted to an object program always and loader accepts these
object modules to convert it to an executable format.

3. 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.
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 main advantage of an absolute loader is its simplicity and speed. Because the memory address of the
program is known in advance, there is no need for relocation or linking, which can significantly reduce the
time required to load the program into memory. However, the disadvantage of an absolute loader is that it
is inflexible, as the memory address of the program is fixed and cannot be changed, which can limit the
program's ability to adapt to changing conditions or requirements.
Advantages:
i. It is simple to implement.
ii. This scheme allows multiple programs or the source programs written in different languages. If
there are multiple programs written in different languages then the respective language
assembler will convert it to the language and common object file can be prepared with all the
ad resolution.
iii. The task of loader becomes simpler as it simply obeys the instruction regarding where to place
the object code to the main memory.
iv. The process of execution is efficient.
Disadvantages:
i. In this scheme, it's the programmer's duty to adjust all the inter-segment addresses and
manually do the linking activity. For that, it is necessary for a programmer to know the memory
management.
ii. If at all any modification is done to some segment the starting address of immediate next
segments may get changed the programmer has to take care of this issue and he/she needs to
update the corresponding starting address on any modification in the source.

You might also like