Originally called linkage editors by IBM.
This is an example of a utility program included with an operating system distribution. Like a compiler, it is not part of the operating system per se, i.e. it does not run in supervisor mode. Unlike a compiler it is OS dependent (what object/load file format is used) and is not (normally) language dependent.
Link of course.
When the assembler has finished it produces an object module that is almost runnable. There are two primary problems that must be solved for the object module to be runnable. Both are involved with linking (that word, again) together multiple object modules. They are relocating relative addresses and resolving external references.
The output of a linker is called a load module because it is now ready to be loaded and run.
To see how a linker works lets consider the following example, which is the first dataset from lab #1. The description in lab1 is more detailed.
The target machine is word addressable and has a memory of 1000 words, each consisting of 4 decimal digits. The first (leftmost) digit is the opcode and the remaining three digits form an address.
Each object module contains three parts, a definition list, a use list, and the program text itself. Each definition is a pair (sym, loc). Each use is a pair (sym, loc). The address in loc points to the next use or is 888 to end the chain.
For those text entries that do not form part of a use chain a fifth (leftmost) digit is added.
Input set #1 1 xy 2 1 z 4 5 31004 15678 2888 38002 7002 0 1 z 3 6 38001 1888 1001 3002 31002 21010 0 1 z 1 2 35001 4888 1 z 2 1 xy 2 3 28000 1888 2001
The first pass simply produces the symbol table giving the values for xy and z (2 and 15 respectively). The second pass does the real work (using the values in the symbol table).
(Unofficial) Remark: It is faster (less I/O) to do a one pass approach, but is harder since you need ``fix-up code'' whenever a use occurs in a module that precedes the module with the definition.
Symbol Table xy=2 z=15 .ft CO +0 0: 31004 1004+0 = 1004 1: 15678 5678 2: xy: 2888 ->z 2015 3: 38002 8002+0 = 8002 4: ->z 7002 7015 +5 0 38001 8001+5 = 8006 1 1888 ->z 1015 2 1001 ->z 1015 3 ->z 3002 3015 4 31002 1002+5 = 1007 5 21010 1010 +11 0 35001 5001+11= 5012 1 ->z 4888 4015 +13 0 28000 8000 1 1888 ->xy 1002 2 z:->xy 2001 2002
The linker on unix is mistakenly called ld (for loader), which is unfortunate since it links but does not load.
Lab #1: Implement a linker. The specific assignment is detailed on the sheet handed out in in class and is due 7 February. The content of the handout is available on the web as well (see the class home page).