Understanding Loaders and Linking Concepts
Understanding Loaders and Linking Concepts
Introduction, functions of loaders, Relocation and Linking concept, Different loading schemes : Relocating loader, Direct
Linking Loader, Dynamic Linking and loading. [ Hr - 8 ]
In the previous chapter, the user’s source program decks are usually
converted to object program decks ( machine language) by assemblers
and compilers.
1
[ 4. Introduction, functions of loaders, Relocation and Linking concept, Different loading schemes : Relocating loader, Direct
Linking Loader, Dynamic Linking and loading. [ Hr - 8 ]
LINKER :
Linker Loader
It’s a computer program, that takes
one or more object files generated by It’s a program that loads
a compiler and combines them into a machine codes of a program
single executable file, library file, or into the system memory.
another object file.
Loader is a part of an
Linker is a part of a library files.
operating system.
It loads the program for
It performs the linking operations.
execution.
Loading a program involves
It also links the user defined functions
loading the contents of
to the user defined libraries.
executable file into memory
TYPES OF LOADERS :
These loaders primarily differ in the manner in which the four basic
functions are accomplished.
1. Compile-and-Go Loader :
The assembler run in one part of memory and place the assembled
machine instructions and data, as they are assembled, directly into
their assigned memory locations.
2
[ 4. Introduction, functions of loaders, Relocation and Linking concept, Different loading schemes : Relocating loader, Direct
Linking Loader, Dynamic Linking and loading. [ Hr - 8 ]
The assembler simply places the code into core, and the “loader”
consists of one instruction that transfers to the starting instruction of
the newly assembled program.
Advantage:
1. Simple to implement.
2. No extra procedures involved.
3
[ 4. Introduction, functions of loaders, Relocation and Linking concept, Different loading schemes : Relocating loader, Direct
Linking Loader, Dynamic Linking and loading. [ Hr - 8 ]
4
[ 4. Introduction, functions of loaders, Relocation and Linking concept, Different loading schemes : Relocating loader, Direct
Linking Loader, Dynamic Linking and loading. [ Hr - 8 ]
3. Absolute Loaders :
5
[ 4. Introduction, functions of loaders, Relocation and Linking concept, Different loading schemes : Relocating loader, Direct
Linking Loader, Dynamic Linking and loading. [ Hr - 8 ]
1. Allocation - by programmer.
2. Linking - by programmer.
3. Relocation - by assembler.
4. Loading - by loader.
Bootstrap Loader:
6
[ 4. Introduction, functions of loaders, Relocation and Linking concept, Different loading schemes : Relocating loader, Direct
Linking Loader, Dynamic Linking and loading. [ Hr - 8 ]
Bootstrapping :
Bootstrapping in a loader :
Loads operating system from disk into memory and makes it run.
7
[ 4. Introduction, functions of loaders, Relocation and Linking concept, Different loading schemes : Relocating loader, Direct
Linking Loader, Dynamic Linking and loading. [ Hr - 8 ]
( no need to relocation).
Relocating loader :
It is used to avoid reassembling of all subroutines when a subroutine
is changed and to execute tasks of allocation and linking for
programmer. It adjust addresses of the executable code to
compensate for variations in the address at which loading starts. The
computers which need relocating loaders are those in which pointers
are absolute addresses rather than offset from the programs base
address. Binary Symbolic Subroutine (BSS) loader is an example of
Relocating Loader. BSS performs all the four functions of the loader.
[ the transfer vector is used only for transfers and not used for loading
or storing of external data. The size of the object program in the
memory is increased due to transfer vector. ]
8
[ 4. Introduction, functions of loaders, Relocation and Linking concept, Different loading schemes : Relocating loader, Direct
Linking Loader, Dynamic Linking and loading. [ Hr - 8 ]
There are four sections to the object deck ( four card formats):
9
[ 4. Introduction, functions of loaders, Relocation and Linking concept, Different loading schemes : Relocating loader, Direct
Linking Loader, Dynamic Linking and loading. [ Hr - 8 ]
The TXT cards contain blocks of data and the relative address at which
the data is to be placed. Once the loader has decided where to load
the program, it merely adds the Program Load Address (PLA) to the
relative address and moves the data into the resulting location. The
data on the TXT card may be instructions, non-relocated data, or
initial values of address constants.
The END card specifies the end of the object deck. If the assembler
END card has a symbol in the operand field, it specifies a start of
execution point to the entire program (all subroutines). This address
is recorded on the END card.
Refer the simple programs PG1 and PG2 in the below figure:
10
[ 4. Introduction, functions of loaders, Relocation and Linking concept, Different loading schemes : Relocating loader, Direct
Linking Loader, Dynamic Linking and loading. [ Hr - 8 ]
Procedure PG1 :
11
[ 4. Introduction, functions of loaders, Relocation and Linking concept, Different loading schemes : Relocating loader, Direct
Linking Loader, Dynamic Linking and loading. [ Hr - 8 ]
Procedure PG2 :
12
[ 4. Introduction, functions of loaders, Relocation and Linking concept, Different loading schemes : Relocating loader, Direct
Linking Loader, Dynamic Linking and loading. [ Hr - 8 ]
13
[ 4. Introduction, functions of loaders, Relocation and Linking concept, Different loading schemes : Relocating loader, Direct
Linking Loader, Dynamic Linking and loading. [ Hr - 8 ]
14
[ 4. Introduction, functions of loaders, Relocation and Linking concept, Different loading schemes : Relocating loader, Direct
Linking Loader, Dynamic Linking and loading. [ Hr - 8 ]
Figure shows the main storage after the programs have been
allocated space, relocated, linked, and loaded.
On the other hand these symbols are external to PG2; thus, the
assembler, while processing PG2, has no means for evaluating the
address constant. This is illustrated in fig. 5.14. the TXT card for
relative locations 32-35 contains a -3, the only part of the address
constant that can be calculated by the assembler. The last two RLD
cards tell the loader to add the value of ID 03, which is PG1ENT2, to
location 32 – 35 and then subtract the value of id 02, which is
PG1ENT1. When processed by the loader, this address constant in
PG2 will indeed have the same value as the one in PG1.
15
[ 4. Introduction, functions of loaders, Relocation and Linking concept, Different loading schemes : Relocating loader, Direct
Linking Loader, Dynamic Linking and loading. [ Hr - 8 ]
The major function of pass 2 is to load the actual program text and
perform the relocation modification of any address constants needing
to be altered.
The first pass allocates and assigns storage locations to all segments
and stores the values of all external symbols in a symbol table. These
external symbols appear as local definitions on the ESD cards of
another assembled program. For every external reference symbol
there must be a corresponding internal symbol in some other
program. The loader inserts the absolute address of all of these
external symbols in the symbol table.
In the second pass, the loader places the text into the assigned
locations and performs the relocation task, modifying re-locatable
constants. Figure 5.16 depicts the interplay between the passes of a
loader in a direct linking loading scheme.
16
[ 4. Introduction, functions of loaders, Relocation and Linking concept, Different loading schemes : Relocating loader, Direct
Linking Loader, Dynamic Linking and loading. [ Hr - 8 ]
The Blobal External Symbol Table (GEST) is used to store the external
symbols defined by means of a Segment Definition (SD) or Local
Definition (LD) entry on an External Symbol Dictionary (ESD) card.
When these symbols are encountered during pass 1, they are assigned
an absolute core address; this address is stored, onloing with the
symbol, in the GEST. ( in figure 5.22).
17
[ 4. Introduction, functions of loaders, Relocation and Linking concept, Different loading schemes : Relocating loader, Direct
Linking Loader, Dynamic Linking and loading. [ Hr - 8 ]
ALGORITHM :
It is necessary for the loader to know where it can load the first
segment. This address, the Initial Program Load Address (IPLA), is
normally determined by the operating system.
In some systems the programmer may specify the IPLA; in either case
we will assume that the IPLA is a parameter supplied to the loader.
Initially, the Program Load Address (PLA) is set to the Initial Program
Load Address (IPLA).
An object card is then read and a copy written for use by pass 2.
The card can be one of five types, ESD, TXT, RLD, END, or LDT/EOF.
18
[ 4. Introduction, functions of loaders, Relocation and Linking concept, Different loading schemes : Relocating loader, Direct
Linking Loader, Dynamic Linking and loading. [ Hr - 8 ]
The symbol and its assigned value are then stored in the GEST; if the
symbol already existed in the GEST, there must have been a previous
SD or LD ESD with the same name – this is an error.
The symbol and its value are printed as part of the load map.
When the LDT or EOF card is finally read, pass 1 is completed and
control transfers to pass 2.
After all the segments have been assigned locations and the external
symbols have been assigned locations and the external symbols have
been defined by pass 1, it is possible to complete the loading by
loading the text and adjusting (relocation or linking) address
constants.
At the end of pass 2, the loader will transfer control to the loaded
program.
19
[ 4. Introduction, functions of loaders, Relocation and Linking concept, Different loading schemes : Relocating loader, Direct
Linking Loader, Dynamic Linking and loading. [ Hr - 8 ]
TXT CARD : When a TXT card is read, the text is copied from the card
to the appropriate relocate core location (PLA + ADDR).
RLD CARD : the value to be used for relocation and linking is extracted
from the local external symbol array as specified by the ID field, i.e.,
LESA(ID). Depending upon the flag setting ( plus or minus) the value is
either added to or subtracted from the address constant. The actual
relocated address of the address constant is computed as the sum of
the PLA and the ADDR field specified on the RLD card.
20
[ 4. Introduction, functions of loaders, Relocation and Linking concept, Different loading schemes : Relocating loader, Direct
Linking Loader, Dynamic Linking and loading. [ Hr - 8 ]
LDT /EOF CARD : The loader transfers control to the loaded program
at the address specified by current contents of the execution address
variable (EXADDR).
21
[ 4. Introduction, functions of loaders, Relocation and Linking concept, Different loading schemes : Relocating loader, Direct
Linking Loader, Dynamic Linking and loading. [ Hr - 8 ]
22
[ 4. Introduction, functions of loaders, Relocation and Linking concept, Different loading schemes : Relocating loader, Direct
Linking Loader, Dynamic Linking and loading. [ Hr - 8 ]
23
[ 4. Introduction, functions of loaders, Relocation and Linking concept, Different loading schemes : Relocating loader, Direct
Linking Loader, Dynamic Linking and loading. [ Hr - 8 ]
24
[ 4. Introduction, functions of loaders, Relocation and Linking concept, Different loading schemes : Relocating loader, Direct
Linking Loader, Dynamic Linking and loading. [ Hr - 8 ]
25
[ 4. Introduction, functions of loaders, Relocation and Linking concept, Different loading schemes : Relocating loader, Direct
Linking Loader, Dynamic Linking and loading. [ Hr - 8 ]
If all the subroutines are loaded simultaneously into the core, there
may be a chance that the core available might be insufficient for the
subroutines, which might lead to complication. Execution of such
program is possible, if all the segments are not required
simultaneously to be present in the memory. So the segments
needed are kept in memory, which is required at the time of
execution.
Keep the instructions and data in memory, that are needed at any
given time.
26
[ 4. Introduction, functions of loaders, Relocation and Linking concept, Different loading schemes : Relocating loader, Direct
Linking Loader, Dynamic Linking and loading. [ Hr - 8 ]
Advatage :
No wastage of memory.
It provides the ability to load the routines only when they are needed,
so lot of time and memory is saved if subroutines are large with lots of
external references.
27
[ 4. Introduction, functions of loaders, Relocation and Linking concept, Different loading schemes : Relocating loader, Direct
Linking Loader, Dynamic Linking and loading. [ Hr - 8 ]
Difference :
28