All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nathan Chancellor <nathan@kernel.org>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Sasha Levin <sashal@kernel.org>
Cc: stable@vger.kernel.org, llvm@lists.linux.dev
Subject: [PATCH 5.4 2/6] kbuild: Update assembler calls to use proper flags and language target
Date: Mon, 11 Aug 2025 16:51:47 -0700	[thread overview]
Message-ID: <20250811235151.1108688-3-nathan@kernel.org> (raw)
In-Reply-To: <20250811235151.1108688-1-nathan@kernel.org>

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/Kbuild.include | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include
index 82eb69f07b35..11f905b95e65 100644
--- a/scripts/Kbuild.include
+++ b/scripts/Kbuild.include
@@ -99,16 +99,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)
-- 
2.50.1


  parent reply	other threads:[~2025-08-11 23:52 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-11 23:51 [PATCH 5.4 0/6] Fix build due to clang -Qunused-arguments change Nathan Chancellor
2025-08-11 23:51 ` [PATCH 5.4 1/6] ARM: 9448/1: Use an absolute path to unified.h in KBUILD_AFLAGS Nathan Chancellor
2025-08-12  4:12   ` Sasha Levin
2025-08-24  5:44   ` Patch "ARM: 9448/1: Use an absolute path to unified.h in KBUILD_AFLAGS" has been added to the 5.4-stable tree gregkh
2025-08-11 23:51 ` Nathan Chancellor [this message]
2025-08-12  4:12   ` [PATCH 5.4 2/6] kbuild: Update assembler calls to use proper flags and language target Sasha Levin
2025-08-12 21:18     ` Nathan Chancellor
2025-08-24  5:44   ` Patch "kbuild: Update assembler calls to use proper flags and language target" has been added to the 5.4-stable tree gregkh
2025-08-11 23:51 ` [PATCH 5.4 3/6] mips: Include KBUILD_CPPFLAGS in CHECKFLAGS invocation Nathan Chancellor
2025-08-12  4:12   ` Sasha Levin
2025-08-24  5:44   ` Patch "mips: Include KBUILD_CPPFLAGS in CHECKFLAGS invocation" has been added to the 5.4-stable tree gregkh
2025-08-11 23:51 ` [PATCH 5.4 4/6] kbuild: Add CLANG_FLAGS to as-instr Nathan Chancellor
2025-08-12  4:12   ` Sasha Levin
2025-08-24  5:44   ` Patch "kbuild: Add CLANG_FLAGS to as-instr" has been added to the 5.4-stable tree gregkh
2025-08-11 23:51 ` [PATCH 5.4 5/6] kbuild: add $(CLANG_FLAGS) to KBUILD_CPPFLAGS Nathan Chancellor
2025-08-12  4:12   ` Sasha Levin
2025-08-12 21:11     ` Nathan Chancellor
2025-08-24  5:44   ` Patch "kbuild: add $(CLANG_FLAGS) to KBUILD_CPPFLAGS" has been added to the 5.4-stable tree gregkh
2025-08-11 23:51 ` [PATCH 5.4 6/6] kbuild: Add KBUILD_CPPFLAGS to as-option invocation Nathan Chancellor
2025-08-12  4:12   ` Sasha Levin
2025-08-24  5:44   ` Patch "kbuild: Add KBUILD_CPPFLAGS to as-option invocation" has been added to the 5.4-stable tree gregkh

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250811235151.1108688-3-nathan@kernel.org \
    --to=nathan@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=llvm@lists.linux.dev \
    --cc=sashal@kernel.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.