为了性能分析,参考x86的perf_event.c写了个例程,结果在加载时,提示:
test: Unknown symbol register_die_notifier
test: Unknown symbol unregister_die_notifier
但是查找了下符号表明明有这两个符号:
[root@bogon boot]# grep "register_die_notifier" System.map-2.6.32-431.*
System.map-2.6.32-431.1.2.0.1.el6.i686:c0483a80 T register_die_notifier
查来查去,只要在代码里加上MODULE_LICENSE("GPL");就可以找到符号。
查看Linux内核代码,发现这两个符号是用EXPORT_SYMBOL_GPL方式来导出的:
int register_die_notifier(struct notifier_block *nb)
{
vmalloc_sync_all();
return atomic_notifier_chain_register(&die_chain, nb);
}
EXPORT_SYMBOL_GPL(register_die_notifier);
int unregister_die_notifier(struct notifier_block *nb)
{
return atomic_notifier_chain_unregister(&die_chain, nb);
}
EXPORT_SYMBOL_GPL(unregister_die_notifier);
以前写代码时,也看过EXPORT_SYMBOL_GPL来导出符号,但是没在意,浪费了一早上时间,太坑爹了。