What exactly is relocatable code? How is it implemented?
Relocatable code means code that can sit anywhere in main memory. The main memory address is not hard-coded into the program when it is compiled and resides on the disk. The program uses only relative addresses, for example, with reference to the beginning of the program. When you ask for the program to be run, a part of the OS (called the dispatcher or loader) decides where in main memory the process will run now, and the relative addresses get interpreted accordingly. The details of this process vary according to the OS and the memory management scheme. Some of this will be clear when we study processes under Unix.