Professional Documents
Culture Documents
05linking and Loading
05linking and Loading
05linking and Loading
The linker resolves all external references and produces integrated object code:
absolute load module
Programs that perform the above functions are called by various names like:
1) Linker
2) Loader
3) Linking loader
The Linking Editor
Each module
has its own
address
space.
P, Q, R, S, X
are registers
Linker Action
Step 1: Construct table of all object modules, their lengths, start address
Step II: Calculate the new addresses of labels, and symbols referring to memory
Find all instructions in a module containing memory address.
Add a relocation constant to take into account the new start address of the module to
each
Linker Action
Step III: Find addresses of external references and link them
1806
Module Old New
Module D
A BRANCH TO 200 BRANCH T0 200
1505
MOVE P TO X MOVE P TO X
1504
CALL B CALL 401
Module C
B BRANCH TO 300 BRANCH TO 702
1003
MOVE Q TO X MOVE Q TO X
1002
CALL C CALL 1003
Loading Options
Ask the Operating System to supply a block of memory of required size and
load in the specified block
Adjust virtual addresses with respect to start address of memory block
Base register
Paging
Use page start address
The Loader
Loader
Action of P1
The first JSRI causes transfer to DL
Call P2 becomes
The second JSR is executed to call P2 JSRI LS
JSRI LS
Static Vs Dynamic Linking
Static linking: linker copies all external routines used in the program into the load
module.
Disadvantages
• more disk space and memory: same routine copied in the several programs that
use them
• programs to be recompiled if the external routines change
Advantages
Dynamic linking: place the name of external routines in the load module
Disadvantage
Advantages