15. Completion and Futures

Previous Table of Contents Next


Chapter 14
The Object Module

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 compiler—analyzing 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.

14.1 What Is the 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.

  Each section has a unique name. Two sections that have the same name are either concatenated together or overlaid by the linker. Thus multiple object modules can contribute to the same section by using the same name. Similarly, separate parts of the same object module can contribute to the same section.
  Each section has a set of attributes. The most important attribute is whether this section involves concatenation of data from separate section commands or overlaying of data from separate section commands. Other attributes include the read and write attributes of the section. The object module can specify that a particular section can be read-only or read-write. This information can be used by the operating system to invoke page protection when possible.
  Each segment has an alignment. Since some data must begin at an address that is a multiple of some specified power of two, the segment command must allow the compiler to describe the multiple of two on which this portion of the segment must begin. This allows the compiler to allocate packets of instructions for multiple issue or data that must be aligned at specified addresses.
  Each section command indicates a size. This is the number of bytes of memory (or whatever memory units are used) to be allocated by this section command.
  The section may have data stored in the storage represented by this section command. Frequently this data will be instructions; however, it can be data or constants.
  Each section contains a collection of other commands, which will be specified below, for performing relocation on the data in the section and storing information about important locations in the section.


Previous Table of Contents Next


Building an Optimizing Compiler
Building an Optimizing Compiler
ISBN: 155558179X
EAN: 2147483647
Year: 1997
Pages: 18
Authors: Bob Morgan

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net