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.
For example, consider a program written in C language such a program may contain calls to functions like printf( ). During program execution main program calls the function
1) The linking process makes address of modules known to each other so that transfer of control takes place.
2) Passing of parameters is handled by the linker.
3) An external variable can be defined in one module and can be used in another module.
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.
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.
Self Relocating ProgramEdit
Q. Explain self relocating programs. ----- 4 m
Program relocatibility refers to the ability to load and execute a given program into an arbitrary place in memory as opposed to a fixed set of locations specified at program translation time depending on how and when the mapping from virtual address space to the physical address space takes place in given relocation: (a) Static (b) Dynamic .
A self relocating program is a program which can perform the relocation itself. Self relocating program contain the relocating logic, so no need of a linker in that.
Static and Dynamic Link LibrariesEdit
Static linking: -
A static linker takes object files produced by the compiler including library functions and produces and executable file. The executable file contains a copy of every subroutine (user defined or library function.) The biggest disadvantage of the static linking is that each executable file contains its own copy of the library routines. If many programs containing same library routines are executed then memory is wasted.
Dynamic Linking: -
Dynamic linking defers much of the linking process until a program starts running. Dynamic linking involves the following steps:
1) A reference to an external module during run time causes the loader to find the target module and load it.
2) Perform relocation during run time
Dynamic linking permits a program to load and unload routines at run time.