Unit-I SSOS Notes
Unit-I SSOS Notes
4054 END A
LIST B
END B
4112 LIST C
END C
REF1
REF1
REF2
REF3
Example-Contd
REF6
REF7
REF8
• The above example contain ProgA,ProgB and
ProgC.
• It contain ListA,ListB,ListC and each list end
with endA,endB and endC.
• Program contain references REF1 to REF8.
• For example ref4 is linked in following way.
Example-Contd
• Ref4 EndA-ListA+ListC
• 4054-4040+4112
= 41126
Algorithm and Data Structures for a
Linking Loader
Data Structure
• The main data structure needed for linking
loader is external symbol table.
• It store name and address of each external
symbols in control section.
• It contain two variables
• PROGADDR:It is beginning address in memory
where the linked program is to be loaded.
• CSADDR –Starting address of control section.
Algorithm
• There are two passes in linking loader
• Pass-I and Pass-II
• Pass-I
• In Pass-I all external symbols are stored in
ESTAB with address.
Algorithm for Pass 1 of a linking
loader:
Begin
get PROOADDR from operating system
set CSADDR to PROOADDR {for first control section}
while not end of input do
begin
read next input record {Header record for control section}
set CSLTH to control section length
search ESTAB for control section name
if found then
set error flag {duplicate external symbol}
else
enter control section name into ESTAB with value CSADDR
while record type ~ 'E' do
begin
read next input record
if record type = 'D' then
for each symbol in the record do
begin
search ESTAB for symbol name
if found then
set error flag (duplicate external symbol)
else
enter symbol into ESTAB with value(CSADDR + indicated address)
end {for}
end {while ~ 'E'}
add CSLTH to CSADDR {starting address for next control section}
end {while not EOF}
end {Pass 1}
Pass-II
• Pass-II of loader performs the actual loading
,relocation and linking of the program.
• In this when each text record is read , the
object code is moved to specified address.
• When a modification record is found then it is
verified in ESTAB.Then relocation is
performed.
• In last step loader transfer of control to the
loaded program to begin execution.
Algorithm
Begin
set CSADDR to PROOADDR
set EXECADDR to PROOADDR
while not end of input do
begin
read next input record {Header record}
set CSLTH to control section length
while record type != 'E' do
begin
read next input record
if record type = 'T' then -~
begin
{if object code is in character form, convert
into internal representation}
move object code from record to location
(CSADDR + specified address)
end {if 'T'}
else if record type = 'M' then
begin
search ESTAB for modifying symbol name
if found then
add or subtract symbol value at location
(CSADDR + specified address)
Else
set error flag (undefined external symbol )
end {if 'M' }
end {while != 'E'}
if an address is specified {in End record} then
set EXECADDR to (CSADDR + specified address)
add CSLTH to CSADDR
end {while not EOF}
jump to location given by EXECADDR {to start execution of
loadedprogram)
end {Pass 2}
Machine Independent Loader Features
• Machine independent loader feature include
1. Automatic Library search
2. Loader options
Automatic Library search
• The subroutines called by the program being
loaded are automatically fetched from the
library linked with the main program and
loaded.
• This feature is referred as a automatic library
call or library search.
• Linking loaders that support automatic library
search must keep track of external symbols
that are refered.
• For example SQRT function automatically
included via the library search function.
Automatic Library search
• The libraries contain assembled or compiled
versions of the subroutines.
• The library contain special structure that
contains a directory that gives the name of
subroutine and its address.
• When subroutine is called search the directory
and move to the corresponding address .
• Then object code of subroutine is loaded.
• In some operating system commonly used
libraries are permanently stored in memory.
Loader Options
• Many loaders have a special command language
that is used to specify options.
• (i) INCLUDE
• Syntax
• INCLUDE prog-name(library name)
• Direct the loader to read the designated object
program from a library.
• DELETE
• Syntax
• DELETE csect-name;
• Delete the external symbols or entire control
sections.
Loader Options
• CHANGE
• Syntax
• CHANGE name1,name2
• External symbol name1 to be changed name2;
• Example
• Include read(utlib)
• Include write(utlib)
• Delete rerec,wrrec
• Change rdrec,read
• Change wrrec,write
Example
• In the above example include control sections Read
and Write from the library UTLIB.
• It also delete the control sections RDREC and WRREC
from the load.
• Then Change the Symbol RDREC to Read and WRREC to
Write.
• LIBRAARY
• Most loaders allow the user to specify alternative
libraries to be searched.
• Ex:
• Library Mylib
• Statistical analysis performed the following conditions
• NOCALL, STDDEV,PLOT,CORREL
Loader Design Options
• Loader Design options include
1. Linkage Editors
2. Dynamic Linking
3. Bootstrap Loaders
Linkage editor
• Linkage editors perform linking prior to load
time.
• The below diagram shows the difference
between linkage loader and linkage editor
Linkage loader
• Linkage loader executed in following way
1. The source program is assembled or
compiled to produce an object program.
2. A linkage loader performs all linking and
relocation operations including automatic
library search if specified.
3. Load the linked program directly into
memory for execution.
Linkage Editor
• Linkage editor executed in following way
1. The source program is assembled or compiled to
produce an object program.
2. Linkage editor perform linking and produce a linked
version of program called load module or executable
image.
3. When user ready to run linked program, simple
relocating loader can be used to load the program
into memory.
4. In linkage editor program is executed in many times
without being reassembled. So linkage editor reduce
the overhead.
Example
Include planner(proglib)
Delete project
Include project(newlib)
Replace planner(proglib)
• Program planner uses large number of subroutines.
One of the subroutine is project.
• If subroutine project is changed then linkage editor
delete the old version of project and add the new
version of project into linked version of project.
• It is not necessary to go back original version of
program.
Dynamic Linking
• Linkage editor perform linking operation before the
program is loaded for execution.
• In dynamic linking subroutine is loaded and linked to the
program when it is first called.It is also called dynamic
loading or load on call.
• In dynamic linking several executing programs share one
copy of subroutine or library.
• In C dynamic link library is linked.
• Dynamic linking provides the ability to load the routines
only when they are needed. It save the time and memory.
• Dynamic linking avoids the necessity of loading the entire
library for each execution. Only necessary subroutine only
loaded.
Example of Dynamic Linking
[a] : Dynamic loader is part of operating
system.It is called from user program.
[b] : The OS examines internal tables to
determine whether or not routine is already
loaded.If necessary then routine is loaded
from system library.
Example of Dynamic Linking
[c] : Control is transferred from OS to the routine
being called.
[d]:When the subroutine completes its processing ,
it return to the OS then OS returns the control to
the program that issued the request.
[e]: After the subroutine is completed the memory
allocated was released and used for other
purpose.The subroutine is in memory as long as
memory is needed for other processing.
Delayed Binding
• Association of an actual address with the
symbolic name of the called routine is not
made until call statement is executed. This is
known as delayed binding.It provide flexibility.
Bootstrap Loaders
• Absolute loader program load the programs into memory.
• Absolute loader program is stored in ROM.
• Some computer program is directly executed from
rom.Some computer it is copied from ROM to main
memory and executed there.
• Another way is bootstrap loader.It read fixed length of
record from device.
• After read operation is complete control is transferred to
memory where instruction stored.
• If loading process requires more instructions then it read
first record and then first record read second and so on.
• The first record is refered as bootstrap loader.