Saturday, July 28, 2012

On linkers


Linker is a program that converts the object files into executables and shared libraries.

What a linker does? can be summarized into the following steps:
  • Parse options on the command line
  • Parse link scripts to read commands of linking
  • Symbol resolution
  • Relocation of instructions, data, symbols and sections
  • Output the linked file

Let's see the working of some existing linkers such as GNU ld, gold and MCLinker.

GNU ld
In the linking flow of GNU ld, the following steps are done iteratively:
  • Read and load the input files.
  • Do format checking.
  • Perform symbol resolution.
  • Apply relocation.

gold
gold separates the linking processes into two stages as follows:
  • stage 1: Do the following steps iteratively until all the files are read.
    • Read and load the input files.
    • Resolve symbols while checking the formats of the input files.
  • stage 2: Perform relocation in parallel.

MCLinker
MCLinker separated the linking processes into three stages as follows:
  • stage 1: Read and load input files. Check the formats.
  • stage 2: Symbol resolution.
  • stage 3: Perform relocation.

Click here for the reference of the above discussed linkers.
Click here for the what and how of linkers by Ian Lance Taylor.

No comments: