Linux Kernel Architecture

(Jacob Rumans) #1
Mauerer runapp02.tex V2 - 09/04/2008 6:09pm Page 1160

Appendix B: Working with the Source Code


Kbuild links all the object files of a directory that are contained in the targetobj-yinto an overall object
filebuilt-in.o, which is subsequently linked into the finished kernel.^5

Modules fit seamlessly into this mechanism, as the following Ext3 Makefile example demonstrates:

#
# Makefile for the linux ext3-filesystem routines.
#

obj-$(CONFIG_EXT3_FS) += ext3.o

ext3-y := balloc.o bitmap.o dir.o file.o fsync.o ialloc.o inode.o \
ioctl.o namei.o super.o symlink.o hash.o resize.o ext3_jbd.o

ext3-$(CONFIG_EXT3_FS_XATTR) += xattr.o xattr_user.o xattr_trusted.o
ext3-$(CONFIG_EXT3_FS_POSIX_ACL) += acl.o
ext3-$(CONFIG_EXT3_FS_SECURITY) += xattr_security.o
If the Ext3 filesystem is compiled as a module andCONFIG_EXT3_FStherefore expands tom, the standard
targetobj-mstipulates that a file namedext3.omust be generated. The contents of this object file are
defined by a further explicit target calledext3-y.

The kernel employs indirect specification of the source files rather than direct specification inobj-mso
that additional features (whether enabled or not) can be taken into account. (The corresponding configu-
ration symbols in the Kconfig mechanism are described by aboolselection, and atristateis used for
the main symbolCONFIG_EXT3_FS.)

If, for example, extended attributes are to be used,CONFIG_EXT3_FS_XATTRexpands toy,andthispro-
duces the following line in the Makefile:

ext3-y += xattr.o xattr_user.o xattr_trusted.o
This links the additionally required object files into the object file and clearly indicates why the indirect
targetext3-yis used. If the following had been used, there would be two targets (obj-yandobj-m):

obj-$(CONFIG_EXT3_FS)} += xattr.o xattr_user.o xattr_trusted.o
As a result, the additional files would not be included in the standard Ext3 object.

Of course, the indirect approach also works when Ext3 is permanently compiled into the kernel.

B.4 Useful Tools
Many excellent tools are available to help programmers manage major software projects and keep
track of sources. They also render very good services in the Linux sector. This section describes
some of the helpers that facilitate work with the kernel. The selection of tools presented here is
purely subjective — they are my personal preferences, but countless alternatives are available on the
Internet.

(^5) If the object files use initcalls (as discussed in Appendix D), the sequence in which the files are specified inobj-yis the order in
which the initcalls of the same category are invoked because the link sequence is identical to the sequence inobj-y.

Free download pdf