Skip to contentSkip to conversation

Fix build due to clang -Qunused-arguments change

PATCH Applied Nathan Chancellor 3 participants 21 messages Aug 11, 2025 – Aug 24, 2025

Subsystems (4)
lore
Share & tools
lore

Nathan Chancellor

author maintainer
#0 lore raw

cover Fix build due to clang -Qunused-arguments change

This is an updated version of [1], just for 5.4, which was waiting on commit 87c4e1459e80 ("ARM: 9448/1: Use an absolute path to unified.h in KBUILD_AFLAGS") to avoid regressing the build [2].

These changes are needed there due to an upstream LLVM change [3] that changes the behavior of -Qunused-arguments with unknown target options, which is only used in 6.1 and older since I removed it in commit 8d9acfce3332 ("kbuild: Stop using '-Qunused-arguments' with clang") in 6.3.

Please let me know if there are any issues.

[1]: https://lore.kernel.org/20250604233141.GA2374479@ax162/
[2]: https://lore.kernel.org/CACo-S-1qbCX4WAVFA63dWfHtrRHZBTyyr2js8Lx=Az03XHTTHg@mail.gmail.com/
[3]: https://github.com/llvm/llvm-project/commit/a4b2f4a72aa9b4655ecc723838830e0a7f29c9ca

Masahiro Yamada (1):
kbuild: add $(CLANG_FLAGS) to KBUILD_CPPFLAGS

Nathan Chancellor (4):
ARM: 9448/1: Use an absolute path to unified.h in KBUILD_AFLAGS
mips: Include KBUILD_CPPFLAGS in CHECKFLAGS invocation
kbuild: Add CLANG_FLAGS to as-instr
kbuild: Add KBUILD_CPPFLAGS to as-option invocation

Nick Desaulniers (1):
kbuild: Update assembler calls to use proper flags and language target

 Makefile               | 3 +--
 arch/arm/Makefile      | 2 +-
 arch/mips/Makefile     | 2 +-
 scripts/Kbuild.include | 8 ++++----
 4 files changed, 7 insertions(+), 8 deletions(-)

base-commit: 04b7726c3cdd2fb4da040c2b898bcf405ed607bd

Signature · 1 line
2.50.1
author maintainer
#1 lore raw

PATCH 1/6 ARM: 9448/1: Use an absolute path to unified.h in KBUILD_AFLAGS

commit 87c4e1459e80bf65066f864c762ef4dc932fad4b upstream.

After commit d5c8d6e0fa61 ("kbuild: Update assembler calls to use proper flags and language target"), which updated as-instr to use the 'assembler-with-cpp' language option, the Kbuild version of as-instr always fails internally for arch/arm with

<command-line>: fatal error: asm/unified.h: No such file or directory compilation terminated.

because '-include' flags are now taken into account by the compiler driver and as-instr does not have '$(LINUXINCLUDE)', so unified.h is not found.

This went unnoticed at the time of the Kbuild change because the last use of as-instr in Kbuild that arch/arm could reach was removed in 5.7 by commit 541ad0150ca4 ("arm: Remove 32bit KVM host support") but a stable backport of the Kbuild change to before that point exposed this potential issue if one were to be reintroduced.

Follow the general pattern of '-include' paths throughout the tree and make unified.h absolute using '$(srctree)' to ensure KBUILD_AFLAGS can be used independently.

Fixes d5c8d6e0fa61 ("kbuild: Update assembler calls to use proper flags and language target")
[nathan: Fix conflicts]
---
 arch/arm/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/Makefile +1 -1
index 4f098edfbf20..cb33ed8de5f8 100644
@@ -136,7 +136,7 @@ endif
 
 # Need -Uarm for gcc < 3.x
 KBUILD_CFLAGS	+=$(CFLAGS_ABI) $(CFLAGS_ISA) $(arch-y) $(tune-y) $(call cc-option,-mshort-load-bytes,$(call cc-option,-malignment-traps,)) -msoft-float -Uarm
-KBUILD_AFLAGS	+=$(CFLAGS_ABI) $(AFLAGS_ISA) $(arch-y) $(tune-y) -include asm/unified.h -msoft-float
+KBUILD_AFLAGS	+=$(CFLAGS_ABI) $(AFLAGS_ISA) $(arch-y) $(tune-y) -include $(srctree)/arch/arm/include/asm/unified.h -msoft-float
 
 CHECKFLAGS	+= -D__arm__
 
Signature · 1 line
2.50.1
author maintainer
#4 lore raw

PATCH 2/6 kbuild: Update assembler calls to use proper flags and language target

In reply to Nathan Chancellor

From: Nick Desaulniers <[email protected]>

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]

---
 scripts/Kbuild.include | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
scripts/Kbuild.include +4 -4
index 82eb69f07b35..11f905b95e65 100644
@@ -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)
Signature · 1 line
2.50.1
author maintainer
#8 lore raw

PATCH 3/6 mips: Include KBUILD_CPPFLAGS in CHECKFLAGS invocation

In reply to Nathan Chancellor

commit 08f6554ff90ef189e6b8f0303e57005bddfdd6a7 upstream.

A future change will move CLANG_FLAGS from KBUILD_{A,C}FLAGS to KBUILD_CPPFLAGS so that '--target' is available while preprocessing. When that occurs, the following error appears when building ARCH=mips with clang (tip of tree error shown):

clang: error: unsupported option '-mabi=' for target 'x86_64-pc-linux-gnu'

Add KBUILD_CPPFLAGS in the CHECKFLAGS invocation to keep everything working after the move.

---
 arch/mips/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/mips/Makefile +1 -1
index 4542258027a7..cc6f8265f28c 100644
@@ -319,7 +319,7 @@ KBUILD_CFLAGS += -fno-asynchronous-unwind-tables
 KBUILD_LDFLAGS		+= -m $(ld-emul)
 
 ifdef CONFIG_MIPS
