This preview shows page 1. Sign up to view the full content.
Unformatted text preview: of the operating system, the ISA, or the object ﬁle format. Details may vary, but the concepts are the same. 7.1 Compiler Drivers
Consider the C program in Figure 7.1. It consists of two source ﬁles, main.c and swap.c. Function main() calls swap, which swaps the two elements in the external global array buf. Granted, this is a strange way to swap two numbers, but it will serve as a small running example throughout this chapter that will allow us to make some important points about how linking works. Most compilation systems provide a compiler driver that invokes the language preprocessor, compiler, assembler, and linker, as needed on behalf of the user. For example, to build the example program using the GNU compilation system, we might invoke the GCC driver by typing the following command to the shell:
unix> gcc -O2 -g -o p main.c swap.c Figure 7.2 summarizes the activities of the driver as it translates the example program from an ASCII source ﬁle into an executable object ﬁle. (If you want to see these steps for yourself, run GCC with the -v option.) The driver ﬁrst runs the C prepro...
View Full Document