Skip to content

Commit d75a9ec

Browse files
committed
build: include -Wextra in generic builds
TF-A is more strict with compiler warnings in comparison to other projects (notably Linux) for security and -Wextra enables a lot of desirable warnings. This patch enables -Wextra by default (from W=1 previously) and reorganises the warning levels so that they can useful when enabled and not just a build failure. This will help us move towards fixing the warnings that are too many to fix at once and enabling all W={1, 2} warnings. The warning levels get new meanings: * W=1: warnings we want the generic build to include but are too time consuming to fix at the moment. They re-enable warnings taken out for generic builds. * W=2: warnings we want the generic build to include but cannot be enabled due to external libraries. * W=3: warnings that are informative but not necessary and generally too verbose and frequently ignored. Quality expectations for new contributions mean that generally they should have no warnings up to W=2. To allow code to be developed with them in mind, -Werror is disabled when W=x is set. This way enabling warnings will not just fail the build due to technicalities we have and contributors will be able to actually see if they get any. Signed-off-by: Boyan Karatotev <[email protected]> Change-Id: Ieb15ddd635d458a956a34b0f9d0ea2f81b9c0745
1 parent 228b06a commit d75a9ec

File tree

1 file changed

+36
-12
lines changed

1 file changed

+36
-12
lines changed

Makefile

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -350,27 +350,51 @@ ASFLAGS_aarch64 = $(march64-directive)
350350
# General warnings
351351
WARNINGS := -Wall -Wmissing-include-dirs -Wunused \
352352
-Wdisabled-optimization -Wvla -Wshadow \
353-
-Wno-unused-parameter -Wredundant-decls
353+
-Wredundant-decls
354+
# stricter warnings
355+
WARNINGS += -Wextra -Wno-trigraphs
356+
# too verbose for generic build
357+
WARNINGS += -Wno-missing-field-initializers \
358+
-Wno-type-limits -Wno-sign-compare \
359+
# on clang this flag gets reset if -Wextra is set after it. No difference on gcc
360+
WARNINGS += -Wno-unused-parameter
354361

355362
# Additional warnings
356-
# Level 1
357-
WARNING1 := -Wextra
358-
WARNING1 += -Wmissing-format-attribute
359-
WARNING1 += -Wmissing-prototypes
360-
WARNING1 += -Wold-style-definition
361-
362-
# Level 2
363-
WARNING2 := -Waggregate-return
364-
WARNING2 += -Wcast-align
365-
WARNING2 += -Wnested-externs
366-
363+
# Level 1 - infrequent warnings we should have none of
364+
# full -Wextra
365+
WARNING1 += -Wsign-compare
366+
WARNING1 += -Wtype-limits
367+
WARNING1 += -Wmissing-field-initializers
368+
369+
# Level 2 - problematic warnings that we want
370+
# zlib, compiler-rt, coreboot, and mbdedtls blow up with these
371+
# TODO: disable just for them and move into default build
372+
WARNING2 += -Wold-style-definition
373+
WARNING2 += -Wmissing-prototypes
374+
WARNING2 += -Wmissing-format-attribute
375+
# TF-A aims to comply with this eventually. Effort too large at present
376+
WARNING2 += -Wundef
377+
378+
# Level 3 - very pedantic, frequently ignored
367379
WARNING3 := -Wbad-function-cast
380+
WARNING3 += -Waggregate-return
381+
WARNING3 += -Wnested-externs
382+
WARNING3 += -Wcast-align
368383
WARNING3 += -Wcast-qual
369384
WARNING3 += -Wconversion
370385
WARNING3 += -Wpacked
371386
WARNING3 += -Wpointer-arith
372387
WARNING3 += -Wswitch-default
373388

389+
# Setting W is quite verbose and most warnings will be pre-existing issues
390+
# outside of the contributor's control. Don't fail the build on them so warnings
391+
# can be seen and hopefully addressed
392+
ifdef W
393+
ifneq (${W},0)
394+
E ?= 0
395+
endif
396+
endif
397+
374398
ifeq (${W},1)
375399
WARNINGS += $(WARNING1)
376400
else ifeq (${W},2)

0 commit comments

Comments
 (0)