Makefile.compiler: replace cc-ifversion with compiler-specific macros

cc-ifversion is GCC specific. Replace it with compiler specific
variants. Update the users of cc-ifversion to use these new macros.

Link: https://github.com/ClangBuiltLinux/linux/issues/350
Link: https://lore.kernel.org/llvm/CAGG=3QWSAUakO42kubrCap8fp-gm1ERJJAYXTnP1iHk_wrH=BQ@mail.gmail.com/
Suggested-by: Bill Wendling <morbo@google.com>
Reviewed-by: Nathan Chancellor <nathan@kernel.org>
Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
This commit is contained in:
Nick Desaulniers 2022-09-19 10:08:28 -07:00 committed by Masahiro Yamada
parent 2e07005f48
commit 88b61e3bff
5 changed files with 29 additions and 22 deletions

View File

@ -682,22 +682,27 @@ more details, with real examples.
In the above example, -Wno-unused-but-set-variable will be added to In the above example, -Wno-unused-but-set-variable will be added to
KBUILD_CFLAGS only if gcc really accepts it. KBUILD_CFLAGS only if gcc really accepts it.
cc-ifversion gcc-min-version
cc-ifversion tests the version of $(CC) and equals the fourth parameter gcc-min-version tests if the value of $(CONFIG_GCC_VERSION) is greater than
if version expression is true, or the fifth (if given) if the version or equal to the provided value and evaluates to y if so.
expression is false.
Example:: Example::
#fs/reiserfs/Makefile cflags-$(call gcc-min-version, 70100) := -foo
ccflags-y := $(call cc-ifversion, -lt, 0402, -O1)
In this example, ccflags-y will be assigned the value -O1 if the In this example, cflags-y will be assigned the value -foo if $(CC) is gcc and
$(CC) version is less than 4.2. $(CONFIG_GCC_VERSION) is >= 7.1.
cc-ifversion takes all the shell operators:
-eq, -ne, -lt, -le, -gt, and -ge clang-min-version
The third parameter may be a text as in this example, but it may also clang-min-version tests if the value of $(CONFIG_CLANG_VERSION) is greater
be an expanded variable or a macro. than or equal to the provided value and evaluates to y if so.
Example::
cflags-$(call clang-min-version, 110000) := -foo
In this example, cflags-y will be assigned the value -foo if $(CC) is clang
and $(CONFIG_CLANG_VERSION) is >= 11.0.0.
cc-cross-prefix cc-cross-prefix
cc-cross-prefix is used to check if there exists a $(CC) in path with cc-cross-prefix is used to check if there exists a $(CC) in path with

View File

@ -790,7 +790,6 @@ KBUILD_CFLAGS += $(stackp-flags-y)
KBUILD_CFLAGS-$(CONFIG_WERROR) += -Werror KBUILD_CFLAGS-$(CONFIG_WERROR) += -Werror
KBUILD_CFLAGS-$(CONFIG_CC_NO_ARRAY_BOUNDS) += -Wno-array-bounds KBUILD_CFLAGS-$(CONFIG_CC_NO_ARRAY_BOUNDS) += -Wno-array-bounds
KBUILD_CFLAGS += $(KBUILD_CFLAGS-y) $(CONFIG_CC_IMPLICIT_FALLTHROUGH)
ifdef CONFIG_CC_IS_CLANG ifdef CONFIG_CC_IS_CLANG
KBUILD_CPPFLAGS += -Qunused-arguments KBUILD_CPPFLAGS += -Qunused-arguments
@ -972,7 +971,6 @@ ifdef CONFIG_CC_IS_GCC
KBUILD_CFLAGS += -Wno-maybe-uninitialized KBUILD_CFLAGS += -Wno-maybe-uninitialized
endif endif
ifdef CONFIG_CC_IS_GCC
# The allocators already balk at large sizes, so silence the compiler # The allocators already balk at large sizes, so silence the compiler
# warnings for bounds checks involving those possible values. While # warnings for bounds checks involving those possible values. While
# -Wno-alloc-size-larger-than would normally be used here, earlier versions # -Wno-alloc-size-larger-than would normally be used here, earlier versions
@ -984,8 +982,8 @@ ifdef CONFIG_CC_IS_GCC
# ignored, continuing to default to PTRDIFF_MAX. So, left with no other # ignored, continuing to default to PTRDIFF_MAX. So, left with no other
# choice, we must perform a versioned check to disable this warning. # choice, we must perform a versioned check to disable this warning.
# https://lore.kernel.org/lkml/20210824115859.187f272f@canb.auug.org.au # https://lore.kernel.org/lkml/20210824115859.187f272f@canb.auug.org.au
KBUILD_CFLAGS += $(call cc-ifversion, -ge, 0901, -Wno-alloc-size-larger-than) KBUILD_CFLAGS-$(call gcc-min-version, 90100) += -Wno-alloc-size-larger-than
endif KBUILD_CFLAGS += $(KBUILD_CFLAGS-y) $(CONFIG_CC_IMPLICIT_FALLTHROUGH)
# disable invalid "can't wrap" optimizations for signed / pointers # disable invalid "can't wrap" optimizations for signed / pointers
KBUILD_CFLAGS += -fno-strict-overflow KBUILD_CFLAGS += -fno-strict-overflow

