Skip to content
Advertisement

init function not present in kallsyms

I wrote a simple hello world kernel module

JavaScript

After loading the module, i am checking what all symbols are added into /proc/kallsysms. I don’t observe test_hello_init. Why don’t we have it

JavaScript

Advertisement

Answer

Using Linux kernel 5.8 source as a reference, the module’s symbol table for “kallsyms” is set up by the call to add_kallsyms() (in “kernel/module.c”) at module load time (call path: syscall init_module(), load_module(), post_relocation(), add_kallsyms()), before the module has been fully initialized. It adds the module’s full symbol table (pointed to by the module’s kallsyms member), and also constructs a cut-down, core symbol table (in the module’s core_kallsyms member) for use after the module has been initialized.

The switch from the full symbol table to the core symbol table occurs at the call

JavaScript

from do_init_module() (call path: syscall init_module(), load_module(), do_init_module()). This occurs after the module’s init function (if it has one) has been called.

do_init_module() is also responsible for discarding the module’s initial memory section (containing functions marked __init and data marked __initdata) once the module is initialized successfully. This is done by adding a pointer to the module’s init section to the static init_free_list list and scheduling a work item to free any sections on the list:

JavaScript
JavaScript
JavaScript

The scheduled work function is do_free_init(). That exchanges init_free_list with an empty list and iterates through the original copy of init_free_list to free the module’s initial memory section:

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement