LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH v2] x86/build: remove stale cc-option checks
@ 2021-08-12 18:38 Nick Desaulniers
  2021-08-15  9:57 ` [tip: x86/build] x86/build: Remove " tip-bot2 for Nick Desaulniers
  2021-08-22  8:32 ` [tip: x86/build] x86/build: Remove stale cc-option checks tip-bot2 for Nick Desaulniers
  0 siblings, 2 replies; 6+ messages in thread
From: Nick Desaulniers @ 2021-08-12 18:38 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, Borislav Petkov
  Cc: Masahiro Yamada, Nick Desaulniers, Nathan Chancellor, x86,
	H. Peter Anvin, linux-kernel, clang-built-linux

cc-option, __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 supported by all supported versions of GCC and
Clang. Remove their cc-option, __cc-option, and cc-option-yn tests.
* -Wno-address-of-packed-member
* -mno-avx
* -m32
* -mno-80387
* -march=k8
* -march=nocona
* -march=core2
* -march=atom
* -mtune=generic
* -mfentry

-mpreferred-stack-boundary= is specific to GCC, while
-mstack-alignment= is specific to Clang. Rather than test for this three
times via cc-option and __cc-option, rely on CONFIG_CC_IS_* from
Kconfig.

GCC did not support values less than 4 for -mpreferred-stack-boundary=
until GCC 7+. Change the cc-option test to check for a value of 2,
rather than 4.

Link: https://github.com/ClangBuiltLinux/linux/issues/1436
Reviewed-by: Nathan Chancellor <nathan@kernel.org>
Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
---
Changes v1 -> v2:
* Change -mpreferred-stack-boundary= cc-option test to check 2 rather
  than 4, noting that in the commit message.
* Rebase on tip/master.
* Carry forward Nathan's RB tag.

 arch/x86/Makefile | 53 +++++++++++++++++------------------------------
 1 file changed, 19 insertions(+), 34 deletions(-)

diff --git a/arch/x86/Makefile b/arch/x86/Makefile
index 307fd0000a83..0d33ba013683 100644
--- a/arch/x86/Makefile
+++ b/arch/x86/Makefile
@@ -14,10 +14,13 @@ endif
 
 # For gcc stack alignment is specified with -mpreferred-stack-boundary,
 # clang has the option -mstack-alignment for that purpose.
-ifneq ($(call cc-option, -mpreferred-stack-boundary=4),)
+ifdef CONFIG_CC_IS_GCC
+ifneq ($(call cc-option, -mpreferred-stack-boundary=2),)
       cc_stack_align4 := -mpreferred-stack-boundary=2
       cc_stack_align8 := -mpreferred-stack-boundary=3
-else ifneq ($(call cc-option, -mstack-alignment=16),)
+endif
+endif
+ifdef CONFIG_CC_IS_CLANG
       cc_stack_align4 := -mstack-alignment=4
       cc_stack_align8 := -mstack-alignment=8
 endif
@@ -31,8 +34,8 @@ REALMODE_CFLAGS	:= -m16 -g -Os -DDISABLE_BRANCH_PROFILING \
 
 REALMODE_CFLAGS += -ffreestanding
 REALMODE_CFLAGS += -fno-stack-protector
-REALMODE_CFLAGS += $(call __cc-option, $(CC), $(REALMODE_CFLAGS), -Wno-address-of-packed-member)
-REALMODE_CFLAGS += $(call __cc-option, $(CC), $(REALMODE_CFLAGS), $(cc_stack_align4))
+REALMODE_CFLAGS += -Wno-address-of-packed-member
+REALMODE_CFLAGS += $(cc_stack_align4)
 REALMODE_CFLAGS += $(CLANG_FLAGS)
 export REALMODE_CFLAGS
 
@@ -48,8 +51,7 @@ export BITS
 #
 #    https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53383
 #
-KBUILD_CFLAGS += -mno-sse -mno-mmx -mno-sse2 -mno-3dnow
-KBUILD_CFLAGS += $(call cc-option,-mno-avx,)
+KBUILD_CFLAGS += -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -mno-avx
 
 # Intel CET isn't enabled in the kernel
 KBUILD_CFLAGS += $(call cc-option,-fcf-protection=none)
@@ -59,9 +61,8 @@ ifeq ($(CONFIG_X86_32),y)
         UTS_MACHINE := i386
         CHECKFLAGS += -D__i386__
 
-        biarch := $(call cc-option,-m32)
-        KBUILD_AFLAGS += $(biarch)
-        KBUILD_CFLAGS += $(biarch)
+        KBUILD_AFLAGS += -m32
+        KBUILD_CFLAGS += -m32
 
         KBUILD_CFLAGS += -msoft-float -mregparm=3 -freg-struct-return
 
