Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disagrees about version of symbol symbol_name after insmod

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

like image 320
user3243499 Avatar asked Nov 16 '15 11:11

user3243499


People also ask

What is the difference between insmod and modprobe?

insmod is similar to modprobe: it can insert a module into the Linux kernel. Unlike modprobe, however, insmod does not read its modules from a set location, automatically insert them, and manage any dependencies. insmod can insert a single module from any location, and does not consider dependencies when doing so.

What is the advantage of using modprobe over insmod to load a module into the kernel?

Suppose, if I loaded a module, which has symbols defined in some other module (this module path is given inside the main module). So, modprobe loads the main module and the dependent module. But if insmod is used, it won't load the dependency, and hence it will give compilation errors like Unresolved symbols .

What happens when we do insmod?

Insmod copies the module into the allocated space and relocates it so that it will run from the kernel address that it has been allocated. This must happen as the module cannot expect to be loaded at the same address twice let alone into the same address in two different Linux systems.

What is module Symvers file?

During a kernel build, a file named Module. symvers will be generated. Module. symvers contains all exported symbols from the kernel and compiled modules. For each symbol, the corresponding CRC value is also stored.


2 Answers

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.
like image 163
dave Avatar answered Oct 05 '22 22:10

dave


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

like image 26
Utkal Sinha Avatar answered Oct 05 '22 22:10

Utkal Sinha