Previous | Table of Contents | Next |
The compiler has now determined the exact instructions, the order of the instructions, and the layout of data. The only four jobs left to do are generate the object, assembly, error, and listing files. These are clerical jobs. This does not minimize their difficulty or importance. There is little theory applicable to these tasks.
To understand the generation of object files, remember the four different concepts of time that the compiler must understand. Events that happen during compile time are events that happen within the compileranalyzing the program and generating output that will be used to create the program. Events that happen at link time are operations that happen while the linker is running. This includes the layout of the executable program and the modification of some addresses to represent the actual locations in memory rather than the relative addresses specified by the compiler. There is a tight correlation between some link-time operations and compile-time operations. The compiler must create a collection of commands to specify the operations that the linker must perform to create the image. The creation of the commands is a compile-time operation; the execution of the commands is a link-time operation.
For completeness, there are two more time intervals: load time and run time. Operations that happen at load time include further relocation of relative addresses and setting the addresses of shared libraries. Load-time operations are the execution of commands that are left in the executable image created by the linker. Thus load-time operations are execution of commands created at link time, which further are the effects of commands created at compile time. Finally, runtime operations are the processes that occur during the execution of the program. Although all instructions are executed at run time, the term usually refers to the creation of data structures, such as the static nesting stack, that are maintained at run time.
As you can see, all of these processes are controlled by commands created by the compiler at compile time and inserted into an output file called the object file or object module.
The object module is a collection of commands to the linker describing how data must be stored in memory and how that data must be modified when the data is placed in one position rather than another. Consider a particular procedure such as the running example we have used throughout the book, MAXCOL. This procedure consists of a contiguous sequence of numbers representing the instructions in the procedure, a set of data representing the storage locations for data in the procedure, and a set of storage locations holding the constants that require more storage than the immediate field of the instructions.
The compiler knows the relative locations of the instructions in the procedure; however, it does not know the absolute locations since it has no knowledge of the other procedures and data that will be loaded with this one. Hence the compiler cannot determine the absolute locations for instructions or data; it can only determine the relative locations with respect to the other instructions and data in the procedure. If required to do so, the linker must adjust the addresses created by the compiler to be absolute addresses rather than the relative addresses created by the compiler.1 This process is called relocation.
1Some instructions represent addresses as offsets from the current program counter. In this case the linker does not need to adjust the addresses. Many processors have a set of relative branches together with the absolute jump instruction.
To represent contiguous sequences of numbers, either instructions or data, the object module has the concept of a section of data. A section of data consists of the following parts.
Previous | Table of Contents | Next |