为所有内核模块添加对符号的支持

时间:2017-01-21 07:24:28

标签: linux module linux-kernel linux-device-driver

我有一个模块,它存在于kernel/trace中,比如说module.c,我在那里定义了一个符号,我需要将它提供给所有内核模块。我在该模块中使用EXPORT_SYMBOL(mymodule)将其导出到所有模块。但我没有在其他模块中指定extern type mymodule(),例如/lib/net等。我收到了数千个现在未定义的引用错误,我不能手动去添加extern到所有模块。有没有办法添加一个extern type mymodule(),以便它被所有模块使用。我想我们应该在一些Makefile中添加它,但是我如何以及在何处添加它?我正在使用linux 4.1内核。

错误讯息:

lib/lib.a(klist.o): In function `klist_del':
lib/klist.c:230: undefined reference to `__cyg_profile_func_enter'
lib/klist.c:232: undefined reference to `__cyg_profile_func_exit'
lib/lib.a(klist.o): In function `klist_iter_exit':
lib/klist.c:313: undefined reference to `__cyg_profile_func_enter'
lib/klist.c:318: undefined reference to `__cyg_profile_func_exit'
lib/lib.a(klist.o): In function `klist_remove':
lib/klist.c:240: undefined reference to `__cyg_profile_func_enter'

1 个答案:

答案 0 :(得分:0)

我不认为extern类型明确需要定义它。 您只需要以下实现(假设您已经在Makefile和Kconfig中进行了更改):

<强>的module.c

return_type module_function(function_args){
}
EXPORT_SYMBOL(module_function);

<强> module.h中

return_type module_function(function_args);

添加标题文件,例如 module.c 中的 module.h 以及您要访问module_function的文件。

您还可以尝试使用EXPORT_SYMBOL_GPL而不是EXPORT_SYMBOL。