⇤ ← Revision 1 as of 2013-09-30 18:29:03
Size: 3875
Comment:
|
Size: 4240
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 1: | Line 1: |
= WHAT IS SPARSE = |
|
Line 5: | Line 3: |
by kernel developers using __attribute__ specifiers. Sparse tool uses these specifiers to pinpoint coding mistakes. |
by kernel developers using the 'attribute' specifiers. Sparse tool uses these specifiers to pinpoint coding mistakes. |
Line 8: | Line 6: |
= HOW TO INSTALL SPARSE = | == How to install sparse == |
Line 11: | Line 9: |
distro. That way, in case you want later to uninstall sparse, you won't need to cleanup executable files manually. |
distribution. That way, in case you want later to uninstall it, you won't need to cleanup the executable files manually. |
Line 21: | Line 19: |
Line 24: | Line 23: |
For example, if you use Arch linux, you can download the package from AUR: https://aur.archlinux.org/packages/sparse/ There, you will find a link from where you can download the sparse source code: |
For example, if you use Arch linux, you can download the sparse source code from [https://aur.archlinux.org/packages/sparse/ AUR]. In the above link, you will find a link from where you can download the most recent version of sparse source code. |
Line 30: | Line 30: |
$ tar -xzvf sparse-0.4.4.tar.gz | {{{ $ tar -xzvf sparse-0.4.4.tar.gz}}} |
Line 32: | Line 34: |
$ cd sparse-0.4.4/ Now, you need to create a file, called PKGBUILD, and copy the contents of the PKGBUILD file found in AUR. To create the package, do: $ makepkg -s |
{{{ $ cd sparse-0.4.4/}}} Now, you need to create a file, called PKGBUILD, and copy the contents of the PKGBUILD file found in [https://aur.archlinux.org/packages/sparse/ AUR]. After creating PKGBUILD, you can build the package doing: {{{ $ makepkg -s}}} |
Line 38: | Line 44: |
$ sudo pacman -U <package_name>.pkg.tar.gz To unistall it, do: $ sudo pacman -R sparse |
{{{ $ sudo pacman -U <package_name>.pkg.tar.gz}}} |
Line 42: | Line 47: |
To install sparse manually follow the steps below. You can download sparse from the following git repository: git://git.kernel.org/pub/scm/devel/sparse/sparse.git |
If you want later to uninstall it, do: {{{ $ sudo pacman -R sparse}}} |
Line 46: | Line 51: |
By doing: $ git clone git://git.kernel.org/pub/scm/devel/sparse/sparse.git |
=== Manual installation from sparse git repository === |
Line 49: | Line 53: |
This will create in your current directory a subdirectory, called 'sparse', which contains the sparse source code. |
You can download sparse from git://git.kernel.org/pub/scm/devel/sparse/sparse.git doing: {{{ $ git clone git://git.kernel.org/pub/scm/devel/sparse/sparse.git}}} This will create in your current directory a subdirectory, called 'sparse', which contains the sparse source code. |
Line 53: | Line 60: |
$ cd sparse | {{{ $ cd sparse}}} |
Line 56: | Line 64: |
$ git tag | {{{ $ git tag}}} |
Line 58: | Line 67: |
Choose the last stable release (v0.4.4) and update the files of the current sparse git tree to match this release: $ git checkout -b stable v0.4.4 |
Choose the last stable release (v0.4.4) and update the files of the current sparse git tree to match this release: {{{ $ git checkout -b stable v0.4.4}}} |
Line 62: | Line 71: |
The above command creates a new branch, named 'stable', which refers to the tagged commit 'v0.4.4' and then updates the tree to refer to this branch. |
The above command creates a new branch, named 'stable', which refers to the tagged commit 'v0.4.4' and then updates the tree to refer to this branch. |
Line 66: | Line 74: |
$ make | {{{ $ make}}} |
Line 68: | Line 77: |
To install it, set in the Makefile the desirable destination directoty for the installation by changing the line PREFIX=$(HOME). For instance, you can change it into PREFIX=$(HOME)/sparse or PREFIX=/usr and then, to install it do: $ make install |
To install it, set in the Makefile the desirable destination directoty for the installation by changing the line PREFIX=$(HOME). For instance, you can change it into PREFIX=$(HOME)/sparse or PREFIX=/usr and then, to install it do: {{{ $ make install}}} |
Line 74: | Line 82: |
If you have installed sparse, in a directory out of your executable search path, you need to setup the environmental variable PATH to include the directory in which sparse executable has been placed. |
If you have chosen to install sparse in a directory out of your executable search path, you need to setup the environmental variable PATH to include the path to the sparse executable. |
Line 79: | Line 86: |
$ export PATH=$PATH:$HOME/sparse/bin | {{{ $ export PATH=$PATH:$HOME/sparse/bin}}} |
Line 81: | Line 90: |
$ echo 'export PATH=$PATH:$HOME/sparse/bin' >> ~/.bashrc | {{{ $ echo 'export PATH=$PATH:$HOME/sparse/bin' >> ~/.bashrc}}} |
Line 84: | Line 94: |
$ which sparse | {{{ $ which sparse}}} |
Line 86: | Line 97: |
= HOW TO USE SPARSE = | == How to use sparse == |
Line 88: | Line 99: |
Choose a subdirectory in the kernel tree that you want to check for sparse warnings and errors, for instance drivers/staging/wlan-ng, and do: $ make C=2 drivers/staging/wlan-ng/ |
Choose a subdirectory in the kernel tree that you want to check for sparse warnings and errors, for instance that could be drivers/staging/wlan-ng, and do: {{{ $ make C=2 drivers/staging/wlan-ng/}}} |
Line 94: | Line 105: |
$ make C=2 CF="-D__CHECK_ENDIAN__" drivers/staging/wlan-ng/ | {{{ $ make C=2 CF="-D__CHECK_ENDIAN__" drivers/staging/wlan-ng/}}} The warnings produced indicate sites in code where types relevant to byteorder are mixed, possibly leading to buggy behavior. |
Line 98: | Line 112: |
{{{ | |
Line 100: | Line 115: |
}}} | |
Line 101: | Line 117: |
More documentation on sparse can be found in Documentation/sparse.txt and the links below: http://kernel.org/pub/software/devel/sparse/dist/sparse-0.4.tar.gz |
== Documentation == More documentation on sparse can be found in your kernel source under '''Documentation/sparse.txt''' and the links below: |
Line 105: | Line 122: |
Sparse is a tool for static code analysis that helps kernel developers to detect coding errors. Kernel code that is prone to mistakes is annotated by kernel developers using the 'attribute' specifiers. Sparse tool uses these specifiers to pinpoint coding mistakes.
How to install sparse
The best way to install sparse is using the package manager of your linux distribution. That way, in case you want later to uninstall it, you won't need to cleanup the executable files manually.
For instance, if you have Ubuntu, to install sparse do:
$ sudo apt-get install sparse
And, to remove it, do:
$ sudo apt-get remove sparse
If your distro does not provide a precompiled package for sparse, either you can create one or proceed with a manual installation.
For example, if you use Arch linux, you can download the sparse source code from [https://aur.archlinux.org/packages/sparse/ AUR].
In the above link, you will find a link from where you can download the most recent version of sparse source code.
http://www.kernel.org/pub/software/devel/sparse/dist/sparse-0.4.4.tar.gz
To decompress the sparse-0.4.4.tar.gz file, do:
$ tar -xzvf sparse-0.4.4.tar.gz
Then, enter sparse-0.4.4 directory:
$ cd sparse-0.4.4/
Now, you need to create a file, called PKGBUILD, and copy the contents of the PKGBUILD file found in [https://aur.archlinux.org/packages/sparse/ AUR].
After creating PKGBUILD, you can build the package doing:
$ makepkg -s
To install it, do:
$ sudo pacman -U <package_name>.pkg.tar.gz
If you want later to uninstall it, do:
$ sudo pacman -R sparse
Manual installation from sparse git repository
You can download sparse from git://git.kernel.org/pub/scm/devel/sparse/sparse.git doing:
$ git clone git://git.kernel.org/pub/scm/devel/sparse/sparse.git
This will create in your current directory a subdirectory, called 'sparse', which contains the sparse source code.
Enter sparse directory:
$ cd sparse
To see the available releases, do:
$ git tag
Choose the last stable release (v0.4.4) and update the files of the current sparse git tree to match this release:
$ git checkout -b stable v0.4.4
The above command creates a new branch, named 'stable', which refers to the tagged commit 'v0.4.4' and then updates the tree to refer to this branch.
To build sparse, do:
$ make
To install it, set in the Makefile the desirable destination directoty for the installation by changing the line PREFIX=$(HOME). For instance, you can change it into PREFIX=$(HOME)/sparse or PREFIX=/usr and then, to install it do:
$ make install
If you have chosen to install sparse in a directory out of your executable search path, you need to setup the environmental variable PATH to include the path to the sparse executable.
For instance, if you had set PREFIX=$(HOME)/sparse, do:
$ export PATH=$PATH:$HOME/sparse/bin
To setup permanently the path, do:
$ echo 'export PATH=$PATH:$HOME/sparse/bin' >> ~/.bashrc
To see if sparse can be successfully located, do:
$ which sparse
How to use sparse
Choose a subdirectory in the kernel tree that you want to check for sparse warnings and errors, for instance that could be drivers/staging/wlan-ng, and do:
$ make C=2 drivers/staging/wlan-ng/
You can use the variable CF to pass more checkflags to sparse. For example, you can enable endian checks doing:
$ make C=2 CF="-D__CHECK_ENDIAN__" drivers/staging/wlan-ng/
The warnings produced indicate sites in code where types relevant to byteorder are mixed, possibly leading to buggy behavior.
You can observe what are the default checkflags set in the Makefile. You will see something close to the following:
CHECKFLAGS := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ \ -Wbitwise -Wno-return-void $(CF)
Documentation
More documentation on sparse can be found in your kernel source under Documentation/sparse.txt and the links below: