Linux Kernel Architecture

(Jacob Rumans) #1

Chapter7:Modules


As a result, the kernel creates two objects in the binary file:

❑ The undefinedvoidpointer__crc_functionis located in the normal symbol table of the mod-
ule.^26
❑ A pointer to the variable just defined is stored underkrcrtab_functionin the__kcrctabsection
of the file.

When the module is linked (in the first phase of module compilation), the linker uses the.verfile gen-
erated bygenksymsas a script. This supplies the__crc_functionsymbols with the values in the script.
The kernel reads them in later. If another module refers to one of these symbols, the kernel uses the
information shown here to ensure that both refer to the same version.

Unresolved References


Naturally it is not sufficient to store only the checksumsoftheexportedfunctionsofamodule.Itismore
importanttonotethechecksumsofallsymbolsusedbecause these must be compared with the versions
made available by the kernel when modules are inserted.

In the second part of module compilation,^27 the following steps are performed to insert version informa-
tion for all referenced symbols of a module into the module binary files:


  1. modpostis called as follows:
    wolfgang@meitner> scripts/modpost vmlinux module1 module2 module3 ...
    modulen
    Not only the name of the kernel image but also the names of all previously generated.o
    module binaries are specified.modpostis a utility that comes with the kernel sources. It pro-
    duces two lists, a global list containing all symbols made available (regardless of whether by
    the kernel or by a module), and a specific list for each module with all unresolved module
    references.

  2. modprobethen iterates through all modules and tries to find the unresolved references in
    the list of all symbols. This succeeds if the symbol is defined either by the kernel itself or in
    another module.
    Anewmodule.mod.c file is created for each module. Its contents look like this (for thevfat
    module, e.g.):
    wolfgang@meitner>cat vfat.mod.c
    #include <linux/module.h>
    #include <linux/vermagic.h>
    #include <linux/compiler.h>


MODULE_INFO(vermagic, VERMAGIC_STRING);

struct module __this_module
__attribute__((section(".gnu.linkonce.this_module"))) =
.name = KBUILD_MODNAME,

(^26) Theweakattribute creates a (weakly) linked variable. If it is not supplied with a value, no error is reported — as it would be for a
normal variable. It is ignored instead. This is necessary becausegenksymsdoes not generate a checksum for some symbols.
(^27) In the first part of compilation, all module source files were compiled into.oobject files that contain version information on the
exported symbols but not the referenced symbols.

Free download pdf