gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:22:03 27 4
gpt4 key购买 nike

我有一个模块存在于 kernel/trace 中,比如 module.c 并且我在其中定义了一个符号,我需要让所有内核都可以使用它模块。我在该模块中使用了 EXPORT_SYMBOL(mymodule) 将其导出到所有模块。但是我没有在其他模块中指定 extern type mymodule() ,例如 /lib/net 等。我现在收到数以千计的 undefined reference 错误,我无法手动将 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'

最佳答案

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

module.c

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

module.h

return_type module_function(function_args);

添加头文件,例如module.h 中的 module.c 和您要访问 module_function 的文件。

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

关于linux - 为所有内核模块添加对符号的支持,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41776778/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com