Linux Kernel Architecture

(Jacob Rumans) #1
Mauerer app03.tex V1 - 09/04/2008 6:11pm Page 1175

Notes on C


For more than 25 years, C has been the preferred programming language for implementing
operating systems of all kinds — including Linux. The major part of the kernel — with the
exception of a few assembly language segments — is programmed in C. Therefore, it is not possible
to understand the kernel without a mastery of C. This book assumes that you have already gained
sufficient experience with C in userspace programming. This appendix discusses little-used and
very specific aspects of C in kernel programming.

The kernel sources are especially designed for compilation with the GNU C compiler.^1 This com-
piler is available for many architectures (far more than are supported by the kernel) and also
features numerous enhancements used by the kernel, as discussed in this appendix.

C.1 How the GNU C Compiler Works


In addition to using GNU enhancements to the C language, the kernel also relies on a number of
optimizations performed by the compiler when it generates assembler code from the C sources.
Because very close cooperation between the sources and the compiler is necessary at some points
in the kernel, this section provides a brief overview of the actions performed by the GNU Compiler
Collection (GCC) when it compiles a program and of the various techniques used. The following
information is, of course, of a summary nature. For detailed information, refer to theGCC Internals
manual provided with the compiler sources and available online atgcc.gnu.org.

(^1) On IA-32 platforms, the proprietary compiler of Intel can also be used. It produces slightly better assembler code and makes
the kernel a fraction faster but does not provide the prime benefit of architecture independence. Because the Intel compiler
supports all GNU C enhancements used by the kernel, you do not need to modify the kernel code to support compilation
with the Intel compiler.

Free download pdf