[go: up one dir, main page]

0% found this document useful (0 votes)
13 views13 pages

SPOS

The document discusses linkers and loaders, which are essential components in system programming that convert object files into executable files and load them into memory for execution. It outlines the functions of loaders, their advantages and disadvantages, various loading schemes such as Compile and Go, General Loading, Absolute Loaders, and Direct Linking Loaders, as well as concepts like self-relocating programs and dynamic vs static linking. Additionally, it explains the use of overlays to manage memory efficiently by loading only necessary parts of a program.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views13 pages

SPOS

The document discusses linkers and loaders, which are essential components in system programming that convert object files into executable files and load them into memory for execution. It outlines the functions of loaders, their advantages and disadvantages, various loading schemes such as Compile and Go, General Loading, Absolute Loaders, and Direct Linking Loaders, as well as concepts like self-relocating programs and dynamic vs static linking. Additionally, it explains the use of overlays to manage memory efficiently by loading only necessary parts of a program.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

System programming and opera ng system

UNIT-3
Linkers and Loaders

Introduc on:
 A linker is a special program that combines the object files, generated by the
compiler/assembler and other pieces of code to originate an executable file
that has a .exe extension.
 A loader is a special program that takes input of executable files from linker,
loads it to main memory, and prepares this code for execu on by computer.

 Func ons of loader: Assemblers and compilers are used to convert source
code to object code. The loader will accept that object code, make it ready
for execu on, and helps to execute. Loader performs its task via four
func ons, these are as follows:
1. Allocation: It allocates memory for the program in the main
memory.
2. Linking: It combines two or more separate object programs or
modules and supplies necessary information.
3. Relocation: It modifies the object program so that it can be
loaded at an address different from the location.
4. Loading: It brings the object program into the main memory for
execution.
System programming and opera ng system

 Advantages and disadvantages of loader:


1. Memory management: The loader is responsible for alloca ng memory
for the program’s instruc ons and data.
2. Dynamic linking: The loader can resolve external references to other
programs or libraries at run me, which allows for more flexibility in the
design of the program.
3. Reloca on: The loader can relocate a program to any memory loca on,
which allows for efficient use of memory and prevents conflicts with other
programs.
4. Error handling: The loader can check the compa bility of the program
with the system and handle any errors that occur during loading, such as
missing libraries or incompa ble instruc on sets.

 Disadvantages:
1. Complexity: Loaders can be complex to implement and maintain, as they
need to perform a variety of tasks such as memory management, symbol
resolu on, and reloca on.
2. Security: A poorly designed or implemented loader can introduce
security vulnerabilities, such as buffer overflows or other types of
memory corruption.
3. Overlapping Memory: Due to the use of dynamic loading and
relocation, the same memory location may be used by multiple
programs leading to overlapping memory.
System programming and opera ng system

4. Dependency issues: Programs might have dependencies on external


libraries or other programs, and the loader needs to resolve these
dependencies before the program can be executed.

Loading schemes:
 Compile and go:
 The "Compile and Go" loader is a technique used in system programming to
load and execute programs. It is also called as “assemble and go and load and
go”.
 It is a loading scheme in which the assembler itself does the compila on and
then loads the assembled instruc ons in the designated memory loca on.
 Examples of compile-and-go systems are WATFOR, PL/C, and Dartmouth
BASIC
 Working:
 The instruc ons are read line by line, its machine code is obtained and it is
directly put in the main memory at some known address.
 The assembler runs in one part of the memory and assembled machine
instruc ons and data is directly put into their assigned memory loca ons.
 Here no object code is generated, source program is directly converted into
exe (Executable file) code.
 Advantages:
1. It is very simple to implement.
2. The translator is enough to do the task, no subroutines are needed.
3. The use of a compiler and loader can result in faster and more efficient
code execu on.
4. Compilers and loaders can automate many aspects of the so ware
development process, making it easier and faster to develop, test, and
deploy so ware.
5. No object files are required.
 Disadvantages:
