sparse: add sparse support
With this adding "-DSPARSE=y" to the "west build" command line performs a sparse check of the project build. So far only gcc-based builds are supported. Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
This commit is contained in:
parent
725ce535f2
commit
7a85ff7683
5 changed files with 45 additions and 2 deletions
|
@ -267,6 +267,10 @@ if(CONFIG_COMPILER_COLOR_DIAGNOSTICS)
|
||||||
zephyr_compile_options($<TARGET_PROPERTY:compiler,diagnostic>)
|
zephyr_compile_options($<TARGET_PROPERTY:compiler,diagnostic>)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if("${SPARSE}" STREQUAL "y")
|
||||||
|
list(APPEND TOOLCHAIN_C_FLAGS -D__CHECKER__)
|
||||||
|
endif()
|
||||||
|
|
||||||
zephyr_compile_options(
|
zephyr_compile_options(
|
||||||
${TOOLCHAIN_C_FLAGS}
|
${TOOLCHAIN_C_FLAGS}
|
||||||
)
|
)
|
||||||
|
|
|
@ -5,7 +5,14 @@ set_ifndef(C++ g++)
|
||||||
# Configures CMake for using GCC, this script is re-used by several
|
# Configures CMake for using GCC, this script is re-used by several
|
||||||
# GCC-based toolchains
|
# GCC-based toolchains
|
||||||
|
|
||||||
find_program(CMAKE_C_COMPILER ${CROSS_COMPILE}${CC} PATHS ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
|
if("${SPARSE}" STREQUAL "y")
|
||||||
|
find_program(CMAKE_C_COMPILER cgcc)
|
||||||
|
find_program(REAL_CC ${CROSS_COMPILE}${CC} PATHS ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
|
||||||
|
set(ENV{REAL_CC} ${REAL_CC})
|
||||||
|
else()
|
||||||
|
find_program(CMAKE_C_COMPILER ${CROSS_COMPILE}${CC} PATHS ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
|
||||||
|
endif()
|
||||||
|
|
||||||
if(${CMAKE_C_COMPILER} STREQUAL CMAKE_C_COMPILER-NOTFOUND)
|
if(${CMAKE_C_COMPILER} STREQUAL CMAKE_C_COMPILER-NOTFOUND)
|
||||||
message(FATAL_ERROR "C compiler ${CROSS_COMPILE}${CC} not found - Please check your toolchain installation")
|
message(FATAL_ERROR "C compiler ${CROSS_COMPILE}${CC} not found - Please check your toolchain installation")
|
||||||
endif()
|
endif()
|
||||||
|
|
|
@ -66,6 +66,12 @@ macro(configure_linker_script linker_script_gen linker_pass_define)
|
||||||
zephyr_get_include_directories_for_lang(C current_includes)
|
zephyr_get_include_directories_for_lang(C current_includes)
|
||||||
get_property(current_defines GLOBAL PROPERTY PROPERTY_LINKER_SCRIPT_DEFINES)
|
get_property(current_defines GLOBAL PROPERTY PROPERTY_LINKER_SCRIPT_DEFINES)
|
||||||
|
|
||||||
|
if("${SPARSE}" STREQUAL "y")
|
||||||
|
set(ld_command ${REAL_CC})
|
||||||
|
else()
|
||||||
|
set(ld_command ${CMAKE_C_COMPILER})
|
||||||
|
endif()
|
||||||
|
|
||||||
add_custom_command(
|
add_custom_command(
|
||||||
OUTPUT ${linker_script_gen}
|
OUTPUT ${linker_script_gen}
|
||||||
DEPENDS
|
DEPENDS
|
||||||
|
@ -74,7 +80,7 @@ macro(configure_linker_script linker_script_gen linker_pass_define)
|
||||||
${extra_dependencies}
|
${extra_dependencies}
|
||||||
# NB: 'linker_script_dep' will use a keyword that ends 'DEPENDS'
|
# NB: 'linker_script_dep' will use a keyword that ends 'DEPENDS'
|
||||||
${linker_script_dep}
|
${linker_script_dep}
|
||||||
COMMAND ${CMAKE_C_COMPILER}
|
COMMAND ${ld_command}
|
||||||
-x assembler-with-cpp
|
-x assembler-with-cpp
|
||||||
${NOSYSDEF_CFLAG}
|
${NOSYSDEF_CFLAG}
|
||||||
-MD -MF ${linker_script_gen}.dep -MT ${linker_script_gen}
|
-MD -MF ${linker_script_gen}.dep -MT ${linker_script_gen}
|
||||||
|
|
|
@ -9,3 +9,4 @@ Testing
|
||||||
ztest
|
ztest
|
||||||
twister
|
twister
|
||||||
coverage
|
coverage
|
||||||
|
sparse
|
||||||
|
|
25
doc/develop/test/sparse.rst
Normal file
25
doc/develop/test/sparse.rst
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
.. _sparse:
|
||||||
|
|
||||||
|
Sparse support
|
||||||
|
##############
|
||||||
|
|
||||||
|
`Sparse <https://kernelnewbies.org/Sparse>`__ is a static code analysis tool.
|
||||||
|
Apart from performing common code analysis tasks it also supports an
|
||||||
|
``address_space`` attribute, which allows introduction of distinct address
|
||||||
|
spaces in C code with subsequent verification that pointers to different
|
||||||
|
address spaces do not get confused. Additionally it supports a ``force``
|
||||||
|
attribute which should be used to cast pointers between different address
|
||||||
|
spaces. At the moment Zephyr introduces a single custom address space
|
||||||
|
``__cache`` used to identify pointers from the cached address range on the
|
||||||
|
Xtensa architecture. This helps identify cases where cached and uncached
|
||||||
|
addresses are confused.
|
||||||
|
|
||||||
|
Running with sparse
|
||||||
|
*******************
|
||||||
|
|
||||||
|
To run a sparse verification build :ref:`west build <west-building>` should be
|
||||||
|
called with a `-DSPARSE=y` parameter, e.g.
|
||||||
|
|
||||||
|
.. code-block:: shell
|
||||||
|
|
||||||
|
west build -d hello -b intel_adsp_cavs25 zephyr/samples/hello_world -- -DSPARSE=y
|
Loading…
Add table
Add a link
Reference in a new issue