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