@@ -72,7 +73,7 @@ ifeq ($(CONFIG_X86_32),y)
         # Align the stack to the register width instead of using the default
         # alignment of 16 bytes. This reduces stack usage and the number of
         # alignment instructions.
-        KBUILD_CFLAGS += $(call cc-option,$(cc_stack_align4))
+        KBUILD_CFLAGS += $(cc_stack_align4)
 
         # CPU-specific tuning. Anything which can be shared with UML should go here.
         include arch/x86/Makefile_32.cpu
@@ -93,7 +94,6 @@ else
         UTS_MACHINE := x86_64
         CHECKFLAGS += -D__x86_64__
 
-        biarch := -m64
         KBUILD_AFLAGS += -m64
         KBUILD_CFLAGS += -m64
 
@@ -104,7 +104,7 @@ else
         KBUILD_CFLAGS += $(call cc-option,-falign-loops=1)
 
         # Don't autogenerate traditional x87 instructions
-        KBUILD_CFLAGS += $(call cc-option,-mno-80387)
+        KBUILD_CFLAGS += -mno-80387
         KBUILD_CFLAGS += $(call cc-option,-mno-fp-ret-in-387)
 
         # By default gcc and clang use a stack alignment of 16 bytes for x86.
@@ -114,20 +114,17 @@ else
         # default alignment which keep the stack *mis*aligned.
         # Furthermore an alignment to the register width reduces stack usage
         # and the number of alignment instructions.
-        KBUILD_CFLAGS += $(call cc-option,$(cc_stack_align8))
+        KBUILD_CFLAGS += $(cc_stack_align8)
 
 	# Use -mskip-rax-setup if supported.
 	KBUILD_CFLAGS += $(call cc-option,-mskip-rax-setup)
 
         # FIXME - should be integrated in Makefile.cpu (Makefile_32.cpu)
-        cflags-$(CONFIG_MK8) += $(call cc-option,-march=k8)
-        cflags-$(CONFIG_MPSC) += $(call cc-option,-march=nocona)
-
-        cflags-$(CONFIG_MCORE2) += \
-                $(call cc-option,-march=core2,$(call cc-option,-mtune=generic))
-	cflags-$(CONFIG_MATOM) += $(call cc-option,-march=atom) \
-		$(call cc-option,-mtune=atom,$(call cc-option,-mtune=generic))
-        cflags-$(CONFIG_GENERIC_CPU) += $(call cc-option,-mtune=generic)
+        cflags-$(CONFIG_MK8)		+= -march=k8
+        cflags-$(CONFIG_MPSC)		+= -march=nocona
+        cflags-$(CONFIG_MCORE2)		+= -march=core2
+        cflags-$(CONFIG_MATOM)		+= -march=atom
+        cflags-$(CONFIG_GENERIC_CPU)	+= -mtune=generic
         KBUILD_CFLAGS += $(cflags-y)
 
         KBUILD_CFLAGS += -mno-red-zone
@@ -158,18 +155,6 @@ export CONFIG_X86_X32_ABI
 ifdef CONFIG_FUNCTION_GRAPH_TRACER
   ifndef CONFIG_HAVE_FENTRY
 	ACCUMULATE_OUTGOING_ARGS := 1
-  else
-    ifeq ($(call cc-option-yn, -mfentry), n)
-	ACCUMULATE_OUTGOING_ARGS := 1
-
-	# GCC ignores '-maccumulate-outgoing-args' when used with '-Os'.
-	# If '-Os' is enabled, disable it and print a warning.
-        ifdef CONFIG_CC_OPTIMIZE_FOR_SIZE
-          undefine CONFIG_CC_OPTIMIZE_FOR_SIZE
-          $(warning Disabling CONFIG_CC_OPTIMIZE_FOR_SIZE.  Your compiler does not have -mfentry so you cannot optimize for size with CONFIG_FUNCTION_GRAPH_TRACER.)
-        endif
-
-    endif
   endif
 endif
 
@@ -193,7 +178,7 @@ ifdef CONFIG_RETPOLINE
   # only been fixed starting from gcc stable version 8.4.0 and
   # onwards, but not for older ones. See gcc bug #86952.
   ifndef CONFIG_CC_IS_CLANG
-    KBUILD_CFLAGS += $(call cc-option,-fno-jump-tables)
+    KBUILD_CFLAGS += -fno-jump-tables
   endif
 endif
 

base-commit: c5ee8ababa9be56241c949d5c3b9e29a1d0300d6
-- 
2.33.0.rc1.237.g0d66db33f3-goog


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [tip: x86/build] x86/build: Remove stale cc-option checks
  2021-08-12 18:38 [PATCH v2] x86/build: remove stale cc-option checks Nick Desaulniers
