• edited by
3,864 views
1 1 vote

Differentiate the Relocation Activities done by

  1. Linker
  2. Loader

In light with the following senario,
 

Imagine I have written a program P and it consists of two source modules M1 and M2 contained in two different files
situation 1 : In M1 there is a reference to a function in M2 .
situation 2 : In M2 there is a reference to printf()
Among the two Which situation is  resolved during   the load time and link time ?
( if any of these situation is not resolved in load time then ) what is the relocation activity done by loader ...?

1 Answer

Best answer
9 9 votes

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$ :

  1. Segments (modules) merge and symbol table resolution.
  2. 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.

• selected by
Position:
Show:

Related questions

0 0 votes
1 1 answer
5.2k
5.2k views
go_editor asked Mar 27, 2020
5,209 views
Which statement is wrong If linked origin $\neq$ translated origin, relocation must be performed by the linkerIf load $\neq$ linked origin, the loader must perform reloca...
1 1 vote
0 0 answers
520
520 views
iarnav asked Aug 25, 2018
520 views
Please explain Dynamic linking and Dynamic Libraries in an intuitive way with an example.
0 0 votes
1 1 answer
628
628 views
Na462 asked Jul 1, 2018
628 views
Compare Following Points between Static and Dynamic Linking :- 1. Program Startup.2. Overall Page Fault Rate.