Linux Kernel Architecture

(Jacob Rumans) #1

Chapter7:Modules


Thenmtool can be used to generate a list of all external functions in a module (or in any object file). The
following example shows a number of functions that are used in theromfsmodule but are labeled as
external references:

wolfgang@meitner>nm romfs.ko
U generic_read_dir
U generic_ro_fops
...
U printk
...
U register_filesystem
...

TheUin the output stands for anunresolvedreference. Note that if your kernel was not built with
KALLSYMS_ALLenabled,generic_ro_fopswill not be visible. Only symbols of functions but no other
symbols like constant structures asgeneric_ro_fopsare included in this case.

It is clear that these functions are defined in kernel base code and are therefore already held in memory.
But how can the matching addresses needed to resolve the reference be found? For this purpose, the
kernel provides a list of all exported functions; this list shows the memory addresses together with the
corresponding function names and can be accessed via theprocfilesystem, this being the purpose of
the file/proc/kallsyms^5 :

wolfgang@meitner>cat /proc/kallsyms | grep printk
ffffffff80232a7f T printk

The function references shown in the above example can be fully resolved using the following informa-
tion, all of which is held in the symbol table of the kernel:

fffffc0000324aa0 T printk
fffffc00003407e0 T generic_file_write
ffffffff8043c710 R generic_ro_fops
fffffc0000376d20 T register_filesystem

ATdenotes that the symbol is located in the text segment, whileDdetermines it to be in the data segment.
Refer to Appendix E for more information on the layout of object files.

Logically, the information in the symbol table differs not only according to kernel configuration but also
from processor to processor. In our example, we used an AMD64 system. Searching through the symbol
table on an IA-32 CPU, for example, would produce the following picture:

c0119290 T printk
c012b7b0 T generic_read_dir
c0129fc0 D generic_ro_fops
c0139340 T register_filesystem

The addresses are not only shorter (after all, IA-32 use a word length of 32 bits) but, logically, point to
different locations.

(^5) Notice that because the reference is resolved in the kernel itself andnot in userspace, this file is available for information purposes
but is not used by the module utilities.

Free download pdf