@ 2021-08-15  9:57 ` tip-bot2 for Nick Desaulniers
  2021-08-22  8:31   ` Ingo Molnar
  2021-08-22  8:32 ` [tip: x86/build] x86/build: Remove stale cc-option checks tip-bot2 for Nick Desaulniers
  1 sibling, 1 reply; 6+ messages in thread
From: tip-bot2 for Nick Desaulniers @ 2021-08-15  9:57 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Nick Desaulniers, Borislav Petkov, Nathan Chancellor, x86, linux-kernel

The following commit has been merged into the x86/build branch of tip:

Commit-ID:     1463c2a27d59c69358ad1cbd869d3a8649695d8c
Gitweb:        https://git.kernel.org/tip/1463c2a27d59c69358ad1cbd869d3a8649695d8c
Author:        Nick Desaulniers <ndesaulniers@google.com>
AuthorDate:    Thu, 12 Aug 2021 11:38:48 -07:00
Committer:     Borislav Petkov <bp@suse.de>
CommitterDate: Sun, 15 Aug 2021 10:32:52 +02:00

x86/build: Remove stale cc-option checks

cc-option, __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 supported by all supported versions of GCC and
Clang. Remove their cc-option, __cc-option, and cc-option-yn tests.

  -Wno-address-of-packed-member
  -mno-avx
  -m32
  -mno-80387
  -march=k8
  -march=nocona
  -march=core2
  -march=atom
  -mtune=generic
  -mfentry

-mpreferred-stack-boundary= is specific to GCC, while -mstack-alignment=
is specific to Clang. Rather than test for this three times via
cc-option and __cc-option, rely on CONFIG_CC_IS_* from Kconfig.

GCC did not support values less than 4 for -mpreferred-stack-boundary=
until GCC 7+. Change the cc-option test to check for a value of 2,
rather than 4.

Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Reviewed-by: Nathan Chancellor <nathan@kernel.org>
Link: https://github.com/ClangBuiltLinux/linux/issues/1436
Link: https://lkml.kernel.org/r/20210812183848.1519994-1-ndesaulniers@google.com
---
 arch/x86/Makefile | 53 ++++++++++++++++------------------------------
 1 file changed, 19 insertions(+), 34 deletions(-)

diff --git a/arch/x86/Makefile b/arch/x86/Makefile
index 307fd00..0d33ba0 100644
--- a/arch/x86/Makefile
+++ b/arch/x86/Makefile
@@ -14,10 +14,13 @@ endif
 
 # For gcc stack alignment is specified with -mpreferred-stack-boundary,
 # clang has the option -mstack-alignment for that purpose.
-ifneq ($(call cc-option, -mpreferred-stack-boundary=4),)
+ifdef CONFIG_CC_IS_GCC
+ifneq ($(call cc-option, -mpreferred-stack-boundary=2),)
       cc_stack_align4 := -mpreferred-stack-boundary=2
       cc_stack_align8 := -mpreferred-stack-boundary=3
-else ifneq ($(call cc-option, -mstack-alignment=16),)
+endif
+endif
+ifdef CONFIG_CC_IS_CLANG
       cc_stack_align4 := -mstack-alignment=4
       cc_stack_align8 := -mstack-alignment=8
 endif
@@ -31,8 +34,8 @@ REALMODE_CFLAGS	:= -m16 -g -Os -DDISABLE_BRANCH_PROFILING \
 
 REALMODE_CFLAGS += -ffreestanding
 REALMODE_CFLAGS += -fno-stack-protector
-REALMODE_CFLAGS += $(call __cc-option, $(CC), $(REALMODE_CFLAGS), -Wno-address-of-packed-member)
-REALMODE_CFLAGS += $(call __cc-option, $(CC), $(REALMODE_CFLAGS), $(cc_stack_align4))
+REALMODE_CFLAGS += -Wno-address-of-packed-member
+REALMODE_CFLAGS += $(cc_stack_align4)
 REALMODE_CFLAGS += $(CLANG_FLAGS)
 export REALMODE_CFLAGS
 
@@ -48,8 +51,7 @@ export BITS
 #
 #    https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53383
 #
-KBUILD_CFLAGS += -mno-sse -mno-mmx -mno-sse2 -mno-3dnow
-KBUILD_CFLAGS += $(call cc-option,-mno-avx,)
+KBUILD_CFLAGS += -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -mno-avx
 
 # Intel CET isn't enabled in the kernel
 KBUILD_CFLAGS += $(call cc-option,-fcf-protection=none)
@@ -59,9 +61,8 @@ ifeq ($(CONFIG_X86_32),y)
         UTS_MACHINE := i386
         CHECKFLAGS += -D__i386__
 
-        biarch := $(call cc-option,-m32)
-        KBUILD_AFLAGS += $(biarch)
-        KBUILD_CFLAGS += $(biarch)
+        KBUILD_AFLAGS += -m32
+        KBUILD_CFLAGS += -m32
 
         KBUILD_CFLAGS += -msoft-float -mregparm=3 -freg-struct-return
 
@@ -72,7 +73,7 @@ ifeq ($(CONFIG_X86_32),y)
         # Align the stack to the register width instead of using the default
         # alignment of 16 bytes. This reduces stack usage and the number of
         # alignment instructions.
-        KBUILD_CFLAGS += $(call cc-option,$(cc_stack_align4))
+        KBUILD_CFLAGS += $(cc_stack_align4)
 
         # CPU-specific tuning. Anything which can be shared with UML should go here.
         include arch/x86/Makefile_32.cpu
@@ -93,7 +94,6 @@ else
         UTS_MACHINE := x86_64
         CHECKFLAGS += -D__x86_64__
 
-        biarch := -m64
         KBUILD_AFLAGS += -m64
         KBUILD_CFLAGS += -m64
 
@@ -104,7 +104,7 @@ else
         KBUILD_CFLAGS += $(call cc-option,-falign-loops=1)
 
         # Don't autogenerate traditional x87 instructions
-        KBUILD_CFLAGS += $(call cc-option,-mno-80387)
+        KBUILD_CFLAGS += -mno-80387
         KBUILD_CFLAGS += $(call cc-option,-mno-fp-ret-in-387)
 
         # By default gcc and clang use a stack alignment of 16 bytes for x86.
@@ -114,20 +114,17 @@ else
         # default alignment which keep the stack *mis*aligned.
         # Furthermore an alignment to the register width reduces stack usage
         # and the number of alignment instructions.
-        KBUILD_CFLAGS += $(call cc-option,$(cc_stack_align8))
+        KBUILD_CFLAGS += $(cc_stack_align8)
 
 	# Use -mskip-rax-setup if supported.
 	KBUILD_CFLAGS += $(call cc-option,-mskip-rax-setup)
 
         # FIXME - should be integrated in Makefile.cpu (Makefile_32.cpu)
-        cflags-$(CONFIG_MK8) += $(call cc-option,-march=k8)
-        cflags-$(CONFIG_MPSC) += $(call cc-option,-march=nocona)
-
-        cflags-$(CONFIG_MCORE2) += \
-                $(call cc-option,-march=core2,$(call cc-option,-mtune=generic))
-	cflags-$(CONFIG_MATOM) += $(call cc-option,-march=atom) \
-		$(call cc-option,-mtune=atom,$(call cc-option,-mtune=generic))
-        cflags-$(CONFIG_GENERIC_CPU) += $(call cc-option,-mtune=generic)
+        cflags-$(CONFIG_MK8)		+= -march=k8
+        cflags-$(CONFIG_MPSC)		+= -march=nocona
+        cflags-$(CONFIG_MCORE2)		+= -march=core2
+        cflags-$(CONFIG_MATOM)		+= -march=atom
+        cflags-$(CONFIG_GENERIC_CPU)	+= -mtune=generic
         KBUILD_CFLAGS += $(cflags-y)
 
         KBUILD_CFLAGS += -mno-red-zone
@@ -158,18 +155,6 @@ export CONFIG_X86_X32_ABI
 ifdef CONFIG_FUNCTION_GRAPH_TRACER
   ifndef CONFIG_HAVE_FENTRY
 	ACCUMULATE_OUTGOING_ARGS := 1
-  else
-    ifeq ($(call cc-option-yn, -mfentry), n)
-	ACCUMULATE_OUTGOING_ARGS := 1
-
-	# GCC ignores '-maccumulate-outgoing-args' when used with '-Os'.
-	# If '-Os' is enabled, disable it and print a warning.
-        ifdef CONFIG_CC_OPTIMIZE_FOR_SIZE
-          undefine CONFIG_CC_OPTIMIZE_FOR_SIZE
-          $(warning Disabling CONFIG_CC_OPTIMIZE_FOR_SIZE.  Your compiler does not have -mfentry so you cannot optimize for size with CONFIG_FUNCTION_GRAPH_TRACER.)
-        endif
-
-    endif
   endif
 endif
 
@@ -193,7 +178,7 @@ ifdef CONFIG_RETPOLINE
   # only been fixed starting from gcc stable version 8.4.0 and
   # onwards, but not for older ones. See gcc bug #86952.
   ifndef CONFIG_CC_IS_CLANG
-    KBUILD_CFLAGS += $(call cc-option,-fno-jump-tables)
+    KBUILD_CFLAGS += -fno-jump-tables
   endif
 endif
 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [tip: x86/build] x86/build: Remove stale cc-option checks
  2021-08-15  9:57 ` [tip: x86/build] x86/build: Remove " tip-bot2 for Nick Desaulniers
