* First of all, check your kernel configuration.
- CONFIG_MODULES=y - CONFIG_MODULE_UNLOAD=y <- Optional
* Create your Kernel module code and Makefile
If you have luck, everything should be OK. But...
CASE: error at insmod?
insmod: init_module 'hello.ko' failed (Exec format error) in android kernel message : unknown relocation: 27
Hmm, then you should check kernel functions you are using in the module (ex. printk)
You can check relocation type with following command (ex. printk)
readelf -r hello.ko | grep prink
Then, result may like below
xxxxxxxx xxxxxxxx R_ARM_PLT32 00000000 printk
For your information : number 27 indicates R_ARM_PLT32.
Then, what's the problem?
ELF for the ARM Architecture(IHI0044E_aaelf.pdf) says that R_ARM_PLT32 is deprecated.
And, Linux kernel doesn't handle R_ARM_PLT32 at module.c : apply_relocation() function
We have two workaround for this issue.
* Update toolchains.
In my case, I faced this issue when I used gcc-4.4.3. And, gcc-4.7 resolved this issue.
(You can see, relocation type is changed into R_ARM_CALL instead of R_ARM_PLT32.)
* fpic / fno-pic HACK.
If you are in trouble with upgrading your toolchains, here is workaround (tested on gcc-4.4.3).
Add, -fpic or -fno-pic at CFLAGS_MODULE in your module Makefile like below.
make CFLAGS_MODULE=-fpic xxxx modules
Then, like above - updating toolchains -, relocation type is changed :-)
'Domain > Kernel' 카테고리의 다른 글
Ext4 에 대한 분석 <Analysis regarding Ext4> (1) | 2012.06.12 |
---|---|
[Kernel] How to know KBUILD_MODNAME of each files. (0) | 2012.01.09 |
[Kernel] Analyzing linux kernel Oops report easily... (0) | 2011.12.15 |
[Kernel] SMP and IRQ - case (2011-Sep) (0) | 2011.09.23 |
[Kernel] Potential bug for using jiffies - ex. schedule_timeout() - at Linux kernel. (0) | 2011.08.18 |