
Linking 23
Most object files begin with a header that describes the sections that follow. Each
of these sections contains one or more blocks of code or data that originated
within the original source file. However, these blocks have been regrouped by the
compiler into related sections. For example, all of the code blocks are collected
into a section called text, initialized global variables (and their initial values) into
a section called data, and uninitialized global variables into a section called bss.
There is also usually a symbol table somewhere in the object file that contains the
names and locations of all the variables and functions referenced within the source
file. Parts of this table may be incomplete, however, because not all of the vari-
ables and functions are always defined in the same file. These are the symbols that
refer to variables and functions defined in other source files. And it is up to the
linker to resolve such unresolved references.
Linking
All of the object files resulting from step one must be combined in a special way
before the program can be executed. The object files themselves are individually
incomplete, most notably in that some of the internal variable and function refer-
ences have not yet been resolved. The job of the linker is to combine these object
files and, in the process, to resolve all of the unresolved symbols.
The output of the linker is a new