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).
Related
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.
I have to write a simple linux kernel module for a study research project, but I am having trouble with make. This is what my Makefile looks like right now:
obj-m := main.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
The source file I want to compile is named main.c, and when I type make in the source code directory I get this output:
root#debian:~/test-module# make
make -C /lib/modules/4.9.0-4-amd64/build M=/root/test-module modules
make[1]: Entering directory '/lib/modules/4.9.0-4-amd64/build'
make[1]: *** No rule to make target 'modules'. Stop.
make[1]: Leaving directory '/lib/modules/4.9.0-4-amd64/build'
Makefile:6: recipe for target 'all' failed
make: *** [all] Error 2
As the output already suggests, I am running Debian 9 with kernel 4.9.0-4-amd64. Since I am pretty new to Makefiles, I can't find any errors in the file. Could somebody please explain to me where my error is?
UPDATE: After some research I found out that /lib/modules/4.9.0-4-amd64/build must contain the kernel source tree. So i did
ln -s /usr/src/linux-source-4.9 /lib/modules/4.9.0-4-amd64/build
where the link's target directory contains the complete linux kernel source tree. When I run make now, I get this output:
root#debian:~/test-module# make
make -C /lib/modules/4.9.0-4-amd64/build modules
make[1]: Entering directory '/usr/src/linux-source-4.9'
scripts/kconfig/conf --silentoldconfig Kconfig
***
*** Configuration file ".config" not found!
***
*** Please run some configurator (e.g. "make oldconfig" or
*** "make menuconfig" or "make xconfig").
***
scripts/kconfig/Makefile:37: recipe for target 'silentoldconfig' failed
make[3]: *** [silentoldconfig] Error 1
Makefile:548: recipe for target 'silentoldconfig' failed
make[2]: *** [silentoldconfig] Error 2
The present kernel configuration has modules disabled.
Type 'make config' and enable loadable module support.
Then build a kernel with module support enabled.
Makefile:1271: recipe for target 'modules' failed
make[1]: *** [modules] Error 1
make[1]: Leaving directory '/usr/src/linux-source-4.9'
Makefile:4: recipe for target 'all' failed
make: *** [all] Error 2
Looks better than last time, but still doesn't work. I guess I just have to run a make config or so in some directory of the kernel source tree, but I don't know where. What should I do?
I finally found out the error: I forgot to specify the M variable in my makefile. It works properly now. This is what my makefile looks like right now, if future users want to know:
obj-m := testmodule.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
Thank you all for your help anyways!
I am trying to build a demo kernel module, but when I do make, I get following,
make[1]: Entering directory '/usr/src/linux-headers-4.4.0-47-generic'
make[2]: *** No rule to make target 'arch/x86/entry/syscalls/syscall_32.tbl', needed by 'arch/x86/entry/syscalls/../../include/generated/asm/syscalls_32.h'. Stop.
arch/x86/Makefile:199: recipe for target 'archheaders' failed
make[1]: *** [archheaders] Error 2
make[1]: Leaving directory '/usr/src/linux-headers-4.4.0-47-generic'
Makefile:4: recipe for target 'all' failed
I am building module across linux kernel - 4.4.0-47 version - 64 bit OS. Can anyone please help me to understand why I am facing this Error.Thank you in advance.
Make sure you have proper make file. this is a very common issue.
or you could use below statement in makefile also.
obj-m += your_module_name.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
it should work.
I'm trying to cross compile a helloworld kernel (2.6.x) module for ARM architecture on my intel x86 host.
The tool chain for ARM is located at: /home/vivek/ti-sdk-am335x-evm-05.07.00.00/linux-devkit/bin
The kernel source is located at: /home/vivek/Arago
The hellow.c and Makefile are located on Desktop on /home/vivek/Desktop/hellodriver
I have given the path for cross compiler as /home/vivek/ti-sdk-am335x-evm-05.07.00.00/linux-devkit/bin
My Makefile is follows:-
export ARCH=arm
export CROSS_COMPILE=arm-arago-linux-gnueabi-
obj-m =Hello.o
KDIR =/home/vivek/Arago
PWD = $(shell pwd)
default:
$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
clean:
$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) clean
On executing make I am getting
vivek#ubuntu:~/Desktop/hellodriver$ make
make: Nothing to be done for `default'.
What am I doing wrong?
There is mistake in your Makefile. As your source code name is hellow.c, But in your Makefile its Hello.o.
So change your obj-m =Hello.o to obj-m =hellow.o
And one more thing Etan Reisner said above make sure you using Tab for command in Makefile.
I wrote a Hello-world module, and built Make file to compile it.
Makefile source code:
obj-m +=hello-1.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
compiling the module by issuing the command make give me the following result
make -C /lib/modules/3.3.4-5.fc17.i686/build M=/home/user/MyModules/hello-1 modules
make: *** /lib/modules/3.3.4-5.fc17.i686/build: No such file or directory. Stoped.
make: *** [all] Error 2
enter code here
While the file is actually Exist!
Why Makefile can't find the file?
Note: I'm using fedora 17