View File

@ -34,7 +34,7 @@ dml_ccflags := -mhard-float -maltivec
endif endif
ifdef CONFIG_CC_IS_GCC ifdef CONFIG_CC_IS_GCC
ifeq ($(call cc-ifversion, -lt, 0701, y), y) ifneq ($(call gcc-min-version, 70100),y)
IS_OLD_GCC = 1 IS_OLD_GCC = 1
endif endif
endif endif

View File

@ -61,9 +61,13 @@ cc-option-yn = $(call try-run,\
cc-disable-warning = $(call try-run,\ cc-disable-warning = $(call try-run,\
$(CC) -Werror $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) -W$(strip $(1)) -c -x c /dev/null -o "$$TMP",-Wno-$(strip $(1))) $(CC) -Werror $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) -W$(strip $(1)) -c -x c /dev/null -o "$$TMP",-Wno-$(strip $(1)))
# cc-ifversion # gcc-min-version
# Usage: EXTRA_CFLAGS += $(call cc-ifversion, -lt, 0402, -O1) # Usage: cflags-$(call gcc-min-version, 70100) += -foo
cc-ifversion = $(shell [ $(CONFIG_GCC_VERSION)0 $(1) $(2)000 ] && echo $(3) || echo $(4)) gcc-min-version = $(shell [ $(CONFIG_GCC_VERSION)0 -ge $(1)0 ] && echo y)
# clang-min-version
# Usage: cflags-$(call clang-min-version, 110000) += -foo
clang-min-version = $(shell [ $(CONFIG_CLANG_VERSION)0 -ge $(1)0 ] && echo y)
# ld-option # ld-option
# Usage: KBUILD_LDFLAGS += $(call ld-option, -X, -Y) # Usage: KBUILD_LDFLAGS += $(call ld-option, -X, -Y)

View File

@ -48,7 +48,7 @@ else
ifdef CONFIG_CC_IS_CLANG ifdef CONFIG_CC_IS_CLANG
KBUILD_CFLAGS += -Wno-initializer-overrides KBUILD_CFLAGS += -Wno-initializer-overrides
# Clang before clang-16 would warn on default argument promotions. # Clang before clang-16 would warn on default argument promotions.
ifeq ($(shell [ $(CONFIG_CLANG_VERSION) -lt 160000 ] && echo y),y) ifneq ($(call clang-min-version, 160000),y)
# Disable -Wformat # Disable -Wformat
KBUILD_CFLAGS += -Wno-format KBUILD_CFLAGS += -Wno-format
# Then re-enable flags that were part of the -Wformat group that aren't # Then re-enable flags that were part of the -Wformat group that aren't
@ -56,7 +56,7 @@ KBUILD_CFLAGS += -Wno-format
KBUILD_CFLAGS += -Wformat-extra-args -Wformat-invalid-specifier KBUILD_CFLAGS += -Wformat-extra-args -Wformat-invalid-specifier
KBUILD_CFLAGS += -Wformat-zero-length -Wnonnull KBUILD_CFLAGS += -Wformat-zero-length -Wnonnull
# Requires clang-12+. # Requires clang-12+.
ifeq ($(shell [ $(CONFIG_CLANG_VERSION) -ge 120000 ] && echo y),y) ifeq ($(call clang-min-version, 120000),y)
KBUILD_CFLAGS += -Wformat-insufficient-args KBUILD_CFLAGS += -Wformat-insufficient-args
endif endif
endif endif