How to properly integrate the pvs-studio into the kernel module makefile?

411 views Asked by At

I'm going to check the simple open-source driver using pvc-studio and so far it does not work out. My system is Debian 4.6.0-amd64. I'm use native x86_64 gcc compiler.

Running with the commands

pvs-studio-analyzer trace -- make; pvs-studio-analyzer analyze -o ./app.log

prints out No compilation units found.

I tried to embed the call in the makefile as follows:

CURRENT = $(shell uname -r)
KDIR = /lib/modules/$(CURRENT)/build
PWD = $(shell pwd)
DEST = /lib/modules/$(CURRENT)/misc

PARAMS = -I/usr/src/linux-headers-4.6.0-1-common/include -I/usr/src/linux-headers-4.6.0-1-amd64/include

TARGET1 = file1
TARGET2 = file2

obj-m   := $(TARGET1).o $(TARGET2).o

all: default clean
default: file1.c file2.c
    pvs-studio --cfg ~/pvs.cfg --source-file $< --cl-params $(CFLAGS) $(PARAMS) $<
    $(MAKE) -C $(KDIR) M=$(PWD) modules

...

As a result, I received many error messages in the style of No such file or directory related to the kernel header files.

My .cfg file:

exclude-path = /usr/include/
exclude-path = /usr/src/linux-headers-4.6.0-1-amd64/include
exclude-path = /usr/src/linux-headers-4.6.0-1-common/include
platform = linux64
preprocessor = gcc
analysis-mode=4
language = C

What I do wrong? How to do it correctly?

1

There are 1 answers

0
Svyatoslav Razmyslov On BEST ANSWER

To check the project it is possible to use pvs-studio-analyzer utility or intergarte analyzer (pvs-studio) directly into a build system, but not two options simultaneously.

  1. pvs-studio-analyzer

No compilation units found

After the tracing command a strace_out file is created in the current directory. You have to make sure that in this file there are commands of file compilation. If you found the necessary command, and the compiler name has the unusual title, it can be pointed using parameter --compiler:

pvs-studio-analyzer analyze ... --compiler COMPILER_NAME ...

If a file for tracing doesn't contain compilation commands, if it is necessary to check if the project compilation is being performed. Perhaps, it is needed to firstly perform a command make clean.

  1. When integrating into Makefile the analyzer also needs the information about the compiler.

By default the compiler is taken from environment variables CC/CXX. In the given example they are not declared, as I see.

If some header files are not found, it is needed to add paths to them to the --cl-params parameter.

Configuration file is arranged right. Try to take into account my recommendations and run the analysis one more time.

Full documentation is available by link: "How to run PVS-Studio on Linux".