2015-10-06 20:40:07 +08:00
|
|
|
# From linux.git/scripts/Kbuild.include
|
|
|
|
#
|
|
|
|
# try-run
|
|
|
|
# Usage: option = $(call try-run, $(CC)...-o "$$TMP",option-ok,otherwise)
|
|
|
|
# Exit code chooses option. "$$TMP" is can be used as temporary file and
|
|
|
|
# is automatically cleaned up.
|
|
|
|
try-run = $(shell set -e; \
|
|
|
|
TMP="$(TMPOUT).$$$$.tmp"; \
|
|
|
|
TMPO="$(TMPOUT).$$$$.o"; \
|
|
|
|
if ($(1)) >/dev/null 2>&1; \
|
|
|
|
then echo "$(2)"; \
|
|
|
|
else echo "$(3)"; \
|
|
|
|
fi; \
|
|
|
|
rm -f "$$TMP" "$$TMPO")
|
|
|
|
|
|
|
|
# cc-option
|
|
|
|
# Usage: cflags-y += $(call cc-option,-march=winchip-c6,-march=i586)
|
|
|
|
|
|
|
|
cc-option = $(call try-run,\
|
|
|
|
$(CC) $(CFLAGS) $(1) -c -x c /dev/null -o "$$TMP",$(1),$(2))
|
|
|
|
|
2018-12-05 14:40:06 +08:00
|
|
|
# cc-disable-warning
|
|
|
|
# Usage: cflags-y += $(call cc-disable-warning,unused-but-set-variable)
|
|
|
|
cc-disable-warning = $(call try-run, \
|
|
|
|
$(CC) -Werror $(CFLAGS) -W$(strip $(1)) -c -x c /dev/null -o "$$TMP",-Wno-$(strip $(1)))
|
|
|
|
|
2015-10-06 20:40:07 +08:00
|
|
|
# From linux.git/scripts/Makefile.extrawarn
|
|
|
|
# ==========================================================================
|
|
|
|
#
|
|
|
|
# make W=... settings
|
|
|
|
#
|
|
|
|
# W=1 - warnings that may be relevant and does not occur too often
|
|
|
|
# W=2 - warnings that occur quite often but may still be relevant
|
|
|
|
# W=3 - the more obscure warnings, can most likely be ignored
|
|
|
|
#
|
|
|
|
# $(call cc-option, -W...) handles gcc -W.. options which
|
|
|
|
# are not supported by all versions of the compiler
|
|
|
|
# ==========================================================================
|
|
|
|
|
|
|
|
ifeq ("$(origin W)", "command line")
|
|
|
|
export BUILD_ENABLE_EXTRA_GCC_CHECKS := $(W)
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifdef BUILD_ENABLE_EXTRA_GCC_CHECKS
|
|
|
|
warning- := $(empty)
|
|
|
|
|
|
|
|
warning-1 := -Wextra -Wunused -Wno-unused-parameter
|
|
|
|
warning-1 += -Wmissing-declarations
|
|
|
|
warning-1 += -Wmissing-format-attribute
|
|
|
|
warning-1 += $(call cc-option, -Wmissing-prototypes)
|
|
|
|
warning-1 += -Wold-style-definition
|
|
|
|
warning-1 += $(call cc-option, -Wmissing-include-dirs)
|
|
|
|
warning-1 += $(call cc-option, -Wunused-but-set-variable)
|
|
|
|
warning-1 += $(call cc-disable-warning, missing-field-initializers)
|
btrfs-progs: silence build warning caused by gcc 8 '-Wformat-truncation'
When using gcc8 + glibc 2.28.5 compiles utils.c, it complains as below:
utils.c:852:45: warning: '%s' directive output may be truncated writing
up to 4095 bytes into a region of size 4084 [-Wformat-truncation=]
snprintf(path, sizeof(path), "/dev/mapper/%s", name);
^~ ~~~~
In file included from /usr/include/stdio.h:873,
from utils.c:20:
/usr/include/bits/stdio2.h:67:10: note: '__builtin___snprintf_chk'
output between 13 and 4108 bytes into a destination of size 4096
return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1,
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
__bos (__s), __fmt, __va_arg_pack ());
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This isn't a type of warning we care about, particularly when calling
snprintf() we expect string to be truncated.
Use the GCC option -Wno-format-truncation to disable this for default
build and W=1 build, while still keeping it for W=2 and W=3 builds.
Signed-off-by: Su Yanjun <suyj.fnst@cn.fujitsu.com>
[ Use cc-disable-warning to fix the not working CFLAGS setting in configure.ac ]
[ Keep the warning in W=2/W=3 build ]
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-12-05 14:40:07 +08:00
|
|
|
warning-1 += $(call cc-disable-warning, format-truncation)
|
2018-12-05 14:40:08 +08:00
|
|
|
warning-1 += $(call cc-disable-warning, sign-compare)
|
2019-06-14 02:45:49 +08:00
|
|
|
warning-2 += $(call cc-option, -Waddress-of-packed-member)
|
2015-10-06 20:40:07 +08:00
|
|
|
|
|
|
|
warning-2 := -Waggregate-return
|
|
|
|
warning-2 += -Wcast-align
|
|
|
|
warning-2 += -Wdisabled-optimization
|
|
|
|
warning-2 += -Wnested-externs
|
|
|
|
warning-2 += $(call cc-option, -Wlogical-op)
|
|
|
|
warning-2 += $(call cc-option, -Wmissing-field-initializers)
|
btrfs-progs: silence build warning caused by gcc 8 '-Wformat-truncation'
When using gcc8 + glibc 2.28.5 compiles utils.c, it complains as below:
utils.c:852:45: warning: '%s' directive output may be truncated writing
up to 4095 bytes into a region of size 4084 [-Wformat-truncation=]
snprintf(path, sizeof(path), "/dev/mapper/%s", name);
^~ ~~~~
In file included from /usr/include/stdio.h:873,
from utils.c:20:
/usr/include/bits/stdio2.h:67:10: note: '__builtin___snprintf_chk'
output between 13 and 4108 bytes into a destination of size 4096
return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1,
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
__bos (__s), __fmt, __va_arg_pack ());
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This isn't a type of warning we care about, particularly when calling
snprintf() we expect string to be truncated.
Use the GCC option -Wno-format-truncation to disable this for default
build and W=1 build, while still keeping it for W=2 and W=3 builds.
Signed-off-by: Su Yanjun <suyj.fnst@cn.fujitsu.com>
[ Use cc-disable-warning to fix the not working CFLAGS setting in configure.ac ]
[ Keep the warning in W=2/W=3 build ]
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-12-05 14:40:07 +08:00
|
|
|
warning-2 += $(call cc-option, -Wformat-truncation)
|
2015-10-06 20:40:07 +08:00
|
|
|
|
|
|
|
warning-3 := -Wbad-function-cast
|
|
|
|
warning-3 += -Wcast-qual
|
|
|
|
warning-3 += -Wconversion
|
|
|
|
warning-3 += -Wpacked
|
|
|
|
warning-3 += -Wpadded
|
|
|
|
warning-3 += -Wpointer-arith
|
|
|
|
warning-3 += -Wredundant-decls
|
|
|
|
warning-3 += -Wswitch-default
|
|
|
|
warning-3 += $(call cc-option, -Wpacked-bitfield-compat)
|
|
|
|
warning-3 += $(call cc-option, -Wvla)
|
2018-12-05 14:40:08 +08:00
|
|
|
warning-3 += $(call cc-option, -Wsign-compare)
|
2015-10-06 20:40:07 +08:00
|
|
|
|
|
|
|
warning := $(warning-$(findstring 1, $(BUILD_ENABLE_EXTRA_GCC_CHECKS)))
|
|
|
|
warning += $(warning-$(findstring 2, $(BUILD_ENABLE_EXTRA_GCC_CHECKS)))
|
|
|
|
warning += $(warning-$(findstring 3, $(BUILD_ENABLE_EXTRA_GCC_CHECKS)))
|
|
|
|
|
|
|
|
ifeq ("$(strip $(warning))","")
|
|
|
|
$(error W=$(BUILD_ENABLE_EXTRA_GCC_CHECKS) is unknown)
|
|
|
|
endif
|
|
|
|
|
|
|
|
EXTRAWARN_CFLAGS += $(warning)
|
|
|
|
else
|
|
|
|
|
|
|
|
ifeq ($(COMPILER),clang)
|
|
|
|
EXTRAWARN_CFLAGS += $(call cc-disable-warning, initializer-overrides)
|
|
|
|
EXTRAWARN_CFLAGS += $(call cc-disable-warning, unused-value)
|
|
|
|
EXTRAWARN_CFLAGS += $(call cc-disable-warning, format)
|
|
|
|
EXTRAWARN_CFLAGS += $(call cc-disable-warning, unknown-warning-option)
|
|
|
|
EXTRAWARN_CFLAGS += $(call cc-disable-warning, sign-compare)
|
|
|
|
EXTRAWARN_CFLAGS += $(call cc-disable-warning, format-zero-length)
|
|
|
|
EXTRAWARN_CFLAGS += $(call cc-disable-warning, uninitialized)
|
|
|
|
endif
|
|
|
|
endif
|