I'm running into some odd issue on kernel module load that I'm suspecting having to do with linking and loading. How to I programmatically figure out the address of each section after they are loaded in memory (from inside the module itself). Like where is .bss / .data / .text and so on.
From reading this article https://lwn.net/Articles/90913/
It is sorta in the directly that I'm looking for.
From the module's code THIS_MODULE
macro is actually a pointer to the struct module
object. Its module_init
and module_core
fields point to memory regions, where all module sections are loaded.
As I understand, sections division is inaccessible from the module code(struct load_info
is dropped after module is loaded into memory). But having module's file you can easily deduce section's addresses after load:
module_init:
- init sections with code (.init.text)
- init sections with readonly data
- init sections with writable data
module_core:
- sections with code (.text)
- sections with readonly data
- sections with writable data
If several sections suit to one category, they are placed in the same order, as in the module's file.
Within module's code you can also print address of any its symbol, and after calculate start of the section, contained this symbol.