stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 6.1 0/4] Update as-{instr,option} to use KBUILD_AFLAGS
@ 2023-06-14 18:04 Nathan Chancellor
  2023-06-14 18:04 ` [PATCH 6.1 1/4] x86/boot/compressed: prefer cc-option for CFLAGS additions Nathan Chancellor
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Nathan Chancellor @ 2023-06-14 18:04 UTC (permalink / raw)
  To: gregkh, sashal, ndesaulniers
  Cc: naresh.kamboju, stable, llvm, Masahiro Yamada, Nathan Chancellor,
	Linux Kernel Functional Testing, Anders Roxell, tsbogend,
	linux-mips, Philippe Mathieu-Daudé

Hi all,

This series backports commit d5c8d6e0fa61 ("kbuild: Update assembler
calls to use proper flags and language target") to linux-6.1.y to
address a recent issue caused by a change in behavior in clang:

https://lore.kernel.org/CA+G9fYsJq0sPC+q6vLNKUgBqCGmmjDrfeP4R1-95Eu28FJRY_A@mail.gmail.com/
https://lore.kernel.org/20230612185424.GA2891387@dev-arch.thelio-3990X/

While that was not the original intention of the aforementioned change,
it ends up resolving the issue for the same reason, by not passing flags
that are not supported or necessary for the current language target
(KBUILD_CFLAGS for .c files and KBUILD_AFLAGS for .S files) when testing
flags for that language target.

All patches except the second one are direct backports from mainline.
The second patch is a stable specific patch because the upstream
solution could break stable due to the minimum supported version of
binutils in mainline being a newer version than 6.1 and earlier; it
chooses to do the more conservative fix, which was alluded to in the
changelog of the upstream commit.

For now, this is just a 6.1 issue. If the issue occurs in older
releases, I will send separate backports. If there are any issues or
objections to this series, please let me know.

Cheers,
Nathan

---
Nathan Chancellor (2):
      MIPS: Move '-Wa,-msoft-float' check from as-option to cc-option
      MIPS: Prefer cc-option for additions to cflags

Nick Desaulniers (2):
      x86/boot/compressed: prefer cc-option for CFLAGS additions
      kbuild: Update assembler calls to use proper flags and language target

 arch/mips/Makefile                | 4 ++--
 arch/mips/loongson2ef/Platform    | 2 +-
 arch/x86/boot/compressed/Makefile | 2 +-
 scripts/Kconfig.include           | 2 +-
 scripts/Makefile.compiler         | 8 ++++----
 scripts/as-version.sh             | 2 +-
 6 files changed, 10 insertions(+), 10 deletions(-)
---
base-commit: ca87e77a2ef8b298aa9f69658d5898e72ee450fe
change-id: 20230612-6-1-asssembler-target-llvm-17-3f8101fc008f

Best regards,
-- 
Nathan Chancellor <nathan@kernel.org>


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

* [PATCH 6.1 1/4] x86/boot/compressed: prefer cc-option for CFLAGS additions
  2023-06-14 18:04 [PATCH 6.1 0/4] Update as-{instr,option} to use KBUILD_AFLAGS Nathan Chancellor
@ 2023-06-14 18:04 ` Nathan Chancellor
  2023-06-14 18:04 ` [PATCH 6.1 2/4] MIPS: Move '-Wa,-msoft-float' check from as-option to cc-option Nathan Chancellor
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Nathan Chancellor @ 2023-06-14 18:04 UTC (permalink / raw)
  To: gregkh, sashal, ndesaulniers
  Cc: naresh.kamboju, stable, llvm, Masahiro Yamada, Nathan Chancellor,
	Linux Kernel Functional Testing, Anders Roxell

From: Nick Desaulniers <ndesaulniers@google.com>

commit 994f5f7816ff963f49269cfc97f63cb2e4edb84f upstream.

as-option tests new options using KBUILD_CFLAGS, which causes problems
when using as-option to update KBUILD_AFLAGS because many compiler
options are not valid assembler options.

This will be fixed in a follow up patch. Before doing so, move the
assembler test for -Wa,-mrelax-relocations=no from using as-option to
cc-option.

Link: https://lore.kernel.org/llvm/CAK7LNATcHt7GcXZ=jMszyH=+M_LC9Qr6yeAGRCBbE6xriLxtUQ@mail.gmail.com/
Suggested-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-by: Nathan Chancellor <nathan@kernel.org>
Tested-by: Nathan Chancellor <nathan@kernel.org>
Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
Tested-by: Linux Kernel Functional Testing <lkft@linaro.org>
Tested-by: Anders Roxell <anders.roxell@linaro.org>
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
---
 arch/x86/boot/compressed/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
index 3a261abb6d15..15b7b403a4bd 100644
--- a/arch/x86/boot/compressed/Makefile
+++ b/arch/x86/boot/compressed/Makefile
@@ -50,7 +50,7 @@ KBUILD_CFLAGS += $(call cc-option,-fmacro-prefix-map=$(srctree)/=)
 KBUILD_CFLAGS += -fno-asynchronous-unwind-tables
 KBUILD_CFLAGS += -D__DISABLE_EXPORTS
 # Disable relocation relaxation in case the link is not PIE.
-KBUILD_CFLAGS += $(call as-option,-Wa$(comma)-mrelax-relocations=no)
+KBUILD_CFLAGS += $(call cc-option,-Wa$(comma)-mrelax-relocations=no)
 KBUILD_CFLAGS += -include $(srctree)/include/linux/hidden.h
 
 # sev.c indirectly inludes inat-table.h which is generated during

-- 
2.41.0


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

* [PATCH 6.1 2/4] MIPS: Move '-Wa,-msoft-float' check from as-option to cc-option
  2023-06-14 18:04 [PATCH 6.1 0/4] Update as-{instr,option} to use KBUILD_AFLAGS Nathan Chancellor
  2023-06-14 18:04 ` [PATCH 6.1 1/4] x86/boot/compressed: prefer cc-option for CFLAGS additions Nathan Chancellor