1. There is no use of the assembler but it is s ll there so a wastage of
memory takes place.
2. When source code runs multiple times, the translation is also done
every time. so, re-translation is happening.
System programming and opera ng system

3. Takes more me as assembler and loader works simultaneously.

 General Loading scheme:


 In this loader scheme, the source program is converted to object program by
some translator (assembler). The loader accepts these object modules and
puts the machine instruc on and data in an executable form at their assigned
memory. The loader occupies the same por on of main memory.

 Advantages:
1. Smaller than Assembler.
2. No reassembly is needed.
3. There is no wastage of memory because assembler is not needed and
loader is also present at the same loca on.
4. Avoids drawbacks of compile and go.
 Disadvantages:
1. Some por on of memory is occupied by loader.
System programming and opera ng system

2. General loader cannot handle different object model from another


computer.

 Absolute Loaders with example:


 Absolute loader is a type of loader in which relocated object files (no fixed
loca on) are created.
 Loader accepts these files (object files) and places them at specific loca ons
of memory. This loca on is usually absolute and does not change when the
program is loaded into memory.
 In this loader there is no reloca on informa on is needed, i.e. When the
program is loaded into memory, it is placed exactly at this predefined
address, and no changes are made to the program's memory addresses
during loading.
 The programmer or system specifies these addresses explicitly, and they are
hardcoded into the program's machine code.
 The star ng address of every module is known to the programmer, this
corresponding star ng address is stored in the object file.

 Example:
 In the example there are two programs, i.e. MAIN starts at memory loca on
100. F1 starts at memory loca on 400. These loca ons are predefined
addresses where the program's code will be loaded.
 The absolute loader takes the compiled program and loads it directly into
memory at the predefined addresses. The MAIN program is loaded star ng
at address 100, and F1 is loaded star ng at address 400.
System programming and opera ng system

 The absolute loader directly loads the compiled code into these fixed
memory loca ons without any adjustments or reloca ons.

 Advantages:
1. It is simple to implement.
2. No reloca on is required.
3. The task of loader becomes simpler as it simply obeys the instruc on
regarding where to place the object code to the main memory.
 Disadvantages:
1. Programmer must specify the star ng address to the assembler for the
program where it should be loaded.
2. The programmer must know memory management as well as memory
status at any me.
3. It is very difficult to relocate in case of mul ple subrou nes.

 Func ons: In absolute loader 4 loader func on are performed by,


1. Alloca on: by programmer
2. Linking: by programmer.
3. Reloca on: by assembler
4. Loading-by loader
System programming and opera ng system

 Subrou ne linkages/program linking loader:


 In given program, it is o en needed to perform a par cular subtask many
mes on different data values. such a subtask is usually called a subrou ne.
 When a subrou ne is required, it can be called many mes during execu on
of a par cular program.

 Subrou ne Linkage method:


System programming and opera ng system

 Reloca ng loaders:
 A reloca ng loader is a type of loader that is used in system so ware to
load programs into memory and adjust their addresses. It is responsible for
dynamic loading, address transla on, and using a symbol table to adjust the
addresses of a program's instruc ons and data.
 The term "reloca ng" refers to the ability of the loader to adjust, or
"relocate", the absolute addresses in a program so that it can be loaded at
an address different from the one originally specified for it.
 It achieves this by modifying the object code of a program based on the
offset address, which is the star ng address where the program is loaded in
main memory.
 Example:
o The best examples of reloca ng loaders are found in early opera ng
systems. Here's a simple hypothe cal scenario to illustrate how a
reloca ng loader would work:
o Imagine an opera ng system that starts each program at memory
address 0. A programmer writes a program that uses memory addresses
0 through 999, and compiles it. The compiled program includes
instruc ons that refer to these memory addresses.
o However, when the program is loaded into memory, another program is
already using memory addresses 0 through 999. So, the opera ng
system decides to load the new program star ng at memory address
1000(Offset address).
System programming and opera ng system

 Direct linking loader (DLL) and need of DLL:


 A direct linking loader is a type of loader used in system programming to
