zephyrproject-rtos / zephyr

Primary Git Repository for the Zephyr Project. Zephyr is a new generation, scalable, optimized, secure RTOS for multiple hardware architectures.
https://docs.zephyrproject.org
Apache License 2.0
9.99k stars 6.15k forks source link

Compiler Options Hardening #72488

Open pdgendt opened 1 month ago

pdgendt commented 1 month ago

Is your enhancement proposal related to a problem? Please describe. Enabling compiler warning options and treating them as errors is in many cases not an easy task, and not a one-man-show. This issue is to track compiler options that could become default enabled, to be verified in CI.

A recent article sums up nicely what this can entail: https://best.openssf.org/Compiler-Hardening-Guides/Compiler-Options-Hardening-Guide-for-C-and-C++.html

Describe the solution you'd like

  1. List the desired compiler options by level, for example [base=0, must-have=1, nice-to-have=2, uncommon=3]
  2. Enable warnings for the next level
  3. Engage the community in fixing the warnings
  4. Repeat from 2.

Describe alternatives you've considered There is a Kconfig option CODING_GUIDELINE_CHECK (see #71493) but this triggers too many warnings at once, and instead of trying to fix the world we should go step by step.

Additional context This issue is created as discussed by the process working group to track compiler related options.

Proposal WIP

These are loosely based on the current GCC toolchain flags in-tree.

Base

Exceptions

Level 1

Optionally go for -Wextra

Level 2

Level 3

TODO

RichardSWheatley commented 1 month ago

Using the link you attached, it looks like they split them between compile-time and run-time. Could we make them groups and keep the compile-time and run-time separated with subgroups?

@pdgendt what do you think?

pdgendt commented 1 month ago

Using the link you attached, it looks like they split them between compile-time and run-time. Could we make them groups and keep the compile-time and run-time separated with subgroups?

I still need to invest some time in the options and what they do, if someone has proposals on how to group, that would be very helpful. I have limited bandwidth, so it will take some time to make progress.