I am trying to create a simple kernel module. I am trying to print messages to dmesg but i keep getting
insmod: init_module 'hello.ko' failed (Exec format error) in android
after : dmesg: unknown relocation: 27
#include <linux/module.h>
#include <linux/kdb.h>
int init_module(void)
{
printk(KERN_ALERT "Hello world!\n");
return 1;
}
void cleanup_module(void)
{
printk(KERN_INFO "Goodbye world 1.\n");
}
MODULE_AUTHOR("Robert P. J. Day");
MODULE_LICENSE("Dual BSD/GPL");
MODULE_VERSION("2:1.0") ;
MODULE_DESCRIPTION("You have to start somewhere.");
The make file
obj-m +=hello.o
KERNELDIR ?= ~/android/kernel/common
#KERNELDIR ?= /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
CROSS_COMPILE=~/android-ndk-r8/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-
ARCH=arm
default:
$(MAKE) -C $(KERNELDIR) M=$(PWD) ARCH=arm CROSS_COMPILE=$(CROSS_COMPILE) modules
clean:
$(MAKE) -C $(KERNELDIR) M=$(PWD) clean
rm *.symvers
does anyone know why? And how to get it working?
I found after doing a readelf that when it is compiled the relocation section is pointing to the wrong directions.
Offset Info Type Sym.Value Sym. Name
00000008 0000171b R_ARM_PLT32 00000000 printk
When in fact it should be:
Offset Info Type Sym.Value Sym. Name
00000008 0000171c R_ARM_CALL 00000000 printk
Can someone guess/know how this might be? Thanks @Chris Stratton for helping me this far.
I found after doing a readelf that when it is compiled the relocation section is pointing to the wrong directions.
Offset Info Type Sym.Value Sym. Name
00000008 0000171b R_ARM_PLT32 00000000 printk
When in fact it should be:
Offset Info Type Sym.Value Sym. Name
00000008 0000171c R_ARM_CALL 00000000 printk
Can someone guess/know how this might be? Thanks @Chris Stratton for helping me this far.
It turns out I had to use
make CFLAGS_MODULE=-fno-pic
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With