load programs into memory and perform the linking process directly while
loading the program. It is a type of relocatable loader. It is the most
common type of loader.
 It allows the programmer to use mul ple procedure segments and mul ple
data segments.
 The assembler should give the following informa on to the DLL loader:
 The length of the object code segment.
 A list of all symbols which are not defined in the current segment but can
be used in the current segment.
 A list of all symbols that could be used by other segments.
 Informa on about address constants.
 Machine code transla on of the source program and rela ve address.
 DLL Assembler generates 4 types of cards in the object code:
 ESD (external symbol directory record): Card contains informa on about
all symbol that are defined in this program, but that may reference
elsewhere, and all symbol referenced in this program but defined
elsewhere.
 TXT (text records): Text card contains actual object code (translated
source code).
 RLD (reloca on and linking directory): Card contains informa on about
those loca ons in the program whose content depend on the address at
which the program is placed
 END: card indicate the end of object code and specifies the star ng
address for execu on if assembled rou ne is the main program.

 Need of DLL: A Direct Linking Loader is needed in situa ons where:


1. Modular Programs: Programs are divided into mul ple modules (code and
data) that need to be loaded and linked dynamically during execu on.
2. Dynamic Address Resolu on: It resolves references between modules (e.g.,
func on calls) at run me, making it adaptable to different memory
loca ons.
System programming and opera ng system

3. Reloca on: It adjusts memory addresses when segments are loaded at


different memory loca ons, preven ng conflicts.
4. Efficiency: It eliminates the need for separate linking steps, speeding up the
loading and execu on process for large programs.
5. Flexibility: It allows upda ng individual modules without recompiling the
en re program, making it easier to maintain and extend.

 Design:
 Design of direct linking loader is more complicated than absolute loader.
 Input to loader is object module and this is divided into 4 sec on ESD, TXT,
RLD, END.
 It requires two passes to complete the linking process: Pass I: assigns
addresses to all external symbols (Uses Global EST: GEST). Pass II: performs
actual loading, reloca on and linking.

 Advantages:
1. Allow mul ple procedure and data segment.
2. Reloca on Facility.
 Disadvantages:
1. Because the loader performs linking and reloca on during the loading phase,
it can be slower than loaders that perform these tasks separately before
loading.
2. The loader must be designed to handle both linking and reloca on
dynamically, making it more complex than simpler loaders that only load the
program.
System programming and opera ng system

 Self-reloca ng programs:
 Program reloca on means the ability to load and run a program at any
memory loca on, instead of needing a fixed loca on specified during its
crea on. This depends on how and when the program’s virtual memory
addresses are mapped to physical memory addresses. In simple terms, a
relocatable program can be placed anywhere in memory and s ll work
correctly, as its memory references are adjusted as needed.
 A self-reloca ng program is a program which can perform the reloca on
itself. Self-reloca ng program contain the reloca ng logic, so no need of a
linker in that.
1. Sta c linking:
 It is the process of copying all library modules used in the program into the
final executable code.
 The sta cally linked file includes both the calling program and the called
program.
 Sta c linking is done by linker as the final step of compila on. When the
program is loaded, the OS places only a single file to the memory containing
both the source code and the reference libraries.
 It has fast execu on but more disk storage.
2. Dynamic linking:
 It is the process of using only the name of the shared library module in
program.
 This dynamically link file includes only the name of calling program.
 Dynamic linking is done by the linker at run me. Dynamic linking allows
many programs to use single copy of library module.
 Execu on is slower but task takes less disk storage.

 Overlays:
 The loader can load programs in chunks called overlays, which allows
programs to run in a smaller memory space by only loading the needed
parts of the program at a me.
 Overlay is a part of program that has same load origin as some other parts
of the program and the program which contains overlays is called as overlay
structured program.
System programming and opera ng system

 The concept of overlays is that it will not use the complete program
simultaneously whenever a process is running. It will use only some part of
it. Then overlays concept says that whatever part you require, you load it,
and once the part is done, you just unload it, which means pull it back and
get the new part you required and run it.
System programming and opera ng system

You might also like