Enable uninitialized variable checking (and other lost CFLAGS) for mosys |
|||||||
Issue descriptionCL [0] recently broke mosys at runtime by introducing a code path where a function could return the value of an automatic variable that was never initialized. [0]: https://chromium-review.googlesource.com/c/chromiumos/platform/mosys/+/1176090 Typically this kind of thing would be detected by the compiler flag "-Wuninitialized" [1] which would throw a warning, which itself would generate an error when -Werror is enabled. [1] https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html It appears that for mosys this flag is not enabled. It is, in fact, possible to manually set this on the command line when building via emerge: CFLAGS="-Wuninitialized" emerge-grunt mosys [153/275] x86_64-cros-linux-gnu-clang -Wuninitialized -Imosys@sta -I. -I../mosys-9999 -I../mosys-9999/include -I/build/grunt/usr/include/uuid -Xclang -fcolor-diagnostics -pipe -D_FILE_OFFSET_BITS=64 -include config.h -std=gnu99 -Wno-address-of-packed-member -Werror -fPIC -MMD -MQ 'mosys@sta/platform_glados_glados.c.o' -MF 'mosys@sta/platform_glados_glados.c.o.d' -o 'mosys@sta/platform_glados_glados.c.o' -c ../mosys-9999/platform/glados/glados.c FAILED: mosys@sta/platform_glados_glados.c.o x86_64-cros-linux-gnu-clang -Wuninitialized -Imosys@sta -I. -I../mosys-9999 -I../mosys-9999/include -I/build/grunt/usr/include/uuid -Xclang -fcolor-diagnostics -pipe -D_FILE_OFFSET_BITS=64 -include config.h -std=gnu99 -Wno-address-of-packed-member -Werror -fPIC -MMD -MQ 'mosys@sta/platform_glados_glados.c.o' -MF 'mosys@sta/platform_glados_glados.c.o.d' -o 'mosys@sta/platform_glados_glados.c.o' -c ../mosys-9999/platform/glados/glados.c ../mosys-9999/platform/glados/glados.c:120:6: error: variable 'ret' is used uninitialized whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized] if (!cros_config_smbios_platform_name_match(intf, "Nautilus")) { ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../mosys-9999/platform/glados/glados.c:141:9: note: uninitialized use occurs here return ret; ^~~ ../mosys-9999/platform/glados/glados.c:120:2: note: remove the 'if' if its condition is always true if (!cros_config_smbios_platform_name_match(intf, "Nautilus")) { ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../mosys-9999/platform/glados/glados.c:108:9: note: initialize the variable 'ret' to silence this warning int ret; ^ = 0 1 error generated. So, let's configure the mosys meson build to enable this (and any other important) compiler flags.
,
Aug 20
,
Aug 21
Issue 876142 has been merged into this issue.
,
Aug 21
closing out b/112856903 in favor of this.
,
Aug 21
It's set here: https://chromium.git.corp.google.com/chromiumos/platform/mosys/+/8cc37a3e53e43308e0eacbafb424b6607f88a62f/meson.build?pli=1#42 . If you want to turn on more warnings, that's how it would be done. -Wall could only exist when -Werror wasn't enabled and is too aggressive in a world in which -Werror is turned on: any toolchain upgrade would certainly break mosys as new warnings are introduced. -Werror was added by Brian Norris in issue 838349 . Someone will need to come up with a list of the warnings that we want to enable that aren't enabled by default.
,
Aug 21
we should be using -Werror -Wall by default. you are certainly correct that toolchain upgrades can break things, but that isn't an issue for us: all of platform2/ and many other platform/ projects (including firmware) have long been built with -Werror, and the toolchain team knows that when they do an upgrade, they have to build all the packages and make sure new warnings are fixed before they actually upgrade.
,
Aug 21
I'm happy to add what ever flags people want/need (they are easy to add to the Meson build file at least). I asked Jason to take a look at this issue though because I've never set compiler flags manually like this so I don't know what to add.
,
Aug 21
I'd recommend restoring the ones that were lost during the transition from Kbuild: -KBUILD_CFLAGS := -Wall -Wundef -Wstrict-prototypes \ - -Werror-implicit-function-declaration \ - -Werror=format-security \ - -fPIC
,
Aug 21
in open source projects, people who use -Werror/etc... put them behind build flags so people can build by disabling them at configure/meson time. whether we need to go that far for mosys is up to you, but i don't think anyone outside of CrOS ever really picked up the mosys tool. building off of Dan's comment, my suggestion would be to use: -Wall -Werror -Wundef -Wstrict-prototypes the other flags should be implied by -Wall and -Werror
,
Aug 21
agreed with #8 and #9. It's a shame the compiler flags were lost in the transition.
,
Aug 21
#9 I'll work up a CL with -Wall -Werror -Wundef -Wstrict-prototypes, thank you for the pointers!
,
Aug 24
The following revision refers to this bug: https://chromium.googlesource.com/chromiumos/platform/mosys/+/5ec537f409df8534096f228e62e4be1ef6f683a9 commit 5ec537f409df8534096f228e62e4be1ef6f683a9 Author: Alec Thilenius <athilenius@google.com> Date: Fri Aug 24 00:43:04 2018 Adds a few clang flags to mosys meson.build file Adds the clang flags -Wall -Werror -Wundef -Wstrict-prototypes to the meson.build file for Mosys, which will enable more strict compile-time checks for C code. BUG= chromium:876106 TEST=emerge-coral sys-apps/mosys Change-Id: I4b1d12f1c4e0a091c104d95f72e30652a696520a Reviewed-on: https://chromium-review.googlesource.com/1185781 Commit-Ready: Jason Clinton <jclinton@chromium.org> Tested-by: Alec Thilenius <athilenius@google.com> Reviewed-by: Mike Frysinger <vapier@chromium.org> [modify] https://crrev.com/5ec537f409df8534096f228e62e4be1ef6f683a9/meson.build
,
Aug 27
,
Aug 29
The following revision refers to this bug: https://chromium.googlesource.com/chromiumos/platform/mosys/+/13fb1aac8dec52f72158a4fbd2919a3c16bd44c0 commit 13fb1aac8dec52f72158a4fbd2919a3c16bd44c0 Author: Douglas Anderson <dianders@chromium.org> Date: Wed Aug 29 18:15:15 2018 Revert "Adds a few clang flags to mosys meson.build file" This reverts commit 5ec537f409df8534096f228e62e4be1ef6f683a9. This commit is needed to make the code compile after the next revert. BUG= chromium:878145 , chromium:876106 TEST=mosys is no longer accessing /dev/mem Fixes: d402d8411b36 ("mosys: Add integration test") Change-Id: I9d87c746478dc2ab7aa26d8906972923a10b4056 Signed-off-by: Douglas Anderson <dianders@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1194283 Reviewed-by: Guenter Roeck <groeck@chromium.org> Reviewed-by: Evan Green <evgreen@chromium.org> [modify] https://crrev.com/13fb1aac8dec52f72158a4fbd2919a3c16bd44c0/meson.build
,
Aug 30
This was ninja-reverted, reopening.
,
Sep 5
The following revision refers to this bug: https://chromium.googlesource.com/chromiumos/platform/mosys/+/4f88fa305562bb9bf6e0d17bf29965278d2f4a03 commit 4f88fa305562bb9bf6e0d17bf29965278d2f4a03 Author: Jason D. Clinton <jclinton@chromium.org> Date: Wed Sep 05 23:11:15 2018 Reland "Adds a few clang flags to mosys meson.build file" This reverts commit 13fb1aac8dec52f72158a4fbd2919a3c16bd44c0. All warning should be fixed now. BUG= chromium:876106 TEST=trybots Change-Id: I76eff978c34db944382c35bca976d64ce068bfa5 Reviewed-on: https://chromium-review.googlesource.com/1194801 Commit-Ready: Jason Clinton <jclinton@chromium.org> Tested-by: Jason Clinton <jclinton@chromium.org> Reviewed-by: Jason Clinton <jclinton@chromium.org> Reviewed-by: Alec Thilenius <athilenius@google.com> [modify] https://crrev.com/4f88fa305562bb9bf6e0d17bf29965278d2f4a03/lib/cros_config/cros_config.c [modify] https://crrev.com/4f88fa305562bb9bf6e0d17bf29965278d2f4a03/meson.build
,
Sep 6
|
|||||||
►
Sign in to add a comment |
|||||||
Comment 1 by djkurtz@google.com
, Aug 20