问题
To display symbols in /proc/kallsyms
, for the module symbols, kernel loops over module objects headed by modules
kernel variable, and iterate over each module's symbol table. But for the 'core' kernel built-in symbols, it uses a bunch of kernel variables, demonstrated in this function:
static unsigned long kallsyms_sym_address(int idx)
{
if (!IS_ENABLED(CONFIG_KALLSYMS_BASE_RELATIVE))
return kallsyms_addresses[idx];
/* values are unsigned offsets if --absolute-percpu is not in effect */
if (!IS_ENABLED(CONFIG_KALLSYMS_ABSOLUTE_PERCPU))
return kallsyms_relative_base + (u32)kallsyms_offsets[idx];
/* ...otherwise, positive offsets are absolute values */
if (kallsyms_offsets[idx] >= 0)
return kallsyms_offsets[idx];
/* ...and negative offsets are relative to kallsyms_relative_base - 1 */
return kallsyms_relative_base - 1 - kallsyms_offsets[idx];
}
Questions are:
- where are kallsyms_addresses and kallsyms_offsets arrays defined? I tried to grep in kernel source but only find references, no definitions.
- where are they initialized?
- what's the relation between these variables and /boot/System.map.kernel_version file? I assume they should be consistent but again I didn't find the initialization code.
来源:https://stackoverflow.com/questions/59146865/linux-proc-kallsyms-file-where-does-kernel-save-core-symbols-list