简体   繁体   English

内核模块中的符号

[英]symbols in kernel module

I built linux kernel module with SSP support for mips architecture. 我构建了Linux内核模块,支持mips架构的SSP。 I added -fstack-protector-all to compilation flags. 我在编译标志中添加了-fstack-protector-all But after loading this module I've got undefined references to __stack_chk_guard and __stack_chk_fail . 但是在加载这个模块后,我得到了对__stack_chk_guard__stack_chk_fail的未定义引用。 But I added libssp.so to linker. 但我将libssp.so添加到链接器。 It looks like I should export those symbols in kernel something like this: 看起来我应该在内核中导出这些符号,如下所示:

EXPORT_SYMBOL(__stack_chk_guard);

Because my kernel is old and didn't contain them yet. 因为我的内核很旧而且还没有包含它们。 But unfortunately I should use this version. 但不幸的是我应该使用这个版本。

My question is: why user space can use this symbols from toolchain library, but kernel space don't ? 我的问题是:为什么用户空间可以使用工具链库中的这个符号,但内核空间不行?

I think, I missed some linux kernel essentials. 我想,我错过了一些Linux内核要领。

You can't link the kernel to shared libraries. 您无法将内核链接到共享库。 If you have a static library of libssp, it MAY work - but it would require that the library isn't calling something else that would cause problems in the kernel. 如果你有一个libssp的静态库,它可以工作 - 但是它要求库不会调用会导致内核出现问题的其他东西。

In general, stack-checking isn't something that you should be doing on the kernel - I'm pretty sure it serves no particularly good purpose [I'm also pretty sure that the kernel uses a "guard page" for each kernel stack]. 一般来说,堆栈检查不是你应该在内核上做的事情 - 我很确定它没有特别好的用途[我也很确定内核为每个内核堆栈使用“保护页面” ]。

You cannot use shared libraries anywhere in kernel space (including as part of kernel modules). 您不能在内核空间中的任何位置使用共享库(包括作为内核模块的一部分)。

You could think of kernel modules themselves as an equivalent of shared libraries in kernel space but with lot of differences. 您可以将内核模块本身视为内核空间中的共享库的等价物,但存在很多差异。

Kernel modules can depend on exported symbols from other kernel modules. 内核模块可以依赖于来自其他内核模块的exported symbols

My question is: why user space can use this symbols from toolchain library, but kernel space don't ? 我的问题是:为什么用户空间可以使用工具链库中的这个符号,但内核空间不行?

Nothing in kernel space has access to the libc C library. 内核空间中没有任何内容可以访问libc C库。 Kernel has its own set of builtin standard string manipulation functions, etc. that you could use instead. 内核有自己的内置标准字符串操作函数等,您可以使用它们。 The toolchain libraries are built on top of libc . 工具链库建立在libc之上。

+1 on Mats's answer. Mats的回答是+1。 You could use a static library as long as it does not depend on standard C libraries like libc 您可以使用static library ,只要它不依赖于像libc这样的标准C库

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

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