-Wimplicit-function-declaration while make module qmi_wwan - linux

my Makefile:
obj-m += qmi_wwan.o
CFLAGS += -Werror -Wno-implicit-function-declaration
all:
make -C /lib/modules/5.10.103-v7l+/build M=$(PWD) modules
clean:
make -C /lib/modules/5.10.103-v7l+/build M=$(PWD) clean
Error i get while compiling:
warning: implicit declaration of function ‘dev_sw_netstats_tx_add’; did you mean ‘dev_sw_netstats_rx_add’? [-Wimplicit-function-declaration]
warning: implicit declaration of function ‘dev_addr_mod’; did you mean ‘dev_addr_add’? [-Wimplicit-function-declaration]
Additional informations:
I'm configuring qmi_wwan module to add Quectel RM520N as it was explained -> in this thread
Thanks in advance for any help.

Problem solved. I was compiling qmi_wwan from kernel 5.15.y on my current kernel 5.10.y, that's why I've got this error.
After compiling qmi_wwan driver from 5.10.y, the problem disappeared.

Related

How do I link a static library when building a kernel module?

I want to build a Linux kernel module foo.ko from an existing file foo.c and a static library support.a. The library support.a is compiled from Rust so there is no support.c.
I've used the following Makefile
KERNEL_DIR := /lib/modules/$(shell uname -r)/build
obj-m += foo.o
foo-obs += support.a
all:
$(MAKE) -C $(KERNEL_DIR) SUBDIRS=$(PWD) modules V=1
It seems that support.a is not linked; there are warnings that the functions called from foo.c (and implemented in support.a) are undefined.
Update 0: the Makefile works on Ubuntu LTS (I've tested on 18.04 and 14.04) but not on Fedora (both 29/30). The output in case of Fedora is:
...
make -C /lib/modules/5.1.11-200.fc29.x86_64/build SUBDIRS=/public/Github/rustyvisor modules
make[1] : on entre dans le répertoire « /usr/src/kernels/5.1.11-200.fc29.x86_64 »
Makefile:205: ================= WARNING ================
Makefile:206: 'SUBDIRS' will be removed after Linux 5.3
Makefile:207: Please use 'M=' or 'KBUILD_EXTMOD' instead
Makefile:208: ==========================================
LD [M] /public/Github/rustyvisor/rustyvisor.o
Building modules, stage 2.
MODPOST 1 modules
WARNING: /public/Github/rustyvisor/rustyvisor.o(.init.text+0xbb): Section mismatch in reference from the function init_module() to the function .exit.text:rustyvisor_exit()
The function __init init_module() references
a function __exit rustyvisor_exit().
This is often seen when error handling in the init function
uses functionality in the exit path.
The fix is often to remove the __exit annotation of
rustyvisor_exit() so it may be used outside an exit section.
WARNING: "rustyvisor_core_unload" [/public/Github/rustyvisor/rustyvisor.ko] undefined!
WARNING: "rustyvisor_load" [/public/Github/rustyvisor/rustyvisor.ko] undefined!
WARNING: "rustyvisor_core_load" [/public/Github/rustyvisor/rustyvisor.ko] undefined!
WARNING: "rustyvisor_unload" [/public/Github/rustyvisor/rustyvisor.ko] undefined!
LD [M] /public/Github/rustyvisor/rustyvisor.ko
make[1] : on quitte le répertoire « /usr/src/kernels/5.1.11-200.fc29.x86_64 »
Update 1: There is very similar question but this question is to ask why the Makefile doesn't work on Fedora but I discovered that it works on Ubuntu.
Finally, I found a workaround for the problem (but I still don't understand why). On Fedora, the library name support.a should be changed to support.o, then the linker works!!!

insmod error: inserting './hello.ko': -1 Invalid module format"

I have just made my first driver module, the hello world module following LDD3. However unfortunately encountered this error:
insmod: error inserting './hello.ko': -1 Invalid module format.
I am doing this on Ubuntu 11.04, and my environment:
$ uname -r
2.6.38-8-generic
I get the kernel source like this:
sudo apt-cache search linux-source
linux-source - Linux kernel source with Ubuntu patches
linux-source-2.6.38 - Linux kernel source for version 2.6.38 with Ubuntu patches
$sudo apt-get install linux-source-2.6.38
my /usr/src:
$ls /usr/src/
linux-headers-2.6.38-8 linux-source-2.6.38 vboxguest-5.0.10
linux-headers-2.6.38-8-generic linux-source-2.6.38.tar.bz2
and then I compile the kernel
$sudo cp /boot/config-2.6.38-8-generic ./.config
$sudo make menuconfig -- load the .config file
$make
$make modules
and then I compile my kernel module
$make -C /usr/src/linux-source-2.6.38/linux-source-2.6.38 M=`pwd` modules
with Makefile:
obj-m := hello.o
and then finally when I insert the module:
$sudo insmod hello_world.ko
insmod: error inserting 'hello_world.ko': -1 Invalid module format
what I found in dmesg:
hello: disagrees about version of symbol module_layout
So what's the problem?
I have also noticed that the linux-header is -2.26.38-generic and source code version is -2.26.38, is this the problem? but I have really not found a linux-source-2.26.38-generic package on web.
status update:
I have found that the file /lib/moduels/$(name -r)/build/Makefile indicate my running kernel version:
VERSION = 2
PATCHLEVEL = 6
SUBLEVEL = 38
EXTRAVERSION = .2
So I download the linux-2.6.38.2 and compile, but still the same error.
I have also found that there is a line in /boot/config-$(uname -r):
CONFIG_VERSION_SIGNATURE="Ubuntu 2.6.38-8.42-generic 2.6.38.2"
Does any one know what is this mean? I don't see it in the config file of the kernel i am building.
Kernel from which you build your kernel module and to which you are inserting module should be of same version. If you do not want to take care of this thing you can use following Makefile.
obj−m += hello−world.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
Now you can build and try to insert module.
I suggest you to become root if possible before this line
$sudo cp /boot/config-2.6.38-8-generic ./.config
$su
#cp /boot/config-2.6.38-8-generic ./.config
#insmod hello_world.ko
Alternatively you can also use following make file
TARGET := hello-world
WARN := -W -Wall -Wstrict-prototypes -Wmissing-prototypes
INCLUDE := -isystem /lib/modules/`uname -r`/build/include
CFLAGS := -O2 -DMODULE -D__KERNEL__ ${WARN} ${INCLUDE}
CC := gcc-3.0
${TARGET}.o: ${TARGET}.c
.PHONY: clean
clean:
rm -rf ${TARGET}.o
Try using cross compile. Please look at the code below for the make file. Be mindful of the indentation else you may end up with error such as missing separator. Stop
obj-m += hello_.o #this name should be the name of your .c file. I am just using hello for example
I suggest the best approach is via cross compilation
Create a variable to hold the directory name where the linux kernel directory resides In my example, change the value "PATH_TO_LINUX_KERNEL_DIRECTORY" to a real path value
Example ~/linux
You really need to do this so that the make file will know where to find arm-linux-gnueabi- Without this, you are likely to run into issues arm-linux-gnueabi-
KDIR := PATH_TO_LINUX_KERNEL_DIRECTORY
all:
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- -C $(KDIR) M=$(shell pwd) modules
clean:
make -C $(KDIR) M=$(shell pwd) clean
You did everything correctly but did not booted your system with the kernel you compiled so the first step is you should boot with it.
If you are using Ubuntu you can hold shift button at the time of booting and you will be given a list of compiled kernel in your system from there select linux-source-2.6.38 and then try to build your module and install it with your way ,than you won't find any problem.
GoodLuck.

Library error when building a make file for a CUDA program

I am trying to build a makefile in linux. The code which goes into the makefile is as follows:
NVCC = /usr/local/cuda/bin/nvcc
CUDAPATH = /usr/local/cuda
NVCCFLAGS = -I$(CUDAPATH)/include
LFLAGS = -L$(CUDAPATH)/lib64 -lcuda -lcudart -lm
VectorAdd:
$(NVCC) $(NVCCFLAGS) $(LFLAGS) -o VectorAdd VectorAdd.cu
So when I type "make"
I get the following error:
How do i get rid of it and build my make file?
Since you're using NVCC you don't really need those LFLAGS and NVCCFLAGS definitions. nvcc knows how to find all that automatically.
But if you want to fix it, get rid of the space at the end of your cuda path definition:
CUDAPATH = /usr/local/cuda
^ there is a space here, delete it

building "out of the source tree" kernel module

I'm building a sample kernel module under linux . The module sources are "out of the kernel tree". I've got kernel source tree from git. But it takes time to configure the kernel. So at this moment i'm just trying to build the module against kernel headers provided by my Distribution.
My Makefile :
KVERSION=$(shell uname -r)
PWD := $(shell pwd)
all:
make -C /lib/modules/$(KVERSION)/build/ M=$(PWD) modules
clean:
make -C /lib/modules/$(KVERSION)/build M=$(PWD) clean
$(info Building with KERNELRELEASE = ${KERNELRELEASE})
obj-m := hello.o
But make stops with reporting that i could not find etc, that means it could not find the headers.
but the files are there :
$ls /lib/modules/$(uname -r)/build
$arch block crypto drivers firmware fs include init ipc kernel lib Makefile Makefile.common mm Module.symvers net samples scripts security sound System.map tools usr virt
I guess its a trivial problem. But still i could not find the solution.
Thanks in advance.
EDIT: Errors :
Building with KERNELRELEASE =
make -C /lib/modules/2.6.32-220.el6.x86_64/build/ M=/usr/local/src/kernel_mods
make[1]: Entering directory `/usr/src/kernels/2.6.32-220.el6.x86_64'
Building with KERNELRELEASE = 2.6.32-220.el6.x86_64
LD /usr/local/src/kernel_mods/built-in.o
CC [M] /usr/local/src/kernel_mods/hello.o
/usr/local/src/kernel_mods/hello.c:2:27: error: linux/modules.h: No such file or directory
/usr/local/src/kernel_mods/hello.c:21: error: expected declaration specifiers or â...â before string constant
/usr/local/src/kernel_mods/hello.c:21: warning: data definition has no type or storage class
/usr/local/src/kernel_mods/hello.c:21: warning: type defaults to âintâ in declaration of âMODULE_LICENSEâ
/usr/local/src/kernel_mods/hello.c:21: warning: function declaration isnât a prototype
/usr/local/src/kernel_mods/hello.c:22: error: expected declaration specifiers or â...â before string constant
/usr/local/src/kernel_mods/hello.c:22: warning: data definition has no type or storage class
/usr/local/src/kernel_mods/hello.c:22: warning: type defaults to âintâ in declaration of âMODULE_AUTHORâ
/usr/local/src/kernel_mods/hello.c:22: warning: function declaration isnât a prototype
/usr/local/src/kernel_mods/hello.c:23: error: expected declaration specifiers or â...â before string constant
/usr/local/src/kernel_mods/hello.c:23: warning: data definition has no type or storage class
/usr/local/src/kernel_mods/hello.c:23: warning: type defaults to âintâ in declaration of âMODULE_DESCRIPTIONâ
/usr/local/src/kernel_mods/hello.c:23: warning: function declaration isnât a prototype
make[2]: *** [/usr/local/src/kernel_mods/hello.o] Error 1
make[1]: *** [_module_/usr/local/src/kernel_mods] Error 2
make[1]: Leaving directory `/usr/src/kernels/2.6.32-220.el6.x86_64'
make: *** [all] Error 2
I think you meant to do
#include <linux/module.h>
rather than
#include <linux/modules.h>

How to compile driver to be profiled with Gprof

Simple question.. how to compile driver to be profiled with Gprof?
My current Makefile:
obj-m += hello-2.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
Works just fine ( I can load the driver etc. ), but if I try to add -pg options to the file then I get an error.
Makefile:
obj-m += hello-2.o
EXTRA_CFLAGS += -pg
LDFLAGS += -pg
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
I get error:
make -C /lib/modules/2.6.31/build M=/home/I/drivertest modules
make[1]: Entering directory `/home/I/linux-2.6.31'
CC [M] /home/I/drivertest/hello-2.o
Building modules, stage 2.
MODPOST 1 modules
WARNING: "mcount" [/home/I/drivertest/hello-2.ko] undefined!
CC /home/I/drivertest/hello-2.mod.o
LD [M] /home/I/drivertest/hello-2.ko
ld: unrecognized option '-pg'
ld: use the --help option for usage information
make[2]: *** [/home/I/drivertest/hello-2.ko] Error 1
make[1]: *** [modules] Error 2
make[1]: Leaving directory `/home/I/linux-2.6.31'
make: *** [all] Error 2
You can't profile a kernel module with gprof. You'll need to compile a kernel with profiling support enabled and use the readprofile tool. See the the Linux kernel documentation for more details.
Even if you can use gprof on a kernel module, it was never advertised as being able to help you locate bottlenecks. More on that.
-pg is a compilation flag, not a linkage flag. Remove it from LDFLAGS (and obviously leave it in EXTRA_CFLAGS).

Resources