New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 876106 link

Starred by 2 users

Issue metadata

Status: Fixed
Owner:
Closed: Sep 6
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: Chrome
Pri: 2
Type: Bug



Sign in to add a comment

Enable uninitialized variable checking (and other lost CFLAGS) for mosys

Project Member Reported by djkurtz@google.com, Aug 20

Issue description

CL [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.
 
It looks like when we used Makefiles, we were using the following CFLAGS
(see https://chromium-review.googlesource.com/1012530 for removal of Makefiles):


-KBUILD_CFLAGS   := -Wall -Wundef -Wstrict-prototypes \
-		   -Werror-implicit-function-declaration \
-		   -Werror=format-security \
-		   -fPIC

However, in the new meson world, I don't see how the CFLAGS are being set, but the result in a clang build line like:

[273/275] x86_64-cros-linux-gnu-clang -O2 -pipe -O2 -pipe -march=amdfam10 -g -fno-exceptions -fno-unwind-tables -fno-asynchronous-unwind-tables -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/lib_cros_config_cros_config.c.o' -MF 'mosys@sta/lib_cros_config_cros_config.c.o.d' -o 'mosys@sta/lib_cros_config_cros_config.c.o' -c ../mosys-9999/lib/cros_config/cros_config.c
Summary: Enable uninitialized variable checking (and other lost CFLAGS) for mosys (was: Enable uninitialized variable checking for mosys)
Cc: teravest@chromium.org adurbin@google.com shapiroc@chromium.org
 Issue 876142  has been merged into this issue.
closing out b/112856903 in favor of this.
Cc: briannorris@chromium.org
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.

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.
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.
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
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
agreed with #8 and #9. It's a shame the compiler flags were lost in the transition.
#9 I'll work up a CL with -Wall -Werror -Wundef -Wstrict-prototypes, thank you for the pointers!
Project Member

Comment 12 by bugdroid1@chromium.org, 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

Status: Fixed (was: Assigned)
Project Member

Comment 14 by bugdroid1@chromium.org, 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

Status: Assigned (was: Fixed)
This was ninja-reverted, reopening.
Project Member

Comment 16 by bugdroid1@chromium.org, 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

Status: Fixed (was: Assigned)

Sign in to add a comment