Jump to: navigation, search

Sparse is a static type-checking program written specifically for the Linux kernel, written by Linus Torvalds. Support for running sparse is in the kernel build system.

That is, you can type "make C=1" and sparse will be executed on the C files that would be compiled. Type "make C=2" to run sparse on all C files in the kernel source tree.

Usage notes from Randy Dunlap

From the "Quick sparse HOWTO, by Randy Dunlap: (located at

Quick sparse HOWTO
Randy Dunlap

in kernel tree, 'make help' says:

  make C=1   [targets] Check all c source with checker tool

To build & install sparse:

"checker tool" is built as "check" but then installed as "sparse".

a.  unpack the tarball or export the bk tree
b.  cd path/to/sparse
c.  make
d.  make install     # default location is in user's $HOME/bin

...then do your target build, e.g.,

make allmodconfig     # or defconfig or whatever
make C=1 all >build.out 2>&1     # to capture all messages


Usage notes from Linus Torvalds

Linus said:

>>[Where to get sparse? I tried to google for it but "sparse" is
>> very common word (as in sparse matrix). And theres no
>> kernel/people/linus on]


If you search for "sparse checker linux" you'll find a number of hits..

Once you have it, just do

    make install

as your regular user, and it will install sparse in your ~/bin directory. 
After that, doing a kernel make with "make C=1" will run sparse on all the 
C files that get recompiled, or with "make C=2" will run sparse on the 
files whether they need to be recompiled or not (ie the latter is fast way 
to check the whole tree if you have already built it).

Use sparse on a C normal project

Running sparse on a C project is quite easy if you use the cgcc wrapper script installed with the sparse package. Just call cgcc instead of your normal gcc.

For make use

make CC=cgcc

With configure use

./configure CC=cgcc