Linux Kernel Architecture

(Jacob Rumans) #1

Chapter7:Modules


At first glance, the definition is anything but clear. Its effect is therefore illustrated by reference to the
following example:

EXPORT_SYMBOL(get_rms)
/*****************************************************************/
EXPORT_SYMBOL_GPL(no_free_beer)

The above code is processed by the pre-processor and then looks something like this:

static const char __kstrtab_get_rms[]
__attribute__((section("__ksymtab_strings"))) = "get_rms";

static const struct kernel_symbol __ksymtab_get_rms
__attribute_used__ __attribute__((section("__ksymtab" ""), unused)) =
(unsigned long)&get_rms, __kstrtab_get_rms

/*****************************************************************/

static const char __kstrtab_no_free_beer[]
__attribute__((section("__ksymtab_strings"))) = "no_free_beer";

static const struct kernel_symbol __ksymtab_no_free_beer
__attribute_used__ __attribute__((section("__ksymtab" "_gpl"), unused)) =
(unsigned long)&no_free_beer, __kstrtab_no_free_beer

Two code sections are generated for each exported symbol. They serve the following purpose:

❑ __kstrtab_functionis stored in the__ksymtab_stringssection as a statically defined variable.
Its value is a string that corresponds to the name of the (function)function.
❑ Akernel_symbolinstance is stored in the__ksymtab(or__kstrtab_gpl) section. It consists of a
pointer to the exported function and a pointer to the entry just created in the string table.
This allows the kernel to find the matching code address by reference to the function name in the
string; this is needed when resolving references, as is discussed in Section 7.3.4.

MODULE_SYMBOL_PREFIXcan be used to assign a prefix to all exported symbols of a module; this is neces-
sary on some architectures (but most define an empty string as the prefix).

__CRC_SYMBOLis used when kernel version control is enabled for exported functions (refer to Section 7.5
for further details); otherwise, it is defined as an empty string as I have assumed here for simplicity’s
sake.

GeneralModuleInformation


The.modinfosection of a module includes general information set usingMODULE_INFO:

<module.h>
#define MODULE_INFO(tag, info) __MODULE_INFO(tag, tag, info)

<moduleparam.h>
#define __MODULE_INFO(tag, name, info) \
static const char __module_cat(name,__LINE__)[] \
Free download pdf