Spos Unit 3 PPT 2022 - Compressed
Spos Unit 3 PPT 2022 - Compressed
Prepared By
Prof. Anand N. Gharu
(Assistant Professor)
PVGCOE Computer Dept.
2/16/2022 3
2/16/2022 4
object code, or an object file, is the
representation of code that a compiler or
assembler generates by processing a source
code file.
A linker is typically used to generate an
executable file by linking object files together.
Object files often also contain data for use by the
code at runtime, relocation information,
program symbols (names of variables and
functions) for linking and/or debugging purposes,
and other debugging information.
2/16/2022 5
In MS-DOS, Windows 95/98 etc object
modules have extension .obj and the
executable binary programs have .exe
extension. In UNIX, object modules have .o
extension and executable programs have no
extens
2/16/2022 6
ALLOCATION: Allocates space in memory for the
programs( calculation program size)
2/16/2022 8
Loader is utility program which takes object
code as input prepares it for execution and
loads the executable code into the memory.
2/16/2022 9
Relocation and linking concepts
2/16/2022 10
User defined function and library funtion
Example-printf() ,scanf()
The linking process makes address of modules known to
each other so that transfer of control takes place during
execution.
Passing of parameter is handled by the linker.
Public variable-same address
External variable –defined in one module and used in another
module.
Resolving of addresses of symbolic reference is handled by the
linker.
2/16/2022 11
Linker-
1.Handled the passing of parameter
2.Resolving of address of symbolic reference
2/16/2022 12
It is the process of modifying the addresses used
in the address sensitive instructions of a program
So, program Can execute correctly from any
designated area of memory.
Ex. MOVER AREG,X
Ex.:-Program A, call function F1();
Program A and F1() must be linked with each
other.
2/16/2022 13
Case I: Address assigned to Prog. A and F1 () when they translated to
memory 0
400
F1
500
Fig.: General Loading scheme
2/16/2022 14
Case II: These two module cannot co-exist at same storage locations.
Main
Storage
0
100 150
A
A
250 151
F1
100
251
F1
200
Relocated address given
Translation time by the loader
address
Fig.: Relocation to avoid address conflict or storage waste
2/16/2022 15
A loader must relocate A and F1 to avoid address
conflict or storage waste.
Relocation refers to adjustment of address field
not to movement of a program.
2/16/2022 16
Various types of loader ,based on various functionalities
1. Compile and go loader
2. General loader scheme
3. Absolute loader
4. subroutine linkage
5. Relocating loader
6. Direct linking loader
2/16/2022 17
Performing the loader function is to have the
assembler run in one part of memory and
place the assembled machine instructions
and data, as they are assembled,direcltly into
their assigned memory location.
Diagram.
Also called “assemble and go”
2/16/2022 18
1. COMPILE AND GO LOADER
Advantages:
It is very simple to understand.
2/16/2022 20
Portion of the memory is wasted because the assembler
resides in the memory.
It is necessary to assemble every time even though no
modifications are being done.
Can not handle multiple program segments especially if
they are written in different languages (e.g. assembly
lang. and FORTRAN or PL/I)
Scheme is good for small program not for bigger one
Execution time = assemble time + load time
2/16/2022 21
Program modules A and B are loaded in memory after linking. It is
ready for execution
Object
Module
A
A
Loader
B
Object
Module
B
2/16/2022 26
Advantages:
Simple, easy to design and implement
Since more core memory is available the user, as an
assembler is not memory at load time.
No linking or relocation is efficient.
Execution time = load time
2/16/2022 27
Disadvantages:
• Programmer must specify the starting address to the assembler for
the program where it should be loaded.
•so programmer must know memory management as well as memory
status at any time.
•It is very difficult to relocate in case of multiple subroutine.
2/16/2022 28
• In absolute loader 4 loader function are
performed by,
Allocation: by programmer
Linking: by programmer
Relocation: by assembler
Loading-by loader
2/16/2022 29
4. SUBROUTINE LINKAGE
5. RELOCATING LOADER
Subroutine: In given program ,it is often
needed to perform a particular subtask many
times on different data values. such a
subtask is usually called a subroutine.
Subroutine linkage method: The way in
which a machine makes it possible to call and
return from subroutine is referred to as its
Subroutine linkage method
2/16/2022 32
Subroutine Linkage: Instructions
There are two forms of the Branch and Link
instruction.
BAL Branch and Link
BALR Branch and Link, Register.
2/16/2022 33
Calling the subroutine
The format of the instruction is BAL
Reg,Address
An example of such an instruction is BAL
8,P10PAGE
2/16/2022 34
MAIN START
SUBROUT START
EXTRN SUBROUT
USING *,15
-------------
-------------
--------------
--------------
L 15,=A(SUBROUT)
BR 14
BALR 14,15
END
….
…..
END
2/16/2022 35
5. RELOCATING LOADER
Relocation is the process of modifying the address used by program such that
program can execute correctly.
E.g. assume that a program A calls a function F1. The program A and the
function F1 must be linked with each other. But where we have to load in main
storage? A possible solution would be to load them according to address
assigned when they were translated.
Case (I) At the time of translation A has been given storage area from 100 to
250 while F occupies area between 400 to 500. If we were to load these
programs at their translated address , a lot of storage will be wasted.
5. RELOCATING LOADER
Case (II) at the time of translated, both A and F1 may have been translated
with the identical start address 100. A goes from 100 to 250 and F1 goes
from 100 to 200. These two modules cannot co-exist at same. The linker
must relocate A and F1 to avoid address conflict or storage waste A possible
relocation is shown in figure.
It may be noted that relocation more than simply moving a program from one are to
another in the storage. It refers to adjustment of address fields and not to movement of a
program.
Relocation bits are used to solve the problem
of relocation.
Transfer vector is used to solve the problem
of linking & Program length info to solve
allocation.
2/16/2022 38
No suited for loading external data.
Transfer vector increase the size.
Does not facilitate access to data segment
that can be shared.
2/16/2022 39
6. DIRECT LINKING LOADER
It is type of Re-locatable Loader.
It is most common type of loader.
It allows the programmer to use multiple
procedure segments and multiple data
segments.
The assembler should give the following
information to the loader:
1.The length of the object code segment.
2.A list of all symbols which are not defined in the
current segment but can be used in the current
2/16/2022 42
3.A list of all symbols which are defined in the
current segment but can be referred in the
current segment.
4.Information about address constants.
5.Machine code translation of the source program
and relative address.
To place the object code in the memory there
are two situations:1. Address of the object code
could be absolute.2. The address of object code
can be relative.
2/16/2022 43
The list of symbols not defined in the current
segment but used in the current segment are
stored in a data structure called USE table.
The lists of symbols defined in the current
segment and referred by the other segments
are stored in a data structure called
DEFINITION table.
2/16/2022 44
Assembler generates 4 types of cards in the
object desk:
ESD:External Symbol Dictionary (ESD) record:
TXT: (TXT) records.
RLD: Relocation and Linkage Directory (RLD):
END :End of object deck
2/16/2022 45
1.ESD:External Symbol Dictionary (ESD) record:
Card contain information about all symbol that are
defined in this program, but that may reference
elsewhere, and all symbol referenced in this
program but defined elsewhere.
Source object symbol Type Relative Length
record Location
no./card no.
1 MAIN SD 0 36
2 RESULT LD 32 -
3 2/16/2022
SUM ER - - 46
Type:
SD: segment definition: symbol in segment
LD: Local definition: symbol is defined in this
program but it can be referenced by other
program.
ER: External symbol: defined in some external
program.
2/16/2022 47
2. TXT: (TEXT) records.
Text card contains actual object code.(translated
source code).
Source object Relative Location Object code
record no.
1 0
2 32
3 -
2/16/2022 48
3. RLD: Relocation and Linkage Directory (RLD):
Card contain information about those locations in
the program whose content depend on the
address at which the program is placed
Source ESD_ID Length(in Flag + or - Relative
object Byte) address
record no.
2/16/2022 50
Allow multiple procedure and data segment.
Allow independent translation of the program.
Relocation Faclility
2/16/2022 51
Not suitable in multitasking.
It is necessary to allocate, relocate, link, and
load all of the subroutines each time in order
to execute a program
loading process can be extremely time
consuming.
2/16/2022 52
Design of direct linking loader is more complicated
than absolute loader.
Input to loader is object module and this is divide into
4 section 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, relocation and
linking.
2/16/2022 53
In Pass I ,a Global External Symbol table(GEST) is
prepared.
It contain every external symbol and corresponding
absolute address value.
2/16/2022 54
Copy of
Object object
Module records
Pass I Pass II
Main
Memory
Object GEST
Module
2/16/2022 55
Write entries of ESD,TXT,RLD,& Global
External Symbol Table(GEST) for PG1,PG2
given below
2/16/2022 56
Object Relative Source
Record Address Program
no.
1. 0 PG1 START
2. ENTRY PG1EN1,PG1EN2
3. EXTRN PG2EN1, PG2
4. 20 PG1EN1 =
5. 30 PG1EN2 =
6. 40 DC A (PG1EN1)
7. 44 DC A (PG1EN2+15)
8. 48 DC A (PG1EN2-PG1EN1-3)
9. 52 DC A (PG2)
10. 56 DC A
2/16/2022
(PG2EN1+PG1EN1+4) 57
Object Relative Source
Record Address Program
no.
12. 0 PG2 START
15. 16 PG2EN1 =
16. 24 DC A (PG1EN1)
17. 28 DC A (PG1EN2+15)
18. 32 DC A (PG1EN2-
PG1EN1-3)
19. 36 END
2/16/2022 58
Source Name Type ID Relative length
object Address
record
no.
1. PG1 SD 01 0 60
2. PG1EN1 LD - 20
3. PG1EN2 LD - 30
4. PG2 ER 02 -
5. PG2EN1 ER 03 -
2/16/2022 59
SD: Segment definition
LD: Local definition (declared in this seg, can
be used by others)
ER: External definition (declared in other , can
be used by this)
Each SD and ER symbol is given unique
numeber which is to used in RLD
2/16/2022 60
Source Relative Contents Comments
object Address
record no.
2/16/2022 61
Source ESD_ID Length(in Flag + or - Relative
object Byte) Address
record
no.
6 01 4 + 40
7 01 4 + 44
9 02 4 + 52
10 03 4 + 56
10 02 4 + 56
10
2/16/2022 01 4 - 56 62
Source Name Type ID Relative length
object Address
record
no.
12. PG2 SD 01 0 36
13. PG2ENT1 LD - 16 -
14 PG1EN1 ER 02 - -
14 PG1ENT2 ER 03 - -
2/16/2022 63
Source object Relative Address Contents
record no.
16 24-27 0
17 28-31 15
18 32-35 -3
2/16/2022 64
Source ESD_ID Length(in Flag + or - Relative
object Byte) Address
record
no.
16 02 4 + 24
17 03 4 + 28
18 03 4 + 32
18 02 4 - 32
2/16/2022 65
Contain external symbol and its corresponding
address.
If we assume that PG2 is loaded at location 268.
External Symbol Assigned Memory Address
PG1 208
PG1ENT1 228
PG1ENT2 238
PG2 268
PG2ENT1 284
2/16/2022 66
LESA is created for each segment.it contains
SD & LD type entries of each segment.
Assigned Memory
LESA for PG1 Address
PG1 208
PG1ENT1 228
PG1ENT2 238
LESA for PG2
Assigned Memory
Address
PG2 268
PG2ENT1 284
2/16/2022 67
OVERLAY STRUCTURE
• Program execution need not be achieved by loading all the
parts of large program in memory.
• So,that we can reduce memory requirement of such program
by loading required parts of program in memory.
• Hence some parts of program are given the same load
address during linking.
• Therefore,at any time,only one of these parts of program can
be loaded in memory because loading of other parts that has
same load address will overwrite it.
2/16/2022 68
OVERLAY STRUCTURE
• Note that procedures B and D are never in used the same time;
neither are C and E.
2/16/2022 70
OVERLAY STRUCTURE
2/16/2022 71
What is linker? Why program relocation is required and
how is it performed?
Any usable program written in any language has to use functions /
subroutines. These functions could be either user defined functions
or they can be library functions.
2 It uses an input of object code produced It uses an input of executable files produced
by the assembler and compiler. by the linker.
4 Linker is used to join all the modules. Loader is used to allocate the address to
executable files.
5 It is accountable for managing objects in It is accountable for setting up references
the program’s space. that are utilized in the program.
STATIC & DYNAMIC LINK LIBRARIES
STATIC & DYNAMIC LINK LIBRARIES
DYNAMIC LINK LIBRARIES
CALLBACK FUNCTION
COMPARE CALLBACK &
NORMAL FUNCTION
THANK YOU!!!
My Blog : https://anandgharu.wordpress.com/
Email : [email protected]