I have a kernel module that needs to have access to the kernel’s _stext and _etext symbols. For some reason, even though the kernel has definitions for these symbols (/proc/kallsyms), whenever I load my module I get
mymodule: Unknown symbol _etext (err 0)
mymodule: Unknown symbol _stext (err 0)
I’m not running a tainted kernel, and everything else in the module seems to link ok. Are there module or license restrictions on linking to _stext and _etext? Is there a substitute definition in the kernel that I could use for the beginning and end of code memory?
Update:
I’m looking at the kernel source, and in kallsyms.c, there’s this:
static int read_symbol_tr(const char *sym, unsigned long long addr)
{
size_t i;
struct text_range *tr;
for (i = 0; i < ARRAY_SIZE(text_ranges); ++i) {
tr = &text_ranges[i];
if (strcmp(sym, tr->stext) == 0) {
tr->start = addr;
return 0;
} else if (strcmp(sym, tr->etext) == 0) {
tr->end = addr;
return 0;
}
}
return 1;
}
Does this mean that the _etext and _stext entries that I’m seeing the /proc/kallsyms are fake symbols that a kernel module can’t actually link to?
The kernel module linker will only link symbols that have been “exported” via an additional mechanism: the symbol must be exported with
EXPORT_SYMBOL()orEXPORT_SYMBOL_GPL(). (The_GPLvariant indicates that the kernel developers are labeling that an internal interface and thus available only to GPL-licensed code.) I cannot find exports for either_stextor_etexton my kernel sources, so I don’t believe they are available to you to use.What are you trying to accomplish?