简体   繁体   English

如何用LKM的导出符号编译内核?

[英]How to compile Kernel with a LKM's exported symbols?

I'm a Kernel newbie and needed some help compiling the Linux Kernel with exported symbols of a Kernel Module. 我是内核新手,需要一些帮助,使用导出的内核模块符号来编译Linux内核。

I tried the following - EXPORT_SYMBOL(func_name) in LKM source, LKM compiles and symbol is generated in its Module.symvers. 我尝试了以下操作-LKM源代码中的EXPORT_SYMBOL(func_name),LKM编译并且在其Module.symvers中生成了符号。 However, when I try to compile the Kernel with the Kernel invoking the exported symbol, it says undefined reference to 'func_name'. 但是,当我尝试使用调用导出符号的内核来编译内核时,它表示未定义对'func_name'的引用。

How should I get the Kernel compilation to see the exported symbols? 我应该如何获取内核编译以查看导出的符号? MOst example I see on Google are of Module-to-Module exporting. 我在Google上看到的第一个示例是模块到模块的导出。

What am I missing? 我想念什么? Any help is appreciated! 任何帮助表示赞赏!

EDIT: I basically want to call a function which is in LKM from the kernel. 编辑:我基本上想从内核中调用LKM中的函数。

When exporting kernel symbols, you have to consider the order of dependencies. 导出内核符号时,必须考虑依赖关系的顺序。 It sounds like you are trying to export a symbol from your module, and expecting that the kernel monolith will be able to use that exported symbol. 听起来您正在尝试从模块中导出符号,并期望内核整体能够使用该导出的符号。 But remember that the kernel is statically linked and therefore must be able to resolve all its symbols when it is built. 但是请记住,内核是静态链接的,因此在构建内核时必须能够解析其所有符号。 If you are adding some code to the monolith which is attempting to reference a symbol exported by a module, then it simply won't build - the linker has no knowledge of module symbols, since modules will always load after the monolith. 如果要向整体中添加一些代码,以尝试引用模块导出的符号,那么它将根本无法构建-链接器不了解模块符号,因为模块将始终在整体后加载。

In short, the monolith may export symbols which may be referenced by modules. 简而言之,整体可以导出模块可以引用的符号。 Also modules may export symbols which are referenced by other dependent modules. 模块也可以导出其他从属模块引用的符号。 But the opposite direction is impossible. 但是相反的方向是不可能的。

It sounds like you need to refactor your code somewhat so that you don't have to export from your module. 听起来您需要某种程度的重构代码,这样就不必从模块中导出。 Could you perhaps instead have the monolith export a function pointer which your module would populate when it is loaded? 也许您可以让巨石导出一个函数指针,您的模块在加载时会填充该函数指针吗? You would have to set it up so that the the monolith would only call the function pointed to by the function pointer if the module is in fact loaded. 您必须对其进行设置,以使整体组件仅在实际上加载了模块的情况下才调用函数指针指向的函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM