Linux Kernel Architecture

(Jacob Rumans) #1

Chapter7:Modules


break;
}
}

return ret;
}

The next step in module loading is to place the table of (GPL-) exported symbols in the kernel by setting
thenum_syms,symsandcrcindexelements (or their GPL equivalents) to the corresponding memory
locations of the binary data:

kernel/module.c
/* Set up EXPORTed & EXPORT_GPLed symbols (section 0 is 0 length) */
mod->num_syms = sechdrs[exportindex].sh_size / sizeof(*mod->syms);
mod->syms = (void *)sechdrs[exportindex].sh_addr;
if (crcindex)
mod->crcs = (void *)sechdrs[crcindex].sh_addr;
mod->num_gpl_syms = sechdrs[gplindex].sh_size / sizeof(*mod->gpl_syms);
mod->gpl_syms = (void *)sechdrs[gplindex].sh_addr;
if (gplcrcindex)
mod->gpl_crcs = (void *)sechdrs[gplcrcindex].sh_addr;
mod->num_gpl_future_syms = sechdrs[gplfutureindex].sh_size /
sizeof(*mod->gpl_future_syms);
mod->gpl_future_syms = (void *)sechdrs[gplfutureindex].sh_addr;
if (gplfuturecrcindex)
mod->gpl_future_crcs = (void *)sechdrs[gplfuturecrcindex].sh_addr;

Symbols marked as unused are handled identically so that we omit the corresponding code. Relocation
is then performed, and again, the kernel iterates through all module sections. Depending on section type
(SHT_RELorSHT_RELA), eitherapply_relocateorapply_relocate_addis called to perform relocation.
Depending on processor type, there is usually only one type of relocation (general relocation or add relo-
cation; see Appendix E). However, let’s not go into the details of relocation because this would involve
discussing a large number of architecture-specific subtleties.

module_finalizethen offers a further architecture-specific hook that allows the individual implementa-
tions to perform system-specific finalization tasks. On IA-32 systems, for example, some slower assembly
language instructions of older processor types are replaced with newer, faster instructions, if this is
possible.

Parameter processing is performed byparse_args, which converts the passed string of thefoo=bar,bar2
baz=fuz wiztype into an array ofkernel_paraminstances. A pointer to this array, which can be processed
by the module initialization function, is stored in theargselement of the module data structure.

As a final step,load_moduleinstalls module-related files into sysfs and frees temporary memory occu-
pied by the initial copy of the binary code.

Resolving References


resolve_symbolis used to resolve undefined symbol references. It is primarily a wrapper function, as
the code flow diagram in Figure 7-5 indicates.
Free download pdf