Commit 7d73c3e9 authored by Nick Desaulniers's avatar Nick Desaulniers Committed by Masahiro Yamada

Makefile: remove stale cc-option checks

cc-option, cc-option-yn, and cc-disable-warning all invoke the compiler
during build time, and can slow down the build when these checks become
stale for our supported compilers, whose minimally supported versions
increases over time. See Documentation/process/changes.rst for the
current supported minimal versions (GCC 4.9+, clang 10.0.1+). Compiler
version support for these flags may be verified on godbolt.org.

The following flags are GCC only and supported since at least GCC 4.9.
Remove cc-option and cc-disable-warning tests.
* -fno-tree-loop-im
* -Wno-maybe-uninitialized
* -fno-reorder-blocks
* -fno-ipa-cp-clone
* -fno-partial-inlining
* -femit-struct-debug-baseonly
* -fno-inline-functions-called-once
* -fconserve-stack

The following flags are supported by all supported versions of GCC and
Clang. Remove their cc-option, cc-option-yn, and cc-disable-warning tests.
* -fno-delete-null-pointer-checks
* -fno-var-tracking
* -Wno-array-bounds

The following configs are made dependent on GCC, since they use GCC
specific flags.
* READABLE_ASM
* DEBUG_SECTION_MISMATCH

-mfentry was not supported by s390-linux-gnu-gcc until gcc-9+, add a
comment.

--param=allow-store-data-races=0 was renamed to -fno-allow-store-data-races
in the GCC 10 release; add a comment.

-Wmaybe-uninitialized (GCC specific) was being added for CONFIG_GCOV,
then again unconditionally; add it only once.

Also, base RETPOLINE_CFLAGS and RETPOLINE_VDSO_CFLAGS on CONFIC_CC_IS_*
then remove cc-option tests for Clang.

