为什么此内核模块在2.6.39上标记为永久 [英] Why is this kernel module marked at permanent on 2.6.39
问题描述
当我加载此模块时:
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
MODULE_LICENSE("Dual BSD/GPL");
static int hello_init(void) {
printk("<1> Hello world!\n");
return 0;
}
static void hello_exit(void) {
printk("<1> Bye, cruel world\n");
}
module_init(hello_init);
module_exit(hello_exit);
(来自 http://www.freesoftwaremagazine.com/articles/drivers_linux? page = 0,2 )
该模块在lsmod
中被标记为[permanent]
并且无法卸载,在2.6.39-02063904-generic(来自
The module get marked as [permanent]
in lsmod
and can't be unloaded, on 2.6.39-02063904-generic (from the Ubuntu PPA). But it works fine on the default 2.6.38 kernel. (Both on Ubuntu 11.04 x86).
2.6.39中发生了什么变化?我需要更改我的代码吗?
What has changed in 2.6.39? and what do I need to change in my code?
遇到此问题时,我正试图找出一个更复杂的问题.
I was trying to isolate a more complicated problem when I ran into this issue.
根据答案的建议,我编辑了代码以添加__init
和__exit
(hello3.c):
Following a suggestion from an answer I edited the code to add __init
and __exit
(hello3.c):
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
MODULE_LICENSE("Dual BSD/GPL");
static int __init hello_init(void) {
printk("<1> Hello world!\n");
return 0;
}
static void __exit hello_exit(void) {
printk("<1> Bye, cruel world\n");
}
module_init(hello_init);
module_exit(hello_exit);
构建输出:
make -C /lib/modules/2.6.39-02063904-generic/build M=/home/douglas/kernelmod modules
make[1]: Entering directory `/usr/src/linux-headers-2.6.39-02063904-generic'
Building with KERNELRELEASE = 2.6.39-02063904-generic
CC [M] /home/douglas/kernelmod/hello3.o
Building modules, stage 2.
Building with KERNELRELEASE = 2.6.39-02063904-generic
MODPOST 8 modules
CC /home/douglas/kernelmod/hello3.mod.o
LD [M] /home/douglas/kernelmod/hello3.ko
make[1]: Leaving directory `/usr/src/linux-headers-2.6.39-02063904-generic'
hello3.mod.c:
hello3.mod.c:
#include <linux/module.h>
#include <linux/vermagic.h>
#include <linux/compiler.h>
MODULE_INFO(vermagic, VERMAGIC_STRING);
struct module __this_module
__attribute__((section(".gnu.linkonce.this_module"))) = {
.name = KBUILD_MODNAME,
.init = init_module,
#ifdef CONFIG_MODULE_UNLOAD
.exit = cleanup_module,
#endif
.arch = MODULE_ARCH_INIT,
};
static const struct modversion_info ____versions[]
__used
__attribute__((section("__versions"))) = {
{ 0xbe4b3e92, "module_layout" },
{ 0xb4390f9a, "mcount" },
{ 0x5e3b3ab4, "printk" },
};
static const char __module_depends[]
__used
__attribute__((section(".modinfo"))) =
"depends=";
MODULE_INFO(srcversion, "D2A869459874C22AB265981");
也
# grep CONFIG_MODULE_UNLOAD /boot/config-2.6.39-02063904-generic
CONFIG_MODULE_UNLOAD=y
更有趣的是,我自己编写的香草内核不会发生这种情况- 可以很好地加载和卸载模块.
More interestingly it doesn't happen with a vanilla kernel I've compiled myself - that loads and unloads modules fine.
我在VM上安装了Oneiric beta 2版本,并且3.0.0-11内核也没有任何问题.因此,它似乎仅限于Ubuntu Vanilla PPA内核.解决起来不会很有趣.
I installed the Oneiric beta 2 build on a VM, and that 3.0.0-11 kernel doesn't have any problem either. So it appears to be limited to the Ubuntu Vanilla PPA kernels. That won't be much fun to resolve.
推荐答案
因此,在与Canonical协商后,我知道问题出在哪里:
So, after consultation with Canonical, I know what the problem is:
Ubuntu主线版本是使用Hardy工具链以及11.04和11.10工具链构建的与构建树外内核模块不兼容.
Ubuntu mainline builds are built with the Hardy tool chain, and the 11.04 and 11.10 tool chains are incompatible for building out-of-tree kernel modules.
这篇关于为什么此内核模块在2.6.39上标记为永久的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!