Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiler Options Hardening #72488

Open
6 of 24 tasks
pdgendt opened this issue May 8, 2024 · 2 comments
Open
6 of 24 tasks

Compiler Options Hardening #72488

pdgendt opened this issue May 8, 2024 · 2 comments
Assignees
Labels
area: Toolchains Toolchains Enhancement Changes/Updates/Additions to existing features

Comments

@pdgendt
Copy link
Collaborator

pdgendt commented May 8, 2024

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

  • -Wall
  • -Wdouble-promotion
  • -Wexpansion-to-defined
  • -Wformat
  • -Wpointer-arith

Exceptions

  • -Wno-pointer-sign

Level 1

  • -Waggregate-return
  • -Wcast-align
  • -Wconversion
  • -Wdisabled-optimization
  • -Wimplicit-fallthrough
  • -Wlogical-op
  • -Wmissing-field-initializers
  • -Wnested-externs
  • -Wshadow

Optionally go for -Wextra

Level 2

  • -Wbad-function-cast
  • -Wcast-qual
  • -Wpacked
  • -Wpadded
  • -Wpointer-arith
  • -Wredundant-decls
  • -Wswitch-default
  • -Wpacked-bitfield-compat
  • -Wvla

Level 3

TODO

@pdgendt pdgendt added the Enhancement Changes/Updates/Additions to existing features label May 8, 2024
@RichardSWheatley
Copy link
Contributor

RichardSWheatley commented May 9, 2024

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
Copy link
Collaborator Author

pdgendt commented May 15, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Toolchains Toolchains Enhancement Changes/Updates/Additions to existing features
Projects
None yet
Development

No branches or pull requests

7 participants