Skip to content

Commit 3fc5d97

Browse files
Flavio Ceolincarlescufi
authored andcommitted
security: Add compiler static analysis support
Enable GCC builtin static analysis in Zephyr's static code analysis (SCA) infra. When this option is enabled GCC performs a static analysis and can point problems like: sample.c + int *j; + + if (j != NULL) { + printf("j != NULL\n"); output: ${ZEPHYR_BASE}/samples/userspace/hello_world_user/src/main.c:30:12: warning: use of uninitialized value 'j' [CWE-457] [-Wanalyzer-use-of-uninitialized-value] 30 | if (j != NULL) { | ^ 'main': events 1-2 | | 25 | int *j; | | ^ | | | | | (1) region created on stack here |...... | 30 | if (j != NULL) { | | ~ | | | | | (2) use of uninitialized value 'j' here Signed-off-by: Flavio Ceolin <[email protected]>
1 parent b27494b commit 3fc5d97

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

cmake/sca/gcc/sca.cmake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
#
3+
# Copyright (c) 2024 Intel Corporation
4+
5+
list(APPEND TOOLCHAIN_C_FLAGS -fanalyzer)

doc/develop/sca/gcc.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
.. _gcc:
2+
3+
GCC static analysis support
4+
###########################
5+
6+
Static analysis was introduced in `GCC <https://gcc.gnu.org/>`__ 10 and it is enabled
7+
with the option ``-fanalyzer``. This option performs a much more expensive and thorough
8+
analysis of the code than traditional warnings.
9+
10+
Run GCC static analysis
11+
***********************
12+
13+
To run GCC static analysis, :ref:`west build <west-building>` should be
14+
called with a ``-DZEPHYR_SCA_VARIANT=gcc`` parameter, e.g.
15+
16+
.. code-block:: shell
17+
18+
west build -b qemu_x86 samples/userspace/hello_world_user -- -DZEPHYR_SCA_VARIANT=gcc

doc/develop/sca/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,4 @@ The following is a list of SCA tools natively supported by Zephyr build system.
6363

6464
codechecker
6565
sparse
66+
gcc

0 commit comments

Comments
 (0)