@ 2023-06-14 18:04 ` Nathan Chancellor
  2023-06-14 18:04 ` [PATCH 6.1 3/4] MIPS: Prefer cc-option for additions to cflags Nathan Chancellor
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Nathan Chancellor @ 2023-06-14 18:04 UTC (permalink / raw)
  To: gregkh, sashal, ndesaulniers
  Cc: naresh.kamboju, stable, llvm, Nathan Chancellor, tsbogend,
	linux-mips

This patch is for linux-6.1.y and earlier, it has no direct mainline
equivalent.

In order to backport commit d5c8d6e0fa61 ("kbuild: Update assembler
calls to use proper flags and language target") to resolve a separate
issue regarding PowerPC, the problem noticed and fixed by
commit 80a20d2f8288 ("MIPS: Always use -Wa,-msoft-float and eliminate
GAS_HAS_SET_HARDFLOAT") needs to be addressed. Unfortunately, 6.1 and
earlier do not contain commit e4412739472b ("Documentation: raise
minimum supported version of binutils to 2.25"), so it cannot be assumed
that all supported versions of GNU as have support for -msoft-float.

In order to switch from KBUILD_CFLAGS to KBUILD_AFLAGS in as-option
without consequence, move the '-Wa,-msoft-float' check to cc-option,
including '$(cflags-y)' directly to avoid the issue mentioned in
commit 80a20d2f8288 ("MIPS: Always use -Wa,-msoft-float and eliminate
GAS_HAS_SET_HARDFLOAT").

Signed-off-by: Nathan Chancellor <nathan@kernel.org>
---
Cc: tsbogend@alpha.franken.de
Cc: linux-mips@vger.kernel.org
---
 arch/mips/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/mips/Makefile b/arch/mips/Makefile
index b296e33f8e33..de8d508f27af 100644
--- a/arch/mips/Makefile
+++ b/arch/mips/Makefile
@@ -109,7 +109,7 @@ endif
 # (specifically newer than 2.24.51.20140728) we then also need to explicitly
 # set ".set hardfloat" in all files which manipulate floating point registers.
 #
-ifneq ($(call as-option,-Wa$(comma)-msoft-float,),)
+ifneq ($(call cc-option,$(cflags-y) -Wa$(comma)-msoft-float,),)
 	cflags-y		+= -DGAS_HAS_SET_HARDFLOAT -Wa,-msoft-float
 endif
 

-- 
2.41.0


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

* [PATCH 6.1 3/4] MIPS: Prefer cc-option for additions to cflags
  2023-06-14 18:04 [PATCH 6.1 0/4] Update as-{instr,option} to use KBUILD_AFLAGS Nathan Chancellor
  2023-06-14 18:04 ` [PATCH 6.1 1/4] x86/boot/compressed: prefer cc-option for CFLAGS additions Nathan Chancellor
  2023-06-14 18:04 ` [PATCH 6.1 2/4] MIPS: Move '-Wa,-msoft-float' check from as-option to cc-option Nathan Chancellor
@ 2023-06-14 18:04 ` Nathan Chancellor
  2023-06-14 18:04 ` [PATCH 6.1 4/4] kbuild: Update assembler calls to use proper flags and language target Nathan Chancellor
  2023-06-19  7:51 ` [PATCH 6.1 0/4] Update as-{instr,option} to use KBUILD_AFLAGS Greg KH
  4 siblings, 0 replies; 6+ messages in thread
From: Nathan Chancellor @ 2023-06-14 18:04 UTC (permalink / raw)
  To: gregkh, sashal, ndesaulniers
  Cc: naresh.kamboju, stable, llvm, Nathan Chancellor,
	Thomas Bogendoerfer, Philippe Mathieu-Daudé,
	Linux Kernel Functional Testing, Anders Roxell, Masahiro Yamada

commit 337ff6bb8960fdc128cabd264aaea3d42ca27a32 upstream.

A future change will switch as-option to use KBUILD_AFLAGS instead of
KBUILD_CFLAGS to allow clang to drop -Qunused-arguments, which may cause
issues if the flag being tested requires a flag previously added to
KBUILD_CFLAGS but not KBUILD_AFLAGS. Use cc-option for cflags additions
so that the flags are tested properly.

Signed-off-by: Nathan Chancellor <nathan@kernel.org>
Acked-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Tested-by: Linux Kernel Functional Testing <lkft@linaro.org>
Tested-by: Anders Roxell <anders.roxell@linaro.org>
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
---
 arch/mips/Makefile             | 2 +-
 arch/mips/loongson2ef/Platform | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/mips/Makefile b/arch/mips/Makefile
index de8d508f27af..85d3c3b4b7bd 100644
--- a/arch/mips/Makefile
+++ b/arch/mips/Makefile
@@ -152,7 +152,7 @@ cflags-y += -fno-stack-check
 #
 # Avoid this by explicitly disabling that assembler behaviour.
 #
-cflags-y += $(call as-option,-Wa$(comma)-mno-fix-loongson3-llsc,)
+cflags-y += $(call cc-option,-Wa$(comma)-mno-fix-loongson3-llsc,)
 
 #
 # CPU-dependent compiler/assembler options for optimization.
diff --git a/arch/mips/loongson2ef/Platform b/arch/mips/loongson2ef/Platform
index eebabf9df6ac..c6f7a4b95997 100644
--- a/arch/mips/loongson2ef/Platform
+++ b/arch/mips/loongson2ef/Platform
@@ -25,7 +25,7 @@ cflags-$(CONFIG_CPU_LOONGSON2F) += -march=loongson2f
 # binutils does not merge support for the flag then we can revisit & remove
 # this later - for now it ensures vendor toolchains don't cause problems.
 #
-cflags-$(CONFIG_CPU_LOONGSON2EF)	+= $(call as-option,-Wa$(comma)-mno-fix-loongson3-llsc,)
+cflags-$(CONFIG_CPU_LOONGSON2EF)	+= $(call cc-option,-Wa$(comma)-mno-fix-loongson3-llsc,)
 
 # Enable the workarounds for Loongson2f
 ifdef CONFIG_CPU_LOONGSON2F_WORKAROUNDS

-- 
2.41.0


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

* [PATCH 6.1 4/4] kbuild: Update assembler calls to use proper flags and language target
  2023-06-14 18:04 [PATCH 6.1 0/4] Update as-{instr,option} to use KBUILD_AFLAGS Nathan Chancellor
                   ` (2 preceding siblings ...)
  2023-06-14 18:04 ` [PATCH 6.1 3/4] MIPS: Prefer cc-option for additions to cflags Nathan Chancellor
@ 2023-06-14 18:04 ` Nathan Chancellor
  2023-06-19  7:51 ` [PATCH 6.1 0/4] Update as-{instr,option} to use KBUILD_AFLAGS Greg KH
  4 siblings, 0 replies; 6+ messages in thread
From: Nathan Chancellor @ 2023-06-14 18:04 UTC (permalink / raw)
  To: gregkh, sashal, ndesaulniers
  Cc: naresh.kamboju, stable, llvm, Masahiro Yamada, Nathan Chancellor,
	Linux Kernel Functional Testing, Anders Roxell

From: Nick Desaulniers <ndesaulniers@google.com>

commit d5c8d6e0fa61401a729e9eb6a9c7077b2d3aebb0 upstream.

as-instr uses KBUILD_AFLAGS, but as-option uses KBUILD_CFLAGS. This can
cause as-option to fail unexpectedly when CONFIG_WERROR is set, because
clang will emit -Werror,-Wunused-command-line-argument for various -m
and -f flags in KBUILD_CFLAGS for assembler sources.

Callers of as-option and as-instr should be adding flags to
KBUILD_AFLAGS / aflags-y, not KBUILD_CFLAGS / cflags-y. Use
KBUILD_AFLAGS in all macros to clear up the initial problem.

Unfortunately, -Wunused-command-line-argument can still be triggered
with clang by the presence of warning flags or macro definitions because
'-x assembler' is used, instead of '-x assembler-with-cpp', which will
consume these flags. Switch to '-x assembler-with-cpp' in places where
'-x assembler' is used, as the compiler is always used as the driver for
out of line assembler sources in the kernel.

Finally, add -Werror to these macros so that they behave consistently
whether or not CONFIG_WERROR is set.

[nathan: Reworded and expanded on problems in commit message
         Use '-x assembler-with-cpp' in a couple more places]

Link: https://github.com/ClangBuiltLinux/linux/issues/1699
Suggested-by: Masahiro Yamada <masahiroy@kernel.org>
Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
Tested-by: Linux Kernel Functional Testing <lkft@linaro.org>
Tested-by: Anders Roxell <anders.roxell@linaro.org>
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
---
 scripts/Kconfig.include   | 2 +-
 scripts/Makefile.compiler | 8 ++++----
 scripts/as-version.sh     | 2 +-
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/scripts/Kconfig.include b/scripts/Kconfig.include
index 274125307ebd..5a84b6443875 100644
--- a/scripts/Kconfig.include
+++ b/scripts/Kconfig.include
@@ -33,7 +33,7 @@ ld-option = $(success,$(LD) -v $(1))
 
 # $(as-instr,<instr>)
 # Return y if the assembler supports <instr>, n otherwise
-as-instr = $(success,printf "%b\n" "$(1)" | $(CC) $(CLANG_FLAGS) -c -x assembler -o /dev/null -)
+as-instr = $(success,printf "%b\n" "$(1)" | $(CC) $(CLANG_FLAGS) -c -x assembler-with-cpp -o /dev/null -)
 
 # check if $(CC) and $(LD) exist
 $(error-if,$(failure,command -v $(CC)),C compiler '$(CC)' not found)
diff --git a/scripts/Makefile.compiler b/scripts/Makefile.compiler
index 20d353dcabfb..158c57f2acfd 100644
--- a/scripts/Makefile.compiler
+++ b/scripts/Makefile.compiler
@@ -29,16 +29,16 @@ try-run = $(shell set -e;		\
 	fi)
 
 # as-option
-# Usage: cflags-y += $(call as-option,-Wa$(comma)-isa=foo,)
+# Usage: aflags-y += $(call as-option,-Wa$(comma)-isa=foo,)
 
 as-option = $(call try-run,\
-	$(CC) $(KBUILD_CFLAGS) $(1) -c -x assembler /dev/null -o "$$TMP",$(1),$(2))
+	$(CC) -Werror $(KBUILD_AFLAGS) $(1) -c -x assembler-with-cpp /dev/null -o "$$TMP",$(1),$(2))
 
 # as-instr
-# Usage: cflags-y += $(call as-instr,instr,option1,option2)
+# Usage: aflags-y += $(call as-instr,instr,option1,option2)
 
 as-instr = $(call try-run,\
-	printf "%b\n" "$(1)" | $(CC) $(KBUILD_AFLAGS) -c -x assembler -o "$$TMP" -,$(2),$(3))
+	printf "%b\n" "$(1)" | $(CC) -Werror $(KBUILD_AFLAGS) -c -x assembler-with-cpp -o "$$TMP" -,$(2),$(3))
 
 # __cc-option
 # Usage: MY_CFLAGS += $(call __cc-option,$(CC),$(MY_CFLAGS),-march=winchip-c6,-march=i586)
diff --git a/scripts/as-version.sh b/scripts/as-version.sh
index 1a21495e9ff0..af717476152d 100755
--- a/scripts/as-version.sh
+++ b/scripts/as-version.sh
@@ -45,7 +45,7 @@ orig_args="$@"
 # Get the first line of the --version output.
 IFS='
 '
-set -- $(LC_ALL=C "$@" -Wa,--version -c -x assembler /dev/null -o /dev/null 2>/dev/null)
+set -- $(LC_ALL=C "$@" -Wa,--version -c -x assembler-with-cpp /dev/null -o /dev/null 2>/dev/null)
 
 # Split the line on spaces.
 IFS=' '

-- 
2.41.0


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

* Re: [PATCH 6.1 0/4] Update as-{instr,option} to use KBUILD_AFLAGS
  2023-06-14 18:04 [PATCH 6.1 0/4] Update as-{instr,option} to use KBUILD_AFLAGS Nathan Chancellor
                   ` (3 preceding siblings ...)
  2023-06-14 18:04 ` [PATCH 6.1 4/4] kbuild: Update assembler calls to use proper flags and language target Nathan Chancellor
@ 2023-06-19  7:51 ` Greg KH
  4 siblings, 0 replies; 6+ messages in thread
From: Greg KH @ 2023-06-19  7:51 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: sashal, ndesaulniers, naresh.kamboju, stable, llvm,
	Masahiro Yamada, Linux Kernel Functional Testing, Anders Roxell,
	tsbogend, linux-mips, Philippe Mathieu-Daudé

On Wed, Jun 14, 2023 at 11:04:34AM -0700, Nathan Chancellor wrote:
> Hi all,
> 
> This series backports commit d5c8d6e0fa61 ("kbuild: Update assembler
> calls to use proper flags and language target") to linux-6.1.y to
> address a recent issue caused by a change in behavior in clang:
> 
> https://lore.kernel.org/CA+G9fYsJq0sPC+q6vLNKUgBqCGmmjDrfeP4R1-95Eu28FJRY_A@mail.gmail.com/
> https://lore.kernel.org/20230612185424.GA2891387@dev-arch.thelio-3990X/
> 
> While that was not the original intention of the aforementioned change,
> it ends up resolving the issue for the same reason, by not passing flags
> that are not supported or necessary for the current language target
> (KBUILD_CFLAGS for .c files and KBUILD_AFLAGS for .S files) when testing
> flags for that language target.
> 
> All patches except the second one are direct backports from mainline.
> The second patch is a stable specific patch because the upstream
> solution could break stable due to the minimum supported version of
> binutils in mainline being a newer version than 6.1 and earlier; it
> chooses to do the more conservative fix, which was alluded to in the
> changelog of the upstream commit.
> 
> For now, this is just a 6.1 issue. If the issue occurs in older
> releases, I will send separate backports. If there are any issues or
> objections to this series, please let me know.

All now queued up, thanks.

greg k-h

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

end of thread, other threads:[~2023-06-19  7:52 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-14 18:04 [PATCH 6.1 0/4] Update as-{instr,option} to use KBUILD_AFLAGS Nathan Chancellor
2023-06-14 18:04 ` [PATCH 6.1 1/4] x86/boot/compressed: prefer cc-option for CFLAGS additions Nathan Chancellor
2023-06-14 18:04 ` [PATCH 6.1 2/4] MIPS: Move '-Wa,-msoft-float' check from as-option to cc-option Nathan Chancellor
2023-06-14 18:04 ` [PATCH 6.1 3/4] MIPS: Prefer cc-option for additions to cflags Nathan Chancellor
2023-06-14 18:04 ` [PATCH 6.1 4/4] kbuild: Update assembler calls to use proper flags and language target Nathan Chancellor
2023-06-19  7:51 ` [PATCH 6.1 0/4] Update as-{instr,option} to use KBUILD_AFLAGS Greg KH

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).