7

I am new in kernel programming.

For implementing my project work, I have downloaded the latest stable kernel (v4.3) from kernel.org.

Just for checking I have copied a few files from the kernel directories into my project directory. Made changes to it and inserted a few more code to it.

Then I compiled on SLES11 Linux kernel using

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

I have used the below makefile

obj-m := my_module.o
my_module-objs := module_main.0 other_module1.o other_module2.o other_module3.o

It compiled successfully. But when I tried to insert into the kernel using

insmod my_sample.ko

It showed the following

disagrees about version of symbol symbol_name

enter image description here

4 Answers 4

8
+50

You need to build your kernel module against the same version kernel you are going to run. Thus if you have kernel 4.3 sources that you have downloaded you need to compile that version of the kernel and boot with that running before trying to load your kernel.

You have two solutions then:

  1. Download the kernel sources for the kernel you are currently running (you can install those with zypper install kernel-source on SLES or an equivalent command on other distributions.)
  2. Compile and install the 4.3 kernel in to your operating system. If you need help with this then ask a separate question (and it probably belongs on superuser not here). Note that if kernel and glibc are tightly coupled, and it is possible that you can't run a new kernel if you have a very old C library.
7
  • I have downloaded the src files from /usr/src/ directory in the running kernel. Then done the same editing. It again compiled successfully but when I try to insmod the .ko file it shows the same version issues as shown in the above snapshot. Kernel version ( uname -r shows 3.0.76-0.11-default ) and insmod -V shows ( module-init-tools version 3.11.1 ) please help. Commented Nov 19, 2015 at 8:07
  • Also by running cat /proc/version it is showing Linux Version 3.0.76-0.11-default (geeko@buildhost) (gcc version 4.3.4 [gcc-4_3-branch revision 152973] (SUSE Linux)) . So which version should I use ? Commented Nov 19, 2015 at 9:11
  • 1
    If you want your module to run under the kernel you are currently running, you will need to compile it against that kernel (3.0). You should be able to get the original kernel sources for that build from SuSE.
    – Joel C
    Commented Nov 20, 2015 at 17:01
  • @user3243499: you need to compile against the same version of the kernel which you want to load the module against. You have kernel version 3.0 and a module version 3.11. So you don't have the sources of your kernel. I'm not familiar with SLES so I'm not sure where to get the correct sources from.
    – dave
    Commented Nov 22, 2015 at 22:49
  • 1
    @user3243499: I don't think that is the case. If you have a very simple module that hardly uses any kernel symbols then that module will load because the symbols haven't changed from one version to the next. But if you have a more complicated module then you have to compile against the same sources (or you will get the error you are seeing).
    – dave
    Commented Nov 25, 2015 at 23:34
3

The problem here is that your Kernel module is using the exported symbols of other kernel modules which in this case appears to be the linux InfiniBand RDMA stack's exported methods or symbols.

To solve the symbol version problems, copy the Module.symvers file from the

/usr/src/ofa-kernel

directory and paste it to your current working directory. Then you make your modules again. Now the insmod should work perfectly fine.

NOTE: The Module.symvers file contains information of all the kernel module exported symbol. So by copying it to your working directory, you are helping kbuild to know more about the used exported symbols.

And if you don't find Module.symvers or it is empty, then create one using create_Module.symvers.sh

1
  • 1
    I have the same issue on ubuntu 14.04. Copying from /usr/src/of-kernal/default didnt solve the issue. /usr/src/ofa-kernel has only one directory default. Installed the driver through mlnx-ofed-kernel-3.3 which created ofa-kernel and ofa-kernel-3.3. Please help. Thanks.
    – S. Salman
    Commented Jul 5, 2016 at 10:25
2

make -C /lib/modules/$(uname -r)/build M=$PWD modules, "$(uname -r)" shows that you are compiling against the kernel version you are running now so you should be able to insmod the module in the current kernel if you haven't changed the headers.

From your text, "Just for checking I have copied a few files from the kernel directories into my project directory. Made changes to it and inserted a few more code to it."

If you have made modifications to the kernel source then you may need to recompile the new kernel and boot with the new updated kernel. Then you should be able to compile your kernel module with the modified headers.

2
  • I think I have made some changes in the headers of some device drivers. Can you refer me a link which shows MINIMAL steps to follow to recompile the kernel. ` Also once compiled do I need to recompile the kernel again if in future I made any changes to the headers as part of the development ? ` Commented Nov 25, 2015 at 14:40
  • 1
    Kernel compilation usually involves config change, then building it and install. I have done this mostly in ubuntu but it isn't a lot different in SuSe. Here is a link that has steps to do it in SuSe howtoforge.com/kernel_compilation_suse. Yes, we need to recompile the kernel if you are modifying the kernel header and use the modified header for your kernel module.
    – Randolf
    Commented Nov 25, 2015 at 19:03
0

Looks like you built agAinst right kernel.something to do with how your kernel is compiled. (See Config_conversions). Try --force

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.