1

root@vm# insmod ./test01.ko

insmod: ERROR: could not insert module ./tes01.ko: Invalid module format

my c file test01.c

#include <linux/module.h>
#include <linux/kernel.h>

int init_module(void)
{
    printk(KERN_INFO "Hello World!");
    return 0;
}

void cleanup_module(void)
{
    printk(KERN_INFO "Unloading test01 module\n");
}

module based test01.c

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>

static int __init load_module(void)
{
    printk(KERN_INFO "Hello World!");
    return 0;
}

static void __exit unload_module(void)
{
    printk(KERN_INFO "Unloading test01 module\n");
}

module_init(load_module);
module_exit(unload_module);

Makefile

obj-m += test01.o

all:
    make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

clean:
    make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean

make works fine output of modinfo

root@vm$ modinfo test01.ko
filename:       /test01/test01.ko
srcversion:     5AF577C6F26F6B146320283
depends:        
vermagic:       4.0.0-rc5+ SMP mod_unload modversions 

my kernel version uname -a

3.19.0-rc1+

dmseg output

[ 1470.217197] test01: disagrees about version of symbol module_layout

I feel problem is my vermagic from modinfo is 4.0 while kernel version is 3.19. Some time back I compiled kernel source(don't know which) and also install it by make -j2 && sudo make modules_install

I don't know why there is mismatch in kernel version ?

eswaat
  • 733
  • 1
  • 13
  • 31
  • after insert failed, what `dmesg` said? – fghj Nov 05 '15 at 07:14
  • @user1034749 I'll take a look and update the question. – eswaat Nov 05 '15 at 23:21
  • I cann't see `dmesg` output, plus how you tell the kernel that `init_module` function should be called on start of module, you should use `module_init` and friends macroses – fghj Nov 05 '15 at 23:23
  • @user1034749 Added dmseg output as well as tried with module based macro, still same error. – eswaat Nov 06 '15 at 05:40
  • It looks like your `/lib/modules/3.19.0-rc1+/build` is actually refers to the build directory of the kernel `4.0.0-rc5+`. E.g., you build and install kernel `3.19.0-rc1+`, remove sources(and build directory), get kernel `4.0.0-rc5+` in the same directory and build it. – Tsyvarev Nov 07 '15 at 17:32

0 Answers0