简体   繁体   English

内核导出符号vs全局符号vs静态全局?

[英]kernel exported symbols vs global symbols vs static global?

I am little bit stack with kernel symbols type meaning. 我有点堆满了内核符号类型的含义。 Simple static symbols have the same meaning like C static. 简单的静态符号与C静态具有相同的含义。 So local static variable have local scope and static allocation. 因此局部静态变量具有局部范围和静态分配。 Static functions scope is a file. 静态函数作用域是一个文件。 But what about static exported symbols? 但是静态导出符号呢? How to deal with EXPORT_SYMBOL() , EXPORT_PER_CPU_SYMBOL() , EXPORT_UNUSED_SYMBOL() if macro export static symbol? 如果宏导出静态符号,如何处理EXPORT_SYMBOL()EXPORT_PER_CPU_SYMBOL()EXPORT_UNUSED_SYMBOL() What is the difference between global and exported symbols? 全局符号和导出符号之间有什么区别? Is it linker responsibility to add additional info for exported symbols? 链接程序有责任为导出的符号添加其他信息吗? Is global static variable built-in kernel visible in all the kernel and loadable module? 全局静态变量内置内核在所有内核和可加载模块中是否可见?

Kernel exported symbols can be accessed from loadable module. 可以从可加载模块访问内核导出的符号。 Is it good style touch such symbols inside kernel. 在内核中触摸此类符号是否是好的样式。 When kernel resolve symbols is it lookup thru kernel symbols table? 当内核解析符号时,它会通过内核符号表进行查找吗?

Conceptually , using static keyword with function declaration means internal linkage -- so such function is only visible within single translation unit (*.o file). 从概念上讲 ,在函数声明中使用static关键字意味着内部链接 -因此,该函数仅在单个翻译单元(* .o文件)中可见。 This may involve inlining of that function (in which case it will be unusable further), but since EXPORT_SYMBOL() takes address of static function, compiler should disable inlining optimization. 这可能涉及该函数的内联(在这种情况下,它将进一步无法使用),但是由于EXPORT_SYMBOL()获取静态函数的地址,因此编译器应禁用内联优化。

Implementation is a bit more complicated. 实现有点复杂。 This internal and external linkage rules are only apply to static ld linker which works when vmlinux or kernel module is built. 内部外部链接规则仅适用于在构建vmlinux或内核模块时有效的静态ld链接器。 Normally symbol with external linkage is added to symtab ELF section and when dynamic linker ld.so loads shared object it reads that section. 通常,将具有外部链接的符号添加到symtab ELF部分中,并且当动态链接程序ld.so加载共享对象时,它将读取该部分。

But when module is loaded Linux Kernel uses separate symbol table ksymtab . 但是,在模块加载时,Linux内核使用单独的符号表ksymtab EXPORT_SYMBOL() adds symbol to that table, but this process is completely transparent to compiler-linker toolchain thus it is not related with internal and external linkage at all. EXPORT_SYMBOL()在该表中添加了符号,但是此过程对于编译器链接程序工具链是完全透明的,因此它根本与内部外部链接无关。

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

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