Linux Kernel Architecture

(Jacob Rumans) #1

Chapter7:Modules


7.2.2 Dependencies


A module can also depend on one or more other modules. Let us take a look at thevfatmodule that
depends on thefatmodule because the latter includes severalfunctions that do not make a distinction
between the two variants of the filesystem.^6 In the view of the object filevfat.o, all this means is that
there are code references to functions defined infat.o. The advantages of this approach are obvious.
Because the code for handling a VFAT filesystem differs only in a few routines from that for handling
a FAT filesystem, a large part of the code can be used by both modules. This not only reduces space
requirements in system memory but also makes the source code shorter, more readable, and easier to
maintain.

Thenmtool illustrates the situation clearly:

wolfgang@meitner>nm vfat.ko
...
U fat_alloc_new_dir
U fat_attach
...

wolfgang@meitner>nm fat.ko
...

0000000000001bad T fat_alloc_new_dir
0000000000004a67 T fat_attach
...

I have selected two examples:fat_alloc_new_dirandfat_attach(fatalso provides many other func-
tions used byvfat). As the output ofnmshows, the two functions are listed in thevfatmodule as
unresolved references, whereas infat.o, they appear together with their (still unrelocated) addresses
in the object file.

Naturally, it makes no sense to patch these addresses into the object code ofvfat.kobecause the func-
tions would be somewhere totally different in memory after relocation offat.ko. Of greater interest are
the addresses of the functionsafterthefatmodule is added. This information is exported to userspace
by/proc/kallsymsbut is still held directly in the kernel. For both the permanently compiled part of the
kernel and for all subsequently added modules, there is an array whose entries assign symbols to their
addresses in virtual address space.

The following items are relevant when adding modules into the kernel:

❑ The symbol list of the functions provided by the kernel can be dynamically extended when mod-
ules are loaded. As you will see below, modules can specify exactly which functions in their code
are to be released for general use and which may be used internally only.
❑ The order in which modules are added into the kernel is important if there are interdependencies
between the modules. If, for example, an attempt is made to load thevfatmodule beforefat
is in the kernel, the attempt will fail because the addresses of a number of functions cannot be
resolved (and the code would not run).

(^6) FAT (file allocation table) is the very simple filesystem used by MS-DOS and still used for diskettes; vfat is a (minimal) enhance-
ment with an identical basic structure that supports filenames up to 255 characters long and no longer restricts them to the old 8 + 3
schema.

Free download pdf