-CHECKFLAGS += $(shell $(CC) $(KBUILD_CFLAGS) -dM -E -x c /dev/null | \
+CHECKFLAGS += $(shell $(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) -dM -E -x c /dev/null | \
 	egrep -vw '__GNUC_(MINOR_|PATCHLEVEL_)?_' | \
 	sed -e "s/^\#define /-D'/" -e "s/ /'='/" -e "s/$$/'/" -e 's/\$$/&&/g')
 endif
Signature · 1 line
2.50.1
author maintainer
#11 lore raw

PATCH 4/6 kbuild: Add CLANG_FLAGS to as-instr

In reply to Nathan Chancellor

commit cff6e7f50bd315e5b39c4e46c704ac587ceb965f upstream.

A future change will move CLANG_FLAGS from KBUILD_{A,C}FLAGS to KBUILD_CPPFLAGS so that '--target' is available while preprocessing. When that occurs, the following errors appear multiple times when building ARCH=powerpc powernv_defconfig:

ld.lld: error: vmlinux.a(arch/powerpc/kernel/head_64.o):(.text+0x12d4): relocation R_PPC64_ADDR16_HI out of range: -4611686018409717520 is not in [-2147483648, 2147483647]; references '__start___soft_mask_table' ld.lld: error: vmlinux.a(arch/powerpc/kernel/head_64.o):(.text+0x12e8): relocation R_PPC64_ADDR16_HI out of range: -4611686018409717392 is not in [-2147483648, 2147483647]; references '__stop___soft_mask_table'

Diffing the .o.cmd files reveals that -DHAVE_AS_ATHIGH=1 is not present anymore, because as-instr only uses KBUILD_AFLAGS, which will no longer contain '--target'.

Mirror Kconfig's as-instr and add CLANG_FLAGS explicitly to the invocation to ensure the target information is always present.

---
 scripts/Kbuild.include | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/Kbuild.include +1 -1
index 11f905b95e65..b01d3108596b 100644
@@ -108,7 +108,7 @@ as-option = $(call try-run,\
 # Usage: aflags-y += $(call as-instr,instr,option1,option2)
 
 as-instr = $(call try-run,\
-	printf "%b\n" "$(1)" | $(CC) -Werror $(KBUILD_AFLAGS) -c -x assembler-with-cpp -o "$$TMP" -,$(2),$(3))
+	printf "%b\n" "$(1)" | $(CC) -Werror $(CLANG_FLAGS) $(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)
Signature · 1 line
2.50.1
author maintainer
#14 lore raw

PATCH 5/6 kbuild: add $(CLANG_FLAGS) to KBUILD_CPPFLAGS

In reply to Nathan Chancellor

From: Masahiro Yamada <[email protected]>

commit feb843a469fb0ab00d2d23cfb9bcc379791011bb upstream.

When preprocessing arch/*/kernel/vmlinux.lds.S, the target triple is not passed to $(CPP) because we add it only to KBUILD_{C,A}FLAGS.

As a result, the linker script is preprocessed with predefined macros for the build host instead of the target.

Assuming you use an x86 build machine, compare the following:

 $ clang -dM -E -x c /dev/null
 $ clang -dM -E -x c /dev/null -target aarch64-linux-gnu

There is no actual problem presumably because our linker scripts do not rely on such predefined macros, but it is better to define correct ones.

Move $(CLANG_FLAGS) to KBUILD_CPPFLAGS, so that all *.c, *.S, *.lds.S will be processed with the proper target triple.

[Note]
After the patch submission, we got an actual problem that needs this commit. (CBL issue 1859)

---
 Makefile | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
Makefile +1 -2
index f65e282f4a3f..16a23aaaa547 100644
@@ -568,8 +568,7 @@ ifneq ($(LLVM_IAS),1)
 CLANG_FLAGS	+= -no-integrated-as
 endif
 CLANG_FLAGS	+= -Werror=unknown-warning-option
-KBUILD_CFLAGS	+= $(CLANG_FLAGS)
-KBUILD_AFLAGS	+= $(CLANG_FLAGS)
+KBUILD_CPPFLAGS	+= $(CLANG_FLAGS)
 export CLANG_FLAGS
 endif
 
Signature · 1 line
2.50.1
author maintainer
#18 lore raw

PATCH 6/6 kbuild: Add KBUILD_CPPFLAGS to as-option invocation

In reply to Nathan Chancellor

commit 43fc0a99906e04792786edf8534d8d58d1e9de0c upstream.

After commit feb843a469fb ("kbuild: add $(CLANG_FLAGS) to KBUILD_CPPFLAGS"), there is an error while building certain PowerPC assembly files with clang:

arch/powerpc/lib/copypage_power7.S: Assembler messages:
arch/powerpc/lib/copypage_power7.S:34: Error: junk at end of line: 0b01000' arch/powerpc/lib/copypage_power7.S:35: Error: junk at end of line: 0b01010' arch/powerpc/lib/copypage_power7.S:37: Error: junk at end of line: 0b01000' arch/powerpc/lib/copypage_power7.S:38: Error: junk at end of line: 0b01010' arch/powerpc/lib/copypage_power7.S:40: Error: junk at end of line: `0b01010'
clang: error: assembler command failed with exit code 1 (use -v to see invocation)

as-option only uses KBUILD_AFLAGS, so after removing CLANG_FLAGS from KBUILD_AFLAGS, there is no more '--target=' or '--prefix=' flags. As a result of those missing flags, the host target
will be tested during as-option calls and likely fail, meaning necessary flags may not get added when building assembly files, resulting in errors like seen above.

Add KBUILD_CPPFLAGS to as-option invocations to clear up the errors. This should have been done in commit d5c8d6e0fa61 ("kbuild: Update assembler calls to use proper flags and language target"), which switched from using the assembler target to the assembler-with-cpp target, so flags that affect preprocessing are passed along in all relevant tests. as-option now mirrors cc-option.

---
 scripts/Kbuild.include | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/Kbuild.include +1 -1
index b01d3108596b..4d2b8e659747 100644
@@ -102,7 +102,7 @@ try-run = $(shell set -e;		\
 # Usage: aflags-y += $(call as-option,-Wa$(comma)-isa=foo,)
 
 as-option = $(call try-run,\
-	$(CC) -Werror $(KBUILD_AFLAGS) $(1) -c -x assembler-with-cpp /dev/null -o "$$TMP",$(1),$(2))
+	$(CC) -Werror $(KBUILD_CPPFLAGS) $(KBUILD_AFLAGS) $(1) -c -x assembler-with-cpp /dev/null -o "$$TMP",$(1),$(2))
 
 # as-instr
 # Usage: aflags-y += $(call as-instr,instr,option1,option2)
Signature · 1 line
2.50.1
maintainer
#12 lore raw

Re: [PATCH 5.4 4/6] kbuild: Add CLANG_FLAGS to as-instr

In reply to Nathan Chancellor

[ Sasha's backport helper bot ]

Hi,

✅ All tests passed successfully. No issues detected. No action required from the submitter.

The upstream commit SHA1 provided is correct: cff6e7f50bd315e5b39c4e46c704ac587ceb965f

Status in newer kernel trees:
6.15.y | Present (exact SHA1)
6.12.y | Present (exact SHA1)
6.6.y | Present (exact SHA1)
6.1.y | Present (different SHA1: ae5a2797e742)
5.15.y | Present (different SHA1: f85d6a08cc9f)
5.10.y | Present (different SHA1: 58c2cac0e779)

Note: Could not generate a diff with upstream commit:
---
Note: Could not generate diff - patch failed to apply for comparison
---

Results of testing on various branches:

| Branch                    | Patch Apply | Build Test |
|---------------------------|-------------|------------|
| 5.4                       | Success     | Success    |
maintainer
#15 lore raw

Re: [PATCH 5.4 5/6] kbuild: add $(CLANG_FLAGS) to KBUILD_CPPFLAGS

In reply to Nathan Chancellor

[ Sasha's backport helper bot ]

Hi,

Summary of potential issues:
ℹ️ This is part 5/6 of a series
⚠️ Found follow-up fixes in mainline

The upstream commit SHA1 provided is correct: feb843a469fb0ab00d2d23cfb9bcc379791011bb

WARNING: Author mismatch between patch and upstream commit:
Backport author: Nathan Chancellor <[email protected]> Commit author: Masahiro Yamada <[email protected]>

Status in newer kernel trees:
6.15.y | Present (exact SHA1)
6.12.y | Present (exact SHA1)
6.6.y | Present (exact SHA1)
6.1.y | Not found
5.15.y | Not found
5.10.y | Not found

Found fixes commits:
02e9a22ceef0 kbuild: hdrcheck: fix cross build with clang 1b71c2fb04e7 kbuild: userprogs: fix bitsize and target detection on clang 43fc0a99906e kbuild: Add KBUILD_CPPFLAGS to as-option invocation

Note: The patch differs from the upstream commit:
---

1:  feb843a469fb < -:  ------------ kbuild: add $(CLANG_FLAGS) to KBUILD_CPPFLAGS
-:  ------------ > 1:  69d313b2b765 kbuild: add $(CLANG_FLAGS) to KBUILD_CPPFLAGS

---

NOTE: These results are for this patch alone. Full series testing will be performed when all parts are received.

Results of testing on various branches:

| Branch                    | Patch Apply | Build Test |
|---------------------------|-------------|------------|
| 5.4                       | Success     | Success    |
maintainer Tested-by Linux Kernel Functional Testing Tested-by Anders Roxell on v1 2/6
#5 lore raw

Re: [PATCH 5.4 2/6] kbuild: Update assembler calls to use proper flags and language target

In reply to Nathan Chancellor

[ Sasha's backport helper bot ]

Hi,

Summary of potential issues:
ℹ️ This is part 2/6 of a series
⚠️ Found follow-up fixes in mainline

The upstream commit SHA1 provided is correct: d5c8d6e0fa61401a729e9eb6a9c7077b2d3aebb0

WARNING: Author mismatch between patch and upstream commit:
Backport author: Nathan Chancellor <[email protected]> Commit author: Nick Desaulniers <[email protected]>

Status in newer kernel trees:
6.15.y | Present (exact SHA1)
6.12.y | Present (exact SHA1)
6.6.y | Present (exact SHA1)
6.1.y | Present (different SHA1: a76d4933c38e)
5.15.y | Present (different SHA1: cefb372db498)
5.10.y | Present (different SHA1: 7fa1764188bf)

Found fixes commits:
87c4e1459e80 ARM: 9448/1: Use an absolute path to unified.h in KBUILD_AFLAGS

Note: The patch differs from the upstream commit:
---
1: d5c8d6e0fa61 ! 1: e516ff739515 kbuild: Update assembler calls to use proper flags and language target
@@ Metadata
## Commit message ##
kbuild: Update assembler calls to use proper flags and language target

+ 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
@@ Commit message

+ Signed-off-by: Nathan Chancellor <[email protected]>

- ## scripts/Kconfig.include ##
-@@ scripts/Kconfig.include: 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)
-
- ## scripts/Makefile.compiler ##
-@@ scripts/Makefile.compiler: try-run = $(shell set -e; \
+ ## scripts/Kbuild.include ##
+@@ scripts/Kbuild.include: try-run = $(shell set -e; \
fi)

# as-option
@@ scripts/Makefile.compiler: try-run = $(shell set -e; \

# __cc-option
# Usage: MY_CFLAGS += $(call __cc-option,$(CC),$(MY_CFLAGS),-march=winchip-c6,-march=i586)
-
- ## scripts/as-version.sh ##
-@@ scripts/as-version.sh: 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=' '

---

NOTE: These results are for this patch alone. Full series testing will be performed when all parts are received.

Results of testing on various branches:

| Branch                    | Patch Apply | Build Test |
|---------------------------|-------------|------------|
| 5.4                       | Success     | Success    |
maintainer
#19 lore raw

Re: [PATCH 5.4 6/6] kbuild: Add KBUILD_CPPFLAGS to as-option invocation

In reply to Nathan Chancellor

[ Sasha's backport helper bot ]

Hi,

✅ All tests passed successfully. No issues detected. No action required from the submitter.

The upstream commit SHA1 provided is correct: 43fc0a99906e04792786edf8534d8d58d1e9de0c

Status in newer kernel trees:
6.15.y | Present (exact SHA1)
6.12.y | Present (exact SHA1)
6.6.y | Present (exact SHA1)
6.1.y | Present (different SHA1: 0f8b3913b3fd)
5.15.y | Present (different SHA1: 510ce6a1393c)
5.10.y | Present (different SHA1: 79a4fba715fa)

Note: Could not generate a diff with upstream commit:
---
Note: Could not generate diff - patch failed to apply for comparison
---

Results of testing on various branches:

| Branch                    | Patch Apply | Build Test |
|---------------------------|-------------|------------|
| 5.4                       | Success     | Success    |
maintainer
#2 lore raw

Re: [PATCH 5.4 1/6] ARM: 9448/1: Use an absolute path to unified.h in KBUILD_AFLAGS

In reply to Nathan Chancellor

[ Sasha's backport helper bot ]

Hi,

✅ All tests passed successfully. No issues detected. No action required from the submitter.

The upstream commit SHA1 provided is correct: 87c4e1459e80bf65066f864c762ef4dc932fad4b

Status in newer kernel trees:
6.15.y | Not found
6.12.y | Not found
6.6.y | Not found
6.1.y | Not found
5.15.y | Not found
5.10.y | Not found

Note: The patch differs from the upstream commit:
---

1:  87c4e1459e80 < -:  ------------ ARM: 9448/1: Use an absolute path to unified.h in KBUILD_AFLAGS
-:  ------------ > 1:  8bf09d3cd9a8 ARM: 9448/1: Use an absolute path to unified.h in KBUILD_AFLAGS

---

Results of testing on various branches:

| Branch                    | Patch Apply | Build Test |
|---------------------------|-------------|------------|
| 5.4                       | Success     | Success    |
maintainer
#9 lore raw

Re: [PATCH 5.4 3/6] mips: Include KBUILD_CPPFLAGS in CHECKFLAGS invocation

In reply to Nathan Chancellor

[ Sasha's backport helper bot ]

Hi,

✅ All tests passed successfully. No issues detected. No action required from the submitter.

The upstream commit SHA1 provided is correct: 08f6554ff90ef189e6b8f0303e57005bddfdd6a7

Status in newer kernel trees:
6.15.y | Present (exact SHA1)
6.12.y | Present (exact SHA1)
6.6.y | Present (exact SHA1)
6.1.y | Present (different SHA1: 2995dbfe98e7)
5.15.y | Present (different SHA1: d36719f29376)
5.10.y | Present (different SHA1: 9562b9f708e9)

Note: The patch differs from the upstream commit:
---
1: 08f6554ff90e ! 1: 49e341f4bf2e mips: Include KBUILD_CPPFLAGS in CHECKFLAGS invocation
@@ Metadata
## Commit message ##
mips: Include KBUILD_CPPFLAGS in CHECKFLAGS invocation

+ commit 08f6554ff90ef189e6b8f0303e57005bddfdd6a7 upstream.
+
A future change will move CLANG_FLAGS from KBUILD_{A,C}FLAGS to KBUILD_CPPFLAGS so that '--target' is available while preprocessing. When that occurs, the following error appears when building ARCH=mips
@@ Commit message

+ Signed-off-by: Nathan Chancellor <[email protected]>

## arch/mips/Makefile ##
@@ arch/mips/Makefile: KBUILD_CFLAGS += -fno-asynchronous-unwind-tables
@@ arch/mips/Makefile: KBUILD_CFLAGS += -fno-asynchronous-unwind-tables
ifdef CONFIG_MIPS
-CHECKFLAGS += $(shell $(CC) $(KBUILD_CFLAGS) -dM -E -x c /dev/null | \
+CHECKFLAGS += $(shell $(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) -dM -E -x c /dev/null | \
- grep -E -vw '__GNUC_(MINOR_|PATCHLEVEL_)?_' | \
+ egrep -vw '__GNUC_(MINOR_|PATCHLEVEL_)?_' | \
sed -e "s/^\#define /-D'/" -e "s/ /'='/" -e "s/$$/'/" -e 's/\$$/&&/g')
endif

---

Results of testing on various branches:

| Branch                    | Patch Apply | Build Test |
|---------------------------|-------------|------------|
| 5.4                       | Success     | Success    |
author maintainer
#16 lore raw

Re: [PATCH 5.4 5/6] kbuild: add $(CLANG_FLAGS) to KBUILD_CPPFLAGS

In reply to Sasha Levin

Hi,

Quoted 5 lines · Sasha Levin
Quoted 1 line

The upstream commit SHA1 provided is correct: feb843a469fb0ab00d2d23cfb9bcc379791011bb

WARNING: Author mismatch between patch and upstream commit:
Backport author: Nathan Chancellor <[email protected]> Commit author: Masahiro Yamada <[email protected]>

Hmmm, the patch has a "From:" header that has Masahiro as the author, is that not sufficient for authorship?

Quoted 1 line

Status in newer kernel trees:

...

Quoted 3 lines

6.1.y | Not found
5.15.y | Not found
5.10.y | Not found

Odd, it appears to be there to me?

6.1.142: 8d21861f91a1 ("kbuild: add $(CLANG_FLAGS) to KBUILD_CPPFLAGS") 5.15.186: 0690824cc325 ("kbuild: add $(CLANG_FLAGS) to KBUILD_CPPFLAGS") 5.10.239: 951dfb0bdcd6 ("kbuild: add $(CLANG_FLAGS) to KBUILD_CPPFLAGS")

Quoted 2 lines

Found fixes commits:
02e9a22ceef0 kbuild: hdrcheck: fix cross build with clang

Unnecessary in 5.4: https://lore.kernel.org/20250617233200.GC3356351@ax162/

Quoted 1 line

1b71c2fb04e7 kbuild: userprogs: fix bitsize and target detection on clang

Uncessary in 5.4: https://lore.kernel.org/20250617232006.GB3356351@ax162/

Quoted 1 line

43fc0a99906e kbuild: Add KBUILD_CPPFLAGS to as-option invocation

43fc0a99906e is present in this series after feb843a469fb0a because that is how it happened upstream but 43fc0a99906e could be applied before feb843a469fb0a in stable.

Cheers,
Nathan

author maintainer
#6 lore raw

Re: [PATCH 5.4 2/6] kbuild: Update assembler calls to use proper flags and language target

In reply to Sasha Levin
Quoted 5 lines · Sasha Levin

The upstream commit SHA1 provided is correct: d5c8d6e0fa61401a729e9eb6a9c7077b2d3aebb0

WARNING: Author mismatch between patch and upstream commit:
Backport author: Nathan Chancellor <[email protected]> Commit author: Nick Desaulniers <[email protected]>

Same comment as the other change, there is a From: line in the patch, so shouldn't Nick still have authorship of the backport?

Quoted 2 lines

Found fixes commits:
87c4e1459e80 ARM: 9448/1: Use an absolute path to unified.h in KBUILD_AFLAGS

Present as the first change of the series.

Cheers,
Nathan

maintainer Applied
#3 lore raw

Patch "ARM: 9448/1: Use an absolute path to unified.h in KBUILD_AFLAGS" has been added to the 5.4-stable tree

In reply to Nathan Chancellor

This is a note to let you know that I've just added the patch titled

ARM: 9448/1: Use an absolute path to unified.h in KBUILD_AFLAGS

to the 5.4-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:

     arm-9448-1-use-an-absolute-path-to-unified.h-in-kbuild_aflags.patch

and it can be found in the queue-5.4 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.

From [email protected] Tue Aug 12 01:52:48 2025
From: Nathan Chancellor <[email protected]>
Date: Mon, 11 Aug 2025 16:51:46 -0700
Subject: ARM: 9448/1: Use an absolute path to unified.h in KBUILD_AFLAGS
To: Greg Kroah-Hartman <[email protected]>, Sasha Levin <[email protected]>
Cc: [email protected], [email protected]
Message-ID: <[email protected]>

From: Nathan Chancellor <[email protected]>

commit 87c4e1459e80bf65066f864c762ef4dc932fad4b upstream.

After commit d5c8d6e0fa61 ("kbuild: Update assembler calls to use proper flags and language target"), which updated as-instr to use the 'assembler-with-cpp' language option, the Kbuild version of as-instr always fails internally for arch/arm with

<command-line>: fatal error: asm/unified.h: No such file or directory compilation terminated.

because '-include' flags are now taken into account by the compiler driver and as-instr does not have '$(LINUXINCLUDE)', so unified.h is not found.

This went unnoticed at the time of the Kbuild change because the last use of as-instr in Kbuild that arch/arm could reach was removed in 5.7 by commit 541ad0150ca4 ("arm: Remove 32bit KVM host support") but a stable backport of the Kbuild change to before that point exposed this potential issue if one were to be reintroduced.

Follow the general pattern of '-include' paths throughout the tree and make unified.h absolute using '$(srctree)' to ensure KBUILD_AFLAGS can be used independently.

Fixes d5c8d6e0fa61 ("kbuild: Update assembler calls to use proper flags and language target")
[nathan: Fix conflicts]
---
 arch/arm/Makefile |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/Makefile +1 -1
@@ -136,7 +136,7 @@ endif
 
 # Need -Uarm for gcc < 3.x
 KBUILD_CFLAGS	+=$(CFLAGS_ABI) $(CFLAGS_ISA) $(arch-y) $(tune-y) $(call cc-option,-mshort-load-bytes,$(call cc-option,-malignment-traps,)) -msoft-float -Uarm
-KBUILD_AFLAGS	+=$(CFLAGS_ABI) $(AFLAGS_ISA) $(arch-y) $(tune-y) -include asm/unified.h -msoft-float
+KBUILD_AFLAGS	+=$(CFLAGS_ABI) $(AFLAGS_ISA) $(arch-y) $(tune-y) -include $(srctree)/arch/arm/include/asm/unified.h -msoft-float
 
 CHECKFLAGS	+= -D__arm__
 

Patches currently in stable-queue which might be from [email protected] are

queue-5.4/kbuild-add-clang_flags-to-as-instr.patch queue-5.4/wifi-brcmsmac-remove-const-from-tbl_ptr-parameter-in-wlc_lcnphy_common_read_table.patch queue-5.4/mips-include-kbuild_cppflags-in-checkflags-invocation.patch queue-5.4/kbuild-add-clang_flags-to-kbuild_cppflags.patch queue-5.4/ftrace-also-allocate-and-copy-hash-for-reading-of-filter-files.patch queue-5.4/memstick-core-zero-initialize-id_reg-in-h_memstick_read_dev_id.patch queue-5.4/kbuild-update-assembler-calls-to-use-proper-flags-and-language-target.patch queue-5.4/phonet-pep-move-call-to-pn_skb_get_dst_sockaddr-earlier-in-pep_sock_accept.patch queue-5.4/arm-9448-1-use-an-absolute-path-to-unified.h-in-kbuild_aflags.patch queue-5.4/kbuild-add-kbuild_cppflags-to-as-option-invocation.patch queue-5.4/usb-atm-cxacru-merge-cxacru_upload_firmware-into-cxacru_heavy_init.patch

maintainer Applied
#13 lore raw

Patch "kbuild: Add CLANG_FLAGS to as-instr" has been added to the 5.4-stable tree

In reply to Nathan Chancellor

This is a note to let you know that I've just added the patch titled

kbuild: Add CLANG_FLAGS to as-instr

to the 5.4-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
kbuild-add-clang_flags-to-as-instr.patch
and it can be found in the queue-5.4 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.

From [email protected] Tue Aug 12 01:52:35 2025
From: Nathan Chancellor <[email protected]>
Date: Mon, 11 Aug 2025 16:51:49 -0700
Subject: kbuild: Add CLANG_FLAGS to as-instr
To: Greg Kroah-Hartman <[email protected]>, Sasha Levin <[email protected]>
Cc: [email protected], [email protected]
Message-ID: <[email protected]>

From: Nathan Chancellor <[email protected]>

commit cff6e7f50bd315e5b39c4e46c704ac587ceb965f upstream.

A future change will move CLANG_FLAGS from KBUILD_{A,C}FLAGS to KBUILD_CPPFLAGS so that '--target' is available while preprocessing. When that occurs, the following errors appear multiple times when building ARCH=powerpc powernv_defconfig:

ld.lld: error: vmlinux.a(arch/powerpc/kernel/head_64.o):(.text+0x12d4): relocation R_PPC64_ADDR16_HI out of range: -4611686018409717520 is not in [-2147483648, 2147483647]; references '__start___soft_mask_table' ld.lld: error: vmlinux.a(arch/powerpc/kernel/head_64.o):(.text+0x12e8): relocation R_PPC64_ADDR16_HI out of range: -4611686018409717392 is not in [-2147483648, 2147483647]; references '__stop___soft_mask_table'

Diffing the .o.cmd files reveals that -DHAVE_AS_ATHIGH=1 is not present anymore, because as-instr only uses KBUILD_AFLAGS, which will no longer contain '--target'.

Mirror Kconfig's as-instr and add CLANG_FLAGS explicitly to the invocation to ensure the target information is always present.

---
 scripts/Kbuild.include |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/Kbuild.include +1 -1
@@ -108,7 +108,7 @@ as-option = $(call try-run,\
 # Usage: aflags-y += $(call as-instr,instr,option1,option2)
 
 as-instr = $(call try-run,\
-	printf "%b\n" "$(1)" | $(CC) -Werror $(KBUILD_AFLAGS) -c -x assembler-with-cpp -o "$$TMP" -,$(2),$(3))
+	printf "%b\n" "$(1)" | $(CC) -Werror $(CLANG_FLAGS) $(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)

Patches currently in stable-queue which might be from [email protected] are

queue-5.4/kbuild-add-clang_flags-to-as-instr.patch queue-5.4/wifi-brcmsmac-remove-const-from-tbl_ptr-parameter-in-wlc_lcnphy_common_read_table.patch queue-5.4/mips-include-kbuild_cppflags-in-checkflags-invocation.patch queue-5.4/kbuild-add-clang_flags-to-kbuild_cppflags.patch queue-5.4/ftrace-also-allocate-and-copy-hash-for-reading-of-filter-files.patch queue-5.4/memstick-core-zero-initialize-id_reg-in-h_memstick_read_dev_id.patch queue-5.4/kbuild-update-assembler-calls-to-use-proper-flags-and-language-target.patch queue-5.4/phonet-pep-move-call-to-pn_skb_get_dst_sockaddr-earlier-in-pep_sock_accept.patch queue-5.4/arm-9448-1-use-an-absolute-path-to-unified.h-in-kbuild_aflags.patch queue-5.4/kbuild-add-kbuild_cppflags-to-as-option-invocation.patch queue-5.4/usb-atm-cxacru-merge-cxacru_upload_firmware-into-cxacru_heavy_init.patch

maintainer Applied
#17 lore raw

Patch "kbuild: add $(CLANG_FLAGS) to KBUILD_CPPFLAGS" has been added to the 5.4-stable tree

In reply to Nathan Chancellor

This is a note to let you know that I've just added the patch titled

    kbuild: add $(CLANG_FLAGS) to KBUILD_CPPFLAGS

to the 5.4-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
kbuild-add-clang_flags-to-kbuild_cppflags.patch
and it can be found in the queue-5.4 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.

From [email protected] Tue Aug 12 01:53:32 2025
From: Nathan Chancellor <[email protected]>
Date: Mon, 11 Aug 2025 16:51:50 -0700
Subject: kbuild: add $(CLANG_FLAGS) to KBUILD_CPPFLAGS
To: Greg Kroah-Hartman <[email protected]>, Sasha Levin <[email protected]>
Cc: [email protected], [email protected]
Message-ID: <[email protected]>

From: Masahiro Yamada <[email protected]>

commit feb843a469fb0ab00d2d23cfb9bcc379791011bb upstream.

When preprocessing arch/*/kernel/vmlinux.lds.S, the target triple is not passed to $(CPP) because we add it only to KBUILD_{C,A}FLAGS.

As a result, the linker script is preprocessed with predefined macros for the build host instead of the target.

Assuming you use an x86 build machine, compare the following:

 $ clang -dM -E -x c /dev/null
 $ clang -dM -E -x c /dev/null -target aarch64-linux-gnu

There is no actual problem presumably because our linker scripts do not rely on such predefined macros, but it is better to define correct ones.

Move $(CLANG_FLAGS) to KBUILD_CPPFLAGS, so that all *.c, *.S, *.lds.S will be processed with the proper target triple.

[Note]
After the patch submission, we got an actual problem that needs this commit. (CBL issue 1859)

---
 Makefile |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
Makefile +1 -2
@@ -568,8 +568,7 @@ ifneq ($(LLVM_IAS),1)
 CLANG_FLAGS	+= -no-integrated-as
 endif
 CLANG_FLAGS	+= -Werror=unknown-warning-option
-KBUILD_CFLAGS	+= $(CLANG_FLAGS)
-KBUILD_AFLAGS	+= $(CLANG_FLAGS)
+KBUILD_CPPFLAGS	+= $(CLANG_FLAGS)
 export CLANG_FLAGS
 endif
 

Patches currently in stable-queue which might be from [email protected] are

queue-5.4/kbuild-add-clang_flags-to-as-instr.patch queue-5.4/wifi-brcmsmac-remove-const-from-tbl_ptr-parameter-in-wlc_lcnphy_common_read_table.patch queue-5.4/mips-include-kbuild_cppflags-in-checkflags-invocation.patch queue-5.4/kbuild-add-clang_flags-to-kbuild_cppflags.patch queue-5.4/ftrace-also-allocate-and-copy-hash-for-reading-of-filter-files.patch queue-5.4/memstick-core-zero-initialize-id_reg-in-h_memstick_read_dev_id.patch queue-5.4/kbuild-update-assembler-calls-to-use-proper-flags-and-language-target.patch queue-5.4/phonet-pep-move-call-to-pn_skb_get_dst_sockaddr-earlier-in-pep_sock_accept.patch queue-5.4/arm-9448-1-use-an-absolute-path-to-unified.h-in-kbuild_aflags.patch queue-5.4/kbuild-add-kbuild_cppflags-to-as-option-invocation.patch queue-5.4/usb-atm-cxacru-merge-cxacru_upload_firmware-into-cxacru_heavy_init.patch

maintainer Applied
#20 lore raw

Patch "kbuild: Add KBUILD_CPPFLAGS to as-option invocation" has been added to the 5.4-stable tree

In reply to Nathan Chancellor

This is a note to let you know that I've just added the patch titled

kbuild: Add KBUILD_CPPFLAGS to as-option invocation

to the 5.4-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
kbuild-add-kbuild_cppflags-to-as-option-invocation.patch
and it can be found in the queue-5.4 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.

From [email protected] Tue Aug 12 01:53:34 2025
From: Nathan Chancellor <[email protected]>
Date: Mon, 11 Aug 2025 16:51:51 -0700
Subject: kbuild: Add KBUILD_CPPFLAGS to as-option invocation
To: Greg Kroah-Hartman <[email protected]>, Sasha Levin <[email protected]>
Cc: [email protected], [email protected]
Message-ID: <[email protected]>

From: Nathan Chancellor <[email protected]>

commit 43fc0a99906e04792786edf8534d8d58d1e9de0c upstream.

After commit feb843a469fb ("kbuild: add $(CLANG_FLAGS) to KBUILD_CPPFLAGS"), there is an error while building certain PowerPC assembly files with clang:

arch/powerpc/lib/copypage_power7.S: Assembler messages:
arch/powerpc/lib/copypage_power7.S:34: Error: junk at end of line: 0b01000' arch/powerpc/lib/copypage_power7.S:35: Error: junk at end of line: 0b01010' arch/powerpc/lib/copypage_power7.S:37: Error: junk at end of line: 0b01000' arch/powerpc/lib/copypage_power7.S:38: Error: junk at end of line: 0b01010' arch/powerpc/lib/copypage_power7.S:40: Error: junk at end of line: `0b01010'
clang: error: assembler command failed with exit code 1 (use -v to see invocation)

as-option only uses KBUILD_AFLAGS, so after removing CLANG_FLAGS from KBUILD_AFLAGS, there is no more '--target=' or '--prefix=' flags. As a result of those missing flags, the host target
will be tested during as-option calls and likely fail, meaning necessary flags may not get added when building assembly files, resulting in errors like seen above.

Add KBUILD_CPPFLAGS to as-option invocations to clear up the errors. This should have been done in commit d5c8d6e0fa61 ("kbuild: Update assembler calls to use proper flags and language target"), which switched from using the assembler target to the assembler-with-cpp target, so flags that affect preprocessing are passed along in all relevant tests. as-option now mirrors cc-option.

---
 scripts/Kbuild.include |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/Kbuild.include +1 -1
@@ -102,7 +102,7 @@ try-run = $(shell set -e;		\
 # Usage: aflags-y += $(call as-option,-Wa$(comma)-isa=foo,)
 
 as-option = $(call try-run,\
-	$(CC) -Werror $(KBUILD_AFLAGS) $(1) -c -x assembler-with-cpp /dev/null -o "$$TMP",$(1),$(2))
+	$(CC) -Werror $(KBUILD_CPPFLAGS) $(KBUILD_AFLAGS) $(1) -c -x assembler-with-cpp /dev/null -o "$$TMP",$(1),$(2))
 
 # as-instr
 # Usage: aflags-y += $(call as-instr,instr,option1,option2)

Patches currently in stable-queue which might be from [email protected] are

queue-5.4/kbuild-add-clang_flags-to-as-instr.patch queue-5.4/wifi-brcmsmac-remove-const-from-tbl_ptr-parameter-in-wlc_lcnphy_common_read_table.patch queue-5.4/mips-include-kbuild_cppflags-in-checkflags-invocation.patch queue-5.4/kbuild-add-clang_flags-to-kbuild_cppflags.patch queue-5.4/ftrace-also-allocate-and-copy-hash-for-reading-of-filter-files.patch queue-5.4/memstick-core-zero-initialize-id_reg-in-h_memstick_read_dev_id.patch queue-5.4/kbuild-update-assembler-calls-to-use-proper-flags-and-language-target.patch queue-5.4/phonet-pep-move-call-to-pn_skb_get_dst_sockaddr-earlier-in-pep_sock_accept.patch queue-5.4/arm-9448-1-use-an-absolute-path-to-unified.h-in-kbuild_aflags.patch queue-5.4/kbuild-add-kbuild_cppflags-to-as-option-invocation.patch queue-5.4/usb-atm-cxacru-merge-cxacru_upload_firmware-into-cxacru_heavy_init.patch

maintainer Applied
#10 lore raw

Patch "mips: Include KBUILD_CPPFLAGS in CHECKFLAGS invocation" has been added to the 5.4-stable tree

In reply to Nathan Chancellor

This is a note to let you know that I've just added the patch titled

mips: Include KBUILD_CPPFLAGS in CHECKFLAGS invocation

to the 5.4-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
mips-include-kbuild_cppflags-in-checkflags-invocation.patch
and it can be found in the queue-5.4 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.

From [email protected] Tue Aug 12 01:52:33 2025
From: Nathan Chancellor <[email protected]>
Date: Mon, 11 Aug 2025 16:51:48 -0700
Subject: mips: Include KBUILD_CPPFLAGS in CHECKFLAGS invocation
To: Greg Kroah-Hartman <[email protected]>, Sasha Levin <[email protected]>
Cc: [email protected], [email protected]
Message-ID: <[email protected]>

From: Nathan Chancellor <[email protected]>

commit 08f6554ff90ef189e6b8f0303e57005bddfdd6a7 upstream.

A future change will move CLANG_FLAGS from KBUILD_{A,C}FLAGS to KBUILD_CPPFLAGS so that '--target' is available while preprocessing. When that occurs, the following error appears when building ARCH=mips with clang (tip of tree error shown):

clang: error: unsupported option '-mabi=' for target 'x86_64-pc-linux-gnu'

Add KBUILD_CPPFLAGS in the CHECKFLAGS invocation to keep everything working after the move.

---
 arch/mips/Makefile |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/mips/Makefile +1 -1
@@ -319,7 +319,7 @@ KBUILD_CFLAGS += -fno-asynchronous-unwin
 KBUILD_LDFLAGS		+= -m $(ld-emul)
 
 ifdef CONFIG_MIPS
-CHECKFLAGS += $(shell $(CC) $(KBUILD_CFLAGS) -dM -E -x c /dev/null | \
+CHECKFLAGS += $(shell $(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) -dM -E -x c /dev/null | \
 	egrep -vw '__GNUC_(MINOR_|PATCHLEVEL_)?_' | \
 	sed -e "s/^\#define /-D'/" -e "s/ /'='/" -e "s/$$/'/" -e 's/\$$/&&/g')
 endif

Patches currently in stable-queue which might be from [email protected] are

queue-5.4/kbuild-add-clang_flags-to-as-instr.patch queue-5.4/wifi-brcmsmac-remove-const-from-tbl_ptr-parameter-in-wlc_lcnphy_common_read_table.patch queue-5.4/mips-include-kbuild_cppflags-in-checkflags-invocation.patch queue-5.4/kbuild-add-clang_flags-to-kbuild_cppflags.patch queue-5.4/ftrace-also-allocate-and-copy-hash-for-reading-of-filter-files.patch queue-5.4/memstick-core-zero-initialize-id_reg-in-h_memstick_read_dev_id.patch queue-5.4/kbuild-update-assembler-calls-to-use-proper-flags-and-language-target.patch queue-5.4/phonet-pep-move-call-to-pn_skb_get_dst_sockaddr-earlier-in-pep_sock_accept.patch queue-5.4/arm-9448-1-use-an-absolute-path-to-unified.h-in-kbuild_aflags.patch queue-5.4/kbuild-add-kbuild_cppflags-to-as-option-invocation.patch queue-5.4/usb-atm-cxacru-merge-cxacru_upload_firmware-into-cxacru_heavy_init.patch

maintainer Applied
#7 lore raw

Patch "kbuild: Update assembler calls to use proper flags and language target" has been added to the 5.4-stable tree

In reply to Nathan Chancellor

This is a note to let you know that I've just added the patch titled

kbuild: Update assembler calls to use proper flags and language target

to the 5.4-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
kbuild-update-assembler-calls-to-use-proper-flags-and-language-target.patch
and it can be found in the queue-5.4 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.

From [email protected] Tue Aug 12 01:52:49 2025
From: Nathan Chancellor <[email protected]>
Date: Mon, 11 Aug 2025 16:51:47 -0700
Subject: kbuild: Update assembler calls to use proper flags and language target
To: Greg Kroah-Hartman <[email protected]>, Sasha Levin <[email protected]>
Cc: [email protected], [email protected]
Message-ID: <[email protected]>

From: Nick Desaulniers <[email protected]>

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]

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

Patches currently in stable-queue which might be from [email protected] are

queue-5.4/kbuild-add-clang_flags-to-as-instr.patch queue-5.4/wifi-brcmsmac-remove-const-from-tbl_ptr-parameter-in-wlc_lcnphy_common_read_table.patch queue-5.4/mips-include-kbuild_cppflags-in-checkflags-invocation.patch queue-5.4/kbuild-add-clang_flags-to-kbuild_cppflags.patch queue-5.4/ftrace-also-allocate-and-copy-hash-for-reading-of-filter-files.patch queue-5.4/memstick-core-zero-initialize-id_reg-in-h_memstick_read_dev_id.patch queue-5.4/kbuild-update-assembler-calls-to-use-proper-flags-and-language-target.patch queue-5.4/phonet-pep-move-call-to-pn_skb_get_dst_sockaddr-earlier-in-pep_sock_accept.patch queue-5.4/arm-9448-1-use-an-absolute-path-to-unified.h-in-kbuild_aflags.patch queue-5.4/kbuild-add-kbuild_cppflags-to-as-option-invocation.patch queue-5.4/usb-atm-cxacru-merge-cxacru_upload_firmware-into-cxacru_heavy_init.patch