2.4 Compilers, linkers and loaders

A compiler is a translator that translates the source code of a HLPL to “object code”. Object code is essentially machine code that has unknowns to be filled in. In other words, a compiler takes the source code of a HLPL as input, and outputs instructions to be executed by a CPU. However, the instructions may have certain “blanks to be filled”, which typically corresponds to locations of subroutines and variables that are defined by other source files.

A linker takes object code files from different source files and resolves the “blanks to be filled”. The output of a linker is an executable file that can be loaded by the loader of an operating system into RAM. After that, the operating system can start the execution of the program.

A loader is a component of an operating system that reads an executable file. It also allocates memory in a computer, and initializes the memory locations for code and data. A loader can also do the last adjustment of location addresses depending on which part of memory a program is loaded.

This is because an executable file assumes location 0 is the beginning of the data and code space. However, when a program is loaded, the memory space allocated by an OS is unlikely to be location 0.