Operating Systems

 

• The preprocessor evaluates a specific set of commands starting with a #. The most important of these commands is used to include other code files (header files) or to define macros that might be used inside the code to avoid duplication. After this step, all the # commands have been removed from the input together with all the comments. If there are no options specified that force GCC to sustain the preprocessor output as a file (e.g., -E or --save-temps), the preprocessing step will occur as an integral part of the source code parsing without ever creating the intermediate .i files.

• The compiler translates a source code file into the architecture-specific assembler language. This step involves parsing and optimizing the code.

• The assembler takes an assembler language file as input and translates it into an ELF object file. Although the GNU Binutils are built to be able to deal with a wide range of different object file formats, only ELF (the most flexible one) is supported on Linux for System z.

• The linker finally takes one or more object files and turns them into either an executable file or shared library. The linker must locate the libraries and ensure that every necessary symbol can be found in one of the involved object files.

The GCC package provides an executable named gcc (the so-called compile driver), the command the user usually calls to start compilation. This driver then calls all other tools, handles intermediate files, and passes all necessary options. The real compiler executables are named cc1 for C and cc1plus for C++. Both are part of the GCC package and are usually invoked by the driver. The GNU assembler (as) and the GNU linker (ld) are distributed as part of the GNU Binutils suite.

Appending the -v option to the gcc command causes the driver to print all the commands it executes. For more on using GCC, visit the GCC homepage: www.gnu.org/software/gcc/gcc.html. The GCC manual also is included in most Linux distributions.

The ELF Binary Object Format

The ELF is the most important object file format used in the UNIX and Linux worlds. First published in the System V application binary interface specification, it later became part of the tool interface standard. A major advantage over other formats is that it can be easily extended without breaking compatibility with older systems.

An ELF file provides two different views to cover different needs at compile time and run-time:

6 Pages