1*49cdfc7eSAndroid Build Coastguard Worker# Sparse based linting 2*49cdfc7eSAndroid Build Coastguard Worker 3*49cdfc7eSAndroid Build Coastguard WorkerThis tool checks LTP test and library code for common problems. 4*49cdfc7eSAndroid Build Coastguard Worker 5*49cdfc7eSAndroid Build Coastguard Worker## Usage 6*49cdfc7eSAndroid Build Coastguard Worker 7*49cdfc7eSAndroid Build Coastguard WorkerIt is integrated with the LTP build system. Just run `make check` or 8*49cdfc7eSAndroid Build Coastguard Worker`make check-a_test01`, where `a_test01` is an arbitrary test 9*49cdfc7eSAndroid Build Coastguard Workerexecutable or object file. 10*49cdfc7eSAndroid Build Coastguard Worker 11*49cdfc7eSAndroid Build Coastguard Worker## Building 12*49cdfc7eSAndroid Build Coastguard Worker 13*49cdfc7eSAndroid Build Coastguard WorkerThe bad news is you must get and build Sparse[^1]. The good news is 14*49cdfc7eSAndroid Build Coastguard Workerthat this only takes a minute and the build system does it for 15*49cdfc7eSAndroid Build Coastguard Workeryou. Just try running `make check` as described above. 16*49cdfc7eSAndroid Build Coastguard Worker 17*49cdfc7eSAndroid Build Coastguard WorkerHowever if you want to reuse an existing Sparse checkout. Then you can 18*49cdfc7eSAndroid Build Coastguard Workerdo the following. Where `$SRC_PATH` is the path to the Sparse 19*49cdfc7eSAndroid Build Coastguard Workerdirectory. 20*49cdfc7eSAndroid Build Coastguard Worker 21*49cdfc7eSAndroid Build Coastguard Worker```sh 22*49cdfc7eSAndroid Build Coastguard Worker$ cd tools/sparse 23*49cdfc7eSAndroid Build Coastguard Worker$ make SPARSE_SRC=$SRC_PATH 24*49cdfc7eSAndroid Build Coastguard Worker``` 25*49cdfc7eSAndroid Build Coastguard WorkerYou can also manually fetch it via the git submodule 26*49cdfc7eSAndroid Build Coastguard Worker 27*49cdfc7eSAndroid Build Coastguard Worker```sh 28*49cdfc7eSAndroid Build Coastguard Worker$ cd tools/sparse 29*49cdfc7eSAndroid Build Coastguard Worker$ git submodule update --init 30*49cdfc7eSAndroid Build Coastguard Worker``` 31*49cdfc7eSAndroid Build Coastguard Worker 32*49cdfc7eSAndroid Build Coastguard Worker### Modifying CFLAGS and -m32 33*49cdfc7eSAndroid Build Coastguard Worker 34*49cdfc7eSAndroid Build Coastguard WorkerWhen compiling the LTP with `-m32` it may break building 35*49cdfc7eSAndroid Build Coastguard Worker`sparse-ltp`. We do not pass LTP's `CFLAGS` or `HOST_CFLAGS` to 36*49cdfc7eSAndroid Build Coastguard Worker`libsparse.a`. In the best case it produces a lot of noise, in the 37*49cdfc7eSAndroid Build Coastguard Workerworst it breaks building anyway. 38*49cdfc7eSAndroid Build Coastguard Worker 39*49cdfc7eSAndroid Build Coastguard WorkerTo avoid issues with m32, just pre-build the checker with a non-m32 40*49cdfc7eSAndroid Build Coastguard Workerconfig. It won't need to be built again unless you are modifying the 41*49cdfc7eSAndroid Build Coastguard Workertool itself. Similar issues with cross-compiling could be handled in a 42*49cdfc7eSAndroid Build Coastguard Workersimilar way. Simply pre-build `sparse-ltp` and `libsparse.a` with a separate 43*49cdfc7eSAndroid Build Coastguard Workerconfig. 44*49cdfc7eSAndroid Build Coastguard Worker 45*49cdfc7eSAndroid Build Coastguard Worker### Clang 46*49cdfc7eSAndroid Build Coastguard Worker 47*49cdfc7eSAndroid Build Coastguard WorkerNote that while it is possible to build Sparse with Clang. This may 48*49cdfc7eSAndroid Build Coastguard Workercause some issues. Namely `GCC_BASE` is set to the Clang resource 49*49cdfc7eSAndroid Build Coastguard Workerdirectory. This contains some headers Sparse can not parse. 50*49cdfc7eSAndroid Build Coastguard Worker 51*49cdfc7eSAndroid Build Coastguard Worker[1]: Many distributions have a Sparse package. This only contains some executables. There is no shared library 52