Linux Kernel Architecture

(Jacob Rumans) #1

Chapter7:Modules


resolve_symbol

_ _find_symbol

check_version

use_module

Figure 7-5: Code flow diagram
forresolve_symbol.

Actual resolution of the symbol is performed in__find_symbol. The kernel first looks through all sym-
bols permanently compiled into the kernel:

kernel/module.c
static unsigned long __find_symbol(const char *name,
struct module **owner,
const unsigned long **crc,
int gplok)
{
struct module *mod;
const struct kernel_symbol *ks;

/* Core kernel first. */
*owner = NULL;
ks = lookup_symbol(name, __start___ksymtab, __stop___ksymtab);
if (ks) {
*crc = symversion(__start___kcrctab, (ks - __start___ksymtab));
return ks->value;
}
...
The helper functionlookup_symbol(name, start, end)searches through the symbol table found
betweenstartandendand checks if an entry with a givennamecan be found.symversionis an
auxiliary macro. If theMODVERSIONSoption is enabled, it extracts the corresponding entry from the CRC
table; otherwise, it returns 0.

The code to search in further sections is basically identical to the code shown above, so we don’t list
it explicitly here. Ifgplokis set to 1 because the module uses a GPL-compatible license, the GPL sym-
bols of the kernel located between__start___ksymtab_gpland__stop___kysmtab_gplare scanned
if no matching information is found in the generally accessible symbols. If this fails, the future GPL-
exported symbols are searched. If this still fails, the unused symbols as well as the unused GPL symbols
are searched. Should the symbol be present in these section, the kernel uses it to resolve the dependency
but prints out a warning because the symbol is bound to disappear sooner or later, so any modules using
the symbol will stop working at this point.

If the search is still unsuccessful, the exported symbols of the modules already loaded are scanned:

kernel/module.c
/* Now try modules. */
list_for_each_entry(mod, &modules, list) {
Free download pdf