During Compile time, we assign addresses starting from $0$ to processes, and later they have to be changed to absolute address using relocation information. An object code contains :
- Header ( pointer to all other entries in object code )
- Text Segment ( all instructions, code)
- Data Segment ( Data part like constants)
- Relocation Information ( Info about relocatable addresses)
- Symbol Table ( contains all symbols ex. variables, functions and address of these)
- Debugging Info. ( other information useful for debugging)
And A linker goes through $2-passes$ :
- Segments (modules) merge and symbol table resolution.
- Replacing stub code. (stub code is a pointer to the location of functions we are provided with like printf(), scanf() )
Situation 1: Suppose $2-modules$ $M_{1}$ and $M_{2}$ are present as object code. So, Linker takes both of these modules to generate the final object code(RA of two individual modules $\rightarrow$ RA final object code). So, Linker does this job.
Situation 2: In first pass of linker a symbol table resolution is done as a result of which the final object code replaces the user defined functions with their code, whereas a stub/glue code is kept for functions like printf(), so that later when program runs stub/glue code will execute and concern OS. So, in second pass of Linker the stub/glue code will be replaced by address where MM contains printf(). Again, Linker does this job.
Loader here converts Relocatable Address (final object code) to Absolute address/Load address when a program is loaded into main memory.