@ 2021-08-22  8:31   ` Ingo Molnar
  2021-08-26 18:55     ` Nick Desaulniers
  0 siblings, 1 reply; 6+ messages in thread
From: Ingo Molnar @ 2021-08-22  8:31 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-tip-commits, Nick Desaulniers, Borislav Petkov,
	Nathan Chancellor, x86


* tip-bot2 for Nick Desaulniers <tip-bot2@linutronix.de> wrote:

> The following commit has been merged into the x86/build branch of tip:
> 
> Commit-ID:     1463c2a27d59c69358ad1cbd869d3a8649695d8c
> Gitweb:        https://git.kernel.org/tip/1463c2a27d59c69358ad1cbd869d3a8649695d8c
> Author:        Nick Desaulniers <ndesaulniers@google.com>
> AuthorDate:    Thu, 12 Aug 2021 11:38:48 -07:00
> Committer:     Borislav Petkov <bp@suse.de>
> CommitterDate: Sun, 15 Aug 2021 10:32:52 +02:00
> 
> x86/build: Remove stale cc-option checks
> 
> -mpreferred-stack-boundary= is specific to GCC, while -mstack-alignment=
> is specific to Clang. Rather than test for this three times via
> cc-option and __cc-option, rely on CONFIG_CC_IS_* from Kconfig.
> 
> GCC did not support values less than 4 for -mpreferred-stack-boundary=
> until GCC 7+. Change the cc-option test to check for a value of 2,
> rather than 4.

