kernel symbol marked with "T" in /proc/kallsyms is not exported

时间:2015-10-06 08:47:10

标签: linux module kernel export symbols

Symbol machine_power_off is marked with "T" in /proc/kallsyms:

$ grep -w machine_power_off /proc/kallsyms 
ffffffff8102391b T machine_power_off

But it is not exported. Is "T" in kallsyms necessary and sufficient for a symbol to be exported? Is being exported necessary and sufficient for using in other modules?

My module using it is compiled with a warning:

WARNING: "machine_power_off" [/path/to/module.ko] undefined!

On host machine (3.2.0-4-amd64) I can load this module, but on VirtualBox (3.16.0-4-amd64) it produces the following message:

insmod: ERROR: could not insert module module.ko: Unknown symbol in module

Why is this module loaded in my host system, but not in VirtualBox?

2 个答案:

答案 0 :(得分:5)

要使用全局但未导出的内核符号(例如您提到的machine_power_off符号),可以在模块代码中使用kallsyms_lookup

#include <linux/kallsyms.h>

static void (*machine_power_off_p)(void);
machine_power_off_p = (void*) kallsyms_lookup_name("machine_power_off");

现在您可以通过machine_power_off指针调用machine_power_off_p函数:

(*machine_power_off_p)();

答案 1 :(得分:4)

/proc/kallsyms中标记“T”表示符号全局可见,可用于其他内核代码(例如通过驱动程序,编译内置)。

但是要在内核模块的代码中使用,需要使用EXPORT_SYMBOL或类似的方法导出符号。导出符号列表与内核中所有符号的列表分开维护。

导出的符号可以在文件/lib/modules/<kernel-version>/build/Module.symvers中找到。

(这个文件应该存在,以便针对给定的内核构建内核模块。)