Link: https://github.com/ClangBuiltLinux/linux/issues/1436Acked-by: default avatarMiguel Ojeda <ojeda@kernel.org>
Reviewed-by: default avatarNathan Chancellor <nathan@kernel.org>
Signed-off-by: default avatarNick Desaulniers <ndesaulniers@google.com>
Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
parent 36f1386d
...@@ -669,9 +669,10 @@ endif # KBUILD_EXTMOD ...@@ -669,9 +669,10 @@ endif # KBUILD_EXTMOD
# Defaults to vmlinux, but the arch makefile usually adds further targets # Defaults to vmlinux, but the arch makefile usually adds further targets
all: vmlinux all: vmlinux
CFLAGS_GCOV := -fprofile-arcs -ftest-coverage \ CFLAGS_GCOV := -fprofile-arcs -ftest-coverage
$(call cc-option,-fno-tree-loop-im) \ ifdef CONFIG_CC_IS_GCC
$(call cc-disable-warning,maybe-uninitialized,) CFLAGS_GCOV += -fno-tree-loop-im
endif
export CFLAGS_GCOV export CFLAGS_GCOV
# The arch Makefiles can override CC_FLAGS_FTRACE. We may also append it later. # The arch Makefiles can override CC_FLAGS_FTRACE. We may also append it later.
...@@ -679,12 +680,14 @@ ifdef CONFIG_FUNCTION_TRACER ...@@ -679,12 +680,14 @@ ifdef CONFIG_FUNCTION_TRACER
CC_FLAGS_FTRACE := -pg CC_FLAGS_FTRACE := -pg
endif endif
RETPOLINE_CFLAGS_GCC := -mindirect-branch=thunk-extern -mindirect-branch-register ifdef CONFIG_CC_IS_GCC
RETPOLINE_VDSO_CFLAGS_GCC := -mindirect-branch=thunk-inline -mindirect-branch-register RETPOLINE_CFLAGS := $(call cc-option,-mindirect-branch=thunk-extern -mindirect-branch-register)
RETPOLINE_CFLAGS_CLANG := -mretpoline-external-thunk RETPOLINE_VDSO_CFLAGS := $(call cc-option,-mindirect-branch=thunk-inline -mindirect-branch-register)
RETPOLINE_VDSO_CFLAGS_CLANG := -mretpoline endif
RETPOLINE_CFLAGS := $(call cc-option,$(RETPOLINE_CFLAGS_GCC),$(call cc-option,$(RETPOLINE_CFLAGS_CLANG))) ifdef CONFIG_CC_IS_CLANG
RETPOLINE_VDSO_CFLAGS := $(call cc-option,$(RETPOLINE_VDSO_CFLAGS_GCC),$(call cc-option,$(RETPOLINE_VDSO_CFLAGS_CLANG))) RETPOLINE_CFLAGS := -mretpoline-external-thunk
RETPOLINE_VDSO_CFLAGS := -mretpoline
endif
export RETPOLINE_CFLAGS export RETPOLINE_CFLAGS
export RETPOLINE_VDSO_CFLAGS export RETPOLINE_VDSO_CFLAGS
...@@ -737,7 +740,7 @@ include/config/auto.conf: ...@@ -737,7 +740,7 @@ include/config/auto.conf:
endif # may-sync-config endif # may-sync-config
endif # need-config endif # need-config
KBUILD_CFLAGS += $(call cc-option,-fno-delete-null-pointer-checks,) KBUILD_CFLAGS += -fno-delete-null-pointer-checks
KBUILD_CFLAGS += $(call cc-disable-warning,frame-address,) KBUILD_CFLAGS += $(call cc-disable-warning,frame-address,)
KBUILD_CFLAGS += $(call cc-disable-warning, format-truncation) KBUILD_CFLAGS += $(call cc-disable-warning, format-truncation)
KBUILD_CFLAGS += $(call cc-disable-warning, format-overflow) KBUILD_CFLAGS += $(call cc-disable-warning, format-overflow)
...@@ -752,17 +755,19 @@ KBUILD_CFLAGS += -Os ...@@ -752,17 +755,19 @@ KBUILD_CFLAGS += -Os
endif endif
# Tell gcc to never replace conditional load with a non-conditional one # Tell gcc to never replace conditional load with a non-conditional one
ifdef CONFIG_CC_IS_GCC
# gcc-10 renamed --param=allow-store-data-races=0 to
# -fno-allow-store-data-races.
KBUILD_CFLAGS += $(call cc-option,--param=allow-store-data-races=0) KBUILD_CFLAGS += $(call cc-option,--param=allow-store-data-races=0)
KBUILD_CFLAGS += $(call cc-option,-fno-allow-store-data-races) KBUILD_CFLAGS += $(call cc-option,-fno-allow-store-data-races)
endif
ifdef CONFIG_READABLE_ASM ifdef CONFIG_READABLE_ASM
# Disable optimizations that make assembler listings hard to read. # Disable optimizations that make assembler listings hard to read.
# reorder blocks reorders the control in the function # reorder blocks reorders the control in the function
# ipa clone creates specialized cloned functions # ipa clone creates specialized cloned functions
# partial inlining inlines only parts of functions # partial inlining inlines only parts of functions
KBUILD_CFLAGS += $(call cc-option,-fno-reorder-blocks,) \ KBUILD_CFLAGS += -fno-reorder-blocks -fno-ipa-cp-clone -fno-partial-inlining
$(call cc-option,-fno-ipa-cp-clone,) \
$(call cc-option,-fno-partial-inlining)
endif endif
ifneq ($(CONFIG_FRAME_WARN),0) ifneq ($(CONFIG_FRAME_WARN),0)
...@@ -854,8 +859,10 @@ DEBUG_CFLAGS += -gdwarf-$(dwarf-version-y) ...@@ -854,8 +859,10 @@ DEBUG_CFLAGS += -gdwarf-$(dwarf-version-y)
endif endif
ifdef CONFIG_DEBUG_INFO_REDUCED ifdef CONFIG_DEBUG_INFO_REDUCED
DEBUG_CFLAGS += $(call cc-option, -femit-struct-debug-baseonly) \ DEBUG_CFLAGS += -fno-var-tracking
$(call cc-option,-fno-var-tracking) ifdef CONFIG_CC_IS_GCC
DEBUG_CFLAGS += -femit-struct-debug-baseonly
endif
endif endif
ifdef CONFIG_DEBUG_INFO_COMPRESSED ifdef CONFIG_DEBUG_INFO_COMPRESSED
...@@ -889,6 +896,7 @@ ifdef CONFIG_FTRACE_MCOUNT_USE_RECORDMCOUNT ...@@ -889,6 +896,7 @@ ifdef CONFIG_FTRACE_MCOUNT_USE_RECORDMCOUNT
endif endif
endif endif
ifdef CONFIG_HAVE_FENTRY ifdef CONFIG_HAVE_FENTRY
# s390-linux-gnu-gcc did not support -mfentry until gcc-9.
ifeq ($(call cc-option-yn, -mfentry),y) ifeq ($(call cc-option-yn, -mfentry),y)
CC_FLAGS_FTRACE += -mfentry CC_FLAGS_FTRACE += -mfentry
CC_FLAGS_USING += -DCC_USING_FENTRY CC_FLAGS_USING += -DCC_USING_FENTRY
...@@ -901,7 +909,7 @@ endif ...@@ -901,7 +909,7 @@ endif
# We trigger additional mismatches with less inlining # We trigger additional mismatches with less inlining
ifdef CONFIG_DEBUG_SECTION_MISMATCH ifdef CONFIG_DEBUG_SECTION_MISMATCH
KBUILD_CFLAGS += $(call cc-option, -fno-inline-functions-called-once) KBUILD_CFLAGS += -fno-inline-functions-called-once
endif endif
ifdef CONFIG_LD_DEAD_CODE_DATA_ELIMINATION ifdef CONFIG_LD_DEAD_CODE_DATA_ELIMINATION
...@@ -980,14 +988,16 @@ KBUILD_CFLAGS += $(call cc-disable-warning, stringop-truncation) ...@@ -980,14 +988,16 @@ KBUILD_CFLAGS += $(call cc-disable-warning, stringop-truncation)
# We'll want to enable this eventually, but it's not going away for 5.7 at least # We'll want to enable this eventually, but it's not going away for 5.7 at least
KBUILD_CFLAGS += $(call cc-disable-warning, zero-length-bounds) KBUILD_CFLAGS += $(call cc-disable-warning, zero-length-bounds)
KBUILD_CFLAGS += $(call cc-disable-warning, array-bounds) KBUILD_CFLAGS += -Wno-array-bounds
KBUILD_CFLAGS += $(call cc-disable-warning, stringop-overflow) KBUILD_CFLAGS += $(call cc-disable-warning, stringop-overflow)
# Another good warning that we'll want to enable eventually # Another good warning that we'll want to enable eventually
KBUILD_CFLAGS += $(call cc-disable-warning, restrict) KBUILD_CFLAGS += $(call cc-disable-warning, restrict)
# Enabled with W=2, disabled by default as noisy # Enabled with W=2, disabled by default as noisy
KBUILD_CFLAGS += $(call cc-disable-warning, maybe-uninitialized) ifdef CONFIG_CC_IS_GCC
KBUILD_CFLAGS += -Wno-maybe-uninitialized
endif
# 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
...@@ -996,7 +1006,9 @@ KBUILD_CFLAGS += -fno-strict-overflow ...@@ -996,7 +1006,9 @@ KBUILD_CFLAGS += -fno-strict-overflow
KBUILD_CFLAGS += -fno-stack-check KBUILD_CFLAGS += -fno-stack-check
# conserve stack if available # conserve stack if available
KBUILD_CFLAGS += $(call cc-option,-fconserve-stack) ifdef CONFIG_CC_IS_GCC
KBUILD_CFLAGS += -fconserve-stack
endif
# Prohibit date/time macros, which would make the build non-deterministic # Prohibit date/time macros, which would make the build non-deterministic
KBUILD_CFLAGS += -Werror=date-time KBUILD_CFLAGS += -Werror=date-time
......
...@@ -365,6 +365,7 @@ config STRIP_ASM_SYMS ...@@ -365,6 +365,7 @@ config STRIP_ASM_SYMS
config READABLE_ASM config READABLE_ASM
bool "Generate readable assembler code" bool "Generate readable assembler code"
depends on DEBUG_KERNEL depends on DEBUG_KERNEL
depends on CC_IS_GCC
help help
Disable some compiler optimizations that tend to generate human unreadable Disable some compiler optimizations that tend to generate human unreadable
assembler output. This may make the kernel slightly slower, but it helps assembler output. This may make the kernel slightly slower, but it helps
...@@ -383,6 +384,7 @@ config HEADERS_INSTALL ...@@ -383,6 +384,7 @@ config HEADERS_INSTALL
config DEBUG_SECTION_MISMATCH config DEBUG_SECTION_MISMATCH
bool "Enable full Section mismatch analysis" bool "Enable full Section mismatch analysis"
depends on CC_IS_GCC
help help
The section mismatch analysis checks if there are illegal The section mismatch analysis checks if there are illegal
references from one section to another section. references from one section to another section.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment