Linking & Loading for the Uninitiated

I started to write a few notes on the function of loaders, which are magic to many programmers, and discovered that there was no good place to start. The very workings of computers is assumed to be well known but can hardly be found on the web. IBM’s 360 and 370 manuals had excellent introductions describing what it meant to fetch and execute a computer instruction. It did not assume that you had ever heard of a computer before. Alas they are no longer on the web and they are out of print.

So here you will find some stuff that you might have been embarrassed to ask—it is part of the oral tradition.

Here is an introduction to the very notion of address and the role it plays in computer logic. Here is some history of these ideas.

Sun’s Linking and Loading manual is a good description of the operations that are performed in the process of loading a program. It assumes many kinds of background information without reference to sources where that information can be found. If you already know what a loader is for then you can understand that manual.

The original purpose of the linkers and loaders is to prepare an address spaces by placing the program in the space so that it can begin execution. As a program begins it will assume that its various parts have already been placed at addresses that were of no immediate concern as the program was written. Programs are typically composed of several, perhaps many, independently compiled sub programs. Those sub programs were independently compiled and the compiler, or assembler was not in a position to know what addresses the program would occupy in memory because it was not known at that time what other programs would share memory. The compiler would be aware of relative differences of instructions but not the absolute addresses. A format for the compiled code was invented to allow the compiler to produce code that merely required the loader or linker to add the location of the program, once it was known, to each field in the program that referred to another part of the same program. When a programmer defined symbol was defined in one program and referred to in another then this file format included that name and enough information for the linker to discover the definition and provide that to the refferer.

Much more later.