> --- a/arch/x86/Makefile
> +++ b/arch/x86/Makefile
> @@ -14,10 +14,13 @@ endif
>  
>  # For gcc stack alignment is specified with -mpreferred-stack-boundary,
>  # clang has the option -mstack-alignment for that purpose.
> -ifneq ($(call cc-option, -mpreferred-stack-boundary=4),)
> +ifdef CONFIG_CC_IS_GCC
> +ifneq ($(call cc-option, -mpreferred-stack-boundary=2),)
>        cc_stack_align4 := -mpreferred-stack-boundary=2
>        cc_stack_align8 := -mpreferred-stack-boundary=3
> -else ifneq ($(call cc-option, -mstack-alignment=16),)
> +endif
> +endif
> +ifdef CONFIG_CC_IS_CLANG
>        cc_stack_align4 := -mstack-alignment=4
>        cc_stack_align8 := -mstack-alignment=8

So I spent most of yesterday bisecting a hard to diagnose bug that looked 
like a GPU driver bug - but the bisect somewhat surprisingly ended up at 
this commit.

Doing the partial revert below solves the regression - as the above hunk is 
not obviously an identity transformation. I have a pretty usual GCC 10.3.0 
build environment with nothing exotic.

I amdended the commit with the partial revert in tip:x86/build.

Thanks,

	Ingo

diff --git a/arch/x86/Makefile b/arch/x86/Makefile
index 0d33ba013683..88fb2bca6a3e 100644
--- a/arch/x86/Makefile
+++ b/arch/x86/Makefile
@@ -14,13 +14,10 @@ endif
 
 # For gcc stack alignment is specified with -mpreferred-stack-boundary,
 # clang has the option -mstack-alignment for that purpose.
-ifdef CONFIG_CC_IS_GCC
-ifneq ($(call cc-option, -mpreferred-stack-boundary=2),)
+ifneq ($(call cc-option, -mpreferred-stack-boundary=4),)
       cc_stack_align4 := -mpreferred-stack-boundary=2
       cc_stack_align8 := -mpreferred-stack-boundary=3
-endif
-endif
-ifdef CONFIG_CC_IS_CLANG
+else ifneq ($(call cc-option, -mstack-alignment=16),)
       cc_stack_align4 := -mstack-alignment=4
       cc_stack_align8 := -mstack-alignment=8
 endif

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [tip: x86/build] x86/build: Remove stale cc-option checks
  2021-08-12 18:38 [PATCH v2] x86/build: remove stale cc-option checks Nick Desaulniers
  2021-08-15  9:57 ` [tip: x86/build] x86/build: Remove " tip-bot2 for Nick Desaulniers
@ 2021-08-22  8:32 ` tip-bot2 for Nick Desaulniers
  1 sibling, 0 replies; 6+ messages in thread
From: tip-bot2 for Nick Desaulniers @ 2021-08-22  8:32 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Nick Desaulniers, Borislav Petkov, Ingo Molnar, x86, linux-kernel

The following commit has been merged into the x86/build branch of tip:

Commit-ID:     989ceac799cb28a477304cdc9ee72995191c6378
Gitweb:        https://git.kernel.org/tip/989ceac799cb28a477304cdc9ee72995191c6378
Author:        Nick Desaulniers <ndesaulniers@google.com>
AuthorDate:    Thu, 12 Aug 2021 11:38:48 -07:00
Committer:     Ingo Molnar <mingo@kernel.org>
CommitterDate: Sun, 22 Aug 2021 10:24:27 +02:00

x86/build: Remove stale cc-option checks

cc-option, __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 supported by all supported versions of GCC and
Clang. Remove their cc-option, __cc-option, and cc-option-yn tests.

  -Wno-address-of-packed-member
  -mno-avx
  -m32
  -mno-80387
  -march=k8
  -march=nocona
  -march=core2
  -march=atom
  -mtune=generic
  -mfentry

[ mingo: Fixed regression on GCC, via partial revert of the stack-boundary changes.  ]

Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Link: https://github.com/ClangBuiltLinux/linux/issues/1436
Link: https://lkml.kernel.org/r/20210812183848.1519994-1-ndesaulniers@google.com
---
 arch/x86/Makefile | 46 ++++++++++++++--------------------------------
 1 file changed, 14 insertions(+), 32 deletions(-)

diff --git a/arch/x86/Makefile b/arch/x86/Makefile
index 307fd00..88fb2bc 100644
--- a/arch/x86/Makefile
+++ b/arch/x86/Makefile
@@ -31,8 +31,8 @@ REALMODE_CFLAGS	:= -m16 -g -Os -DDISABLE_BRANCH_PROFILING \
 
 REALMODE_CFLAGS += -ffreestanding
 REALMODE_CFLAGS += -fno-stack-protector
-REALMODE_CFLAGS += $(call __cc-option, $(CC), $(REALMODE_CFLAGS), -Wno-address-of-packed-member)
-REALMODE_CFLAGS += $(call __cc-option, $(CC), $(REALMODE_CFLAGS), $(cc_stack_align4))
+REALMODE_CFLAGS += -Wno-address-of-packed-member
+REALMODE_CFLAGS += $(cc_stack_align4)
 REALMODE_CFLAGS += $(CLANG_FLAGS)
 export REALMODE_CFLAGS
 
@@ -48,8 +48,7 @@ export BITS
 #
 #    https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53383
 #
-KBUILD_CFLAGS += -mno-sse -mno-mmx -mno-sse2 -mno-3dnow
-KBUILD_CFLAGS += $(call cc-option,-mno-avx,)
+KBUILD_CFLAGS += -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -mno-avx
 
 # Intel CET isn't enabled in the kernel
 KBUILD_CFLAGS += $(call cc-option,-fcf-protection=none)
@@ -59,9 +58,8 @@ ifeq ($(CONFIG_X86_32),y)
         UTS_MACHINE := i386
         CHECKFLAGS += -D__i386__
 
-        biarch := $(call cc-option,-m32)
-        KBUILD_AFLAGS += $(biarch)
-        KBUILD_CFLAGS += $(biarch)
+        KBUILD_AFLAGS += -m32
+        KBUILD_CFLAGS += -m32
 
         KBUILD_CFLAGS += -msoft-float -mregparm=3 -freg-struct-return
 
@@ -72,7 +70,7 @@ ifeq ($(CONFIG_X86_32),y)
         # Align the stack to the register width instead of using the default
         # alignment of 16 bytes. This reduces stack usage and the number of
         # alignment instructions.
-        KBUILD_CFLAGS += $(call cc-option,$(cc_stack_align4))
+        KBUILD_CFLAGS += $(cc_stack_align4)
 
         # CPU-specific tuning. Anything which can be shared with UML should go here.
         include arch/x86/Makefile_32.cpu
@@ -93,7 +91,6 @@ else
         UTS_MACHINE := x86_64
         CHECKFLAGS += -D__x86_64__
 
-        biarch := -m64
         KBUILD_AFLAGS += -m64
         KBUILD_CFLAGS += -m64
 
@@ -104,7 +101,7 @@ else
         KBUILD_CFLAGS += $(call cc-option,-falign-loops=1)
 
         # Don't autogenerate traditional x87 instructions
-        KBUILD_CFLAGS += $(call cc-option,-mno-80387)
+        KBUILD_CFLAGS += -mno-80387
         KBUILD_CFLAGS += $(call cc-option,-mno-fp-ret-in-387)
 
         # By default gcc and clang use a stack alignment of 16 bytes for x86.
@@ -114,20 +111,17 @@ else
         # default alignment which keep the stack *mis*aligned.
         # Furthermore an alignment to the register width reduces stack usage
         # and the number of alignment instructions.
-        KBUILD_CFLAGS += $(call cc-option,$(cc_stack_align8))
+        KBUILD_CFLAGS += $(cc_stack_align8)
 
 	# Use -mskip-rax-setup if supported.
 	KBUILD_CFLAGS += $(call cc-option,-mskip-rax-setup)
 
         # FIXME - should be integrated in Makefile.cpu (Makefile_32.cpu)
-        cflags-$(CONFIG_MK8) += $(call cc-option,-march=k8)
-        cflags-$(CONFIG_MPSC) += $(call cc-option,-march=nocona)
-
-        cflags-$(CONFIG_MCORE2) += \
-                $(call cc-option,-march=core2,$(call cc-option,-mtune=generic))
-	cflags-$(CONFIG_MATOM) += $(call cc-option,-march=atom) \
-		$(call cc-option,-mtune=atom,$(call cc-option,-mtune=generic))
-        cflags-$(CONFIG_GENERIC_CPU) += $(call cc-option,-mtune=generic)
+        cflags-$(CONFIG_MK8)		+= -march=k8
+        cflags-$(CONFIG_MPSC)		+= -march=nocona
+        cflags-$(CONFIG_MCORE2)		+= -march=core2
+        cflags-$(CONFIG_MATOM)		+= -march=atom
+        cflags-$(CONFIG_GENERIC_CPU)	+= -mtune=generic
         KBUILD_CFLAGS += $(cflags-y)
 
         KBUILD_CFLAGS += -mno-red-zone
@@ -158,18 +152,6 @@ export CONFIG_X86_X32_ABI
 ifdef CONFIG_FUNCTION_GRAPH_TRACER
   ifndef CONFIG_HAVE_FENTRY
 	ACCUMULATE_OUTGOING_ARGS := 1
-  else
-    ifeq ($(call cc-option-yn, -mfentry), n)
-	ACCUMULATE_OUTGOING_ARGS := 1
-
-	# GCC ignores '-maccumulate-outgoing-args' when used with '-Os'.
-	# If '-Os' is enabled, disable it and print a warning.
-        ifdef CONFIG_CC_OPTIMIZE_FOR_SIZE
-          undefine CONFIG_CC_OPTIMIZE_FOR_SIZE
-          $(warning Disabling CONFIG_CC_OPTIMIZE_FOR_SIZE.  Your compiler does not have -mfentry so you cannot optimize for size with CONFIG_FUNCTION_GRAPH_TRACER.)
-        endif
-
-    endif
   endif
 endif
 
@@ -193,7 +175,7 @@ ifdef CONFIG_RETPOLINE
   # only been fixed starting from gcc stable version 8.4.0 and
   # onwards, but not for older ones. See gcc bug #86952.
   ifndef CONFIG_CC_IS_CLANG
-    KBUILD_CFLAGS += $(call cc-option,-fno-jump-tables)
+    KBUILD_CFLAGS += -fno-jump-tables
   endif
 endif
 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [tip: x86/build] x86/build: Remove stale cc-option checks
  2021-08-22  8:31   ` Ingo Molnar
@ 2021-08-26 18:55     ` Nick Desaulniers
  2021-08-26 18:58       ` [PATCH] x86/build: Refresh stale cc-option check for stack alignment Nick Desaulniers
  0 siblings, 1 reply; 6+ messages in thread
From: Nick Desaulniers @ 2021-08-26 18:55 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: linux-kernel, linux-tip-commits, Borislav Petkov,
	Nathan Chancellor, x86, Masahiro Yamada

On Sun, Aug 22, 2021 at 1:31 AM Ingo Molnar <mingo@kernel.org> wrote:
>
>
> * tip-bot2 for Nick Desaulniers <tip-bot2@linutronix.de> wrote:
>
> > The following commit has been merged into the x86/build branch of tip:
> >
> > Commit-ID:     1463c2a27d59c69358ad1cbd869d3a8649695d8c
> > Gitweb:        https://git.kernel.org/tip/1463c2a27d59c69358ad1cbd869d3a8649695d8c
> > Author:        Nick Desaulniers <ndesaulniers@google.com>
> > AuthorDate:    Thu, 12 Aug 2021 11:38:48 -07:00
> > Committer:     Borislav Petkov <bp@suse.de>
> > CommitterDate: Sun, 15 Aug 2021 10:32:52 +02:00
> >
> > x86/build: Remove stale cc-option checks
> >
> > -mpreferred-stack-boundary= is specific to GCC, while -mstack-alignment=
> > is specific to Clang. Rather than test for this three times via
> > cc-option and __cc-option, rely on CONFIG_CC_IS_* from Kconfig.
> >
> > GCC did not support values less than 4 for -mpreferred-stack-boundary=
> > until GCC 7+. Change the cc-option test to check for a value of 2,
> > rather than 4.
>
> > --- a/arch/x86/Makefile
> > +++ b/arch/x86/Makefile
> > @@ -14,10 +14,13 @@ endif
> >
> >  # For gcc stack alignment is specified with -mpreferred-stack-boundary,
> >  # clang has the option -mstack-alignment for that purpose.
> > -ifneq ($(call cc-option, -mpreferred-stack-boundary=4),)
> > +ifdef CONFIG_CC_IS_GCC
> > +ifneq ($(call cc-option, -mpreferred-stack-boundary=2),)
> >        cc_stack_align4 := -mpreferred-stack-boundary=2
> >        cc_stack_align8 := -mpreferred-stack-boundary=3
> > -else ifneq ($(call cc-option, -mstack-alignment=16),)
> > +endif
> > +endif
> > +ifdef CONFIG_CC_IS_CLANG
> >        cc_stack_align4 := -mstack-alignment=4
> >        cc_stack_align8 := -mstack-alignment=8
>
> So I spent most of yesterday bisecting a hard to diagnose bug that looked
> like a GPU driver bug - but the bisect somewhat surprisingly ended up at
> this commit.

I'm genuinely sorry about that.  Let me guess, GPF on SSE instruction
with stack based operand from AMDGPU? (I've seen that twice so far
related to these options.)

I see now what went wrong....
GCC only supports a 4B stack alignment for ***32b*** (or 16b) x86;
`-mpreferred-stack-boundary=2` will produce an error unless -m32 or
-m16 is set; but `-mpreferred-stack-boundary=2 -m32` has been long
supported.  It's -mpreferred-stack-boundary=3 for -m64 that wasn't
supported until the gcc-7 release.  So the cc-option test should
instead test -mpreferred-stack-boundary=3.

>
> Doing the partial revert below solves the regression - as the above hunk is
> not obviously an identity transformation. I have a pretty usual GCC 10.3.0
> build environment with nothing exotic.
>
> I amdended the commit with the partial revert in tip:x86/build.

No worries. I'll send a follow up.

-- 
Thanks,
~Nick Desaulniers

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH] x86/build: Refresh stale cc-option check for stack alignment
  2021-08-26 18:55     ` Nick Desaulniers
@ 2021-08-26 18:58       ` Nick Desaulniers
  0 siblings, 0 replies; 6+ messages in thread
From: Nick Desaulniers @ 2021-08-26 18:58 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: llvm, Masahiro Yamada, Nick Desaulniers, Thomas Gleixner,
	Borislav Petkov, x86, H. Peter Anvin, linux-kernel

GCC did not support values for -mpreferred-stack-boundary= outside the
range [4, 12] for -m64 until GCC 7+. Modify the cc-option tests to check
for support for a value of 3, and only when using GCC.

GCC has long supported values in the range [2, 12] for -m16 and -m32
targets, so there's no need to test for support for
-mpreferred-stack-boundary=2, since cc_stack_align4 is only used for
-m16 and -m32 targets.

Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
---
 arch/x86/Makefile | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/arch/x86/Makefile b/arch/x86/Makefile
index d82d01490dd3..2744c4f60b63 100644
--- a/arch/x86/Makefile
+++ b/arch/x86/Makefile
@@ -14,10 +14,11 @@ endif
 
 # For gcc stack alignment is specified with -mpreferred-stack-boundary,
 # clang has the option -mstack-alignment for that purpose.
-ifneq ($(call cc-option, -mpreferred-stack-boundary=4),)
+ifdef CONFIG_CC_IS_GCC
       cc_stack_align4 := -mpreferred-stack-boundary=2
-      cc_stack_align8 := -mpreferred-stack-boundary=3
-else ifneq ($(call cc-option, -mstack-alignment=16),)
+      cc_stack_align8 := $(call cc-option,-mpreferred-stack-boundary=3)
+endif
+ifdef CONFIG_CC_IS_CLANG
       cc_stack_align4 := -mstack-alignment=4
       cc_stack_align8 := -mstack-alignment=8
 endif

base-commit: 2e98d9bede666aa8f2137047043bfba9c2c2edc0
-- 
2.33.0.259.gc128427fd7-goog


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-08-26 18:58 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-12 18:38 [PATCH v2] x86/build: remove stale cc-option checks Nick Desaulniers
2021-08-15  9:57 ` [tip: x86/build] x86/build: Remove " tip-bot2 for Nick Desaulniers
2021-08-22  8:31   ` Ingo Molnar
2021-08-26 18:55     ` Nick Desaulniers
2021-08-26 18:58       ` [PATCH] x86/build: Refresh stale cc-option check for stack alignment Nick Desaulniers
2021-08-22  8:32 ` [tip: x86/build] x86/build: Remove stale cc-option checks tip-bot2 for Nick Desaulniers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).