Skip to content

Commit 117ae29

Browse files
committed
patches: Add Kbuild series to 5.4 for LLVM 21 -Qunused-argument changes
See [1] for a primer on why this is needed. There were build failures in 5.4 with this applied, for which it was backed out of [2] and I submitted a fix for upstream inclusion [3]. Apply these until [3] makes its way upstream and back into 5.4 with the rest of these changes. Link: https://lore.kernel.org/20250604233141.GA2374479@ax162/ [1] Link: https://lore.kernel.org/2025062508-vertical-rewrite-4bce@gregkh/ [2] Link: https://lore.kernel.org/20250618-arm-expand-include-unified-h-path-v1-1-aef6eb4c44ca@kernel.org/ [3] Signed-off-by: Nathan Chancellor <[email protected]>
1 parent d3a5c12 commit 117ae29

11 files changed

+544
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
From 668a8b64118d2d263025e92ebab1233f2a9b9c1c Mon Sep 17 00:00:00 2001
2+
From: Nick Desaulniers <[email protected]>
3+
Date: Wed, 11 Jan 2023 20:04:58 -0700
4+
Subject: [PATCH 1/9] x86/boot/compressed: prefer cc-option for CFLAGS
5+
additions
6+
7+
commit 994f5f7816ff963f49269cfc97f63cb2e4edb84f upstream.
8+
9+
as-option tests new options using KBUILD_CFLAGS, which causes problems
10+
when using as-option to update KBUILD_AFLAGS because many compiler
11+
options are not valid assembler options.
12+
13+
This will be fixed in a follow up patch. Before doing so, move the
14+
assembler test for -Wa,-mrelax-relocations=no from using as-option to
15+
cc-option.
16+
17+
Link: https://lore.kernel.org/llvm/CAK7LNATcHt7GcXZ=jMszyH=+M_LC9Qr6yeAGRCBbE6xriLxtUQ@mail.gmail.com/
18+
Suggested-by: Masahiro Yamada <[email protected]>
19+
Reviewed-by: Nathan Chancellor <[email protected]>
20+
Tested-by: Nathan Chancellor <[email protected]>
21+
Signed-off-by: Nick Desaulniers <[email protected]>
22+
Signed-off-by: Nathan Chancellor <[email protected]>
23+
Tested-by: Linux Kernel Functional Testing <[email protected]>
24+
Tested-by: Anders Roxell <[email protected]>
25+
Signed-off-by: Masahiro Yamada <[email protected]>
26+
Signed-off-by: Nathan Chancellor <[email protected]>
27+
---
28+
arch/x86/boot/compressed/Makefile | 2 +-
29+
1 file changed, 1 insertion(+), 1 deletion(-)
30+
31+
diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
32+
index edfb1a718510..62ef24bb2313 100644
33+
--- a/arch/x86/boot/compressed/Makefile
34+
+++ b/arch/x86/boot/compressed/Makefile
35+
@@ -39,7 +39,7 @@ KBUILD_CFLAGS += $(call cc-disable-warning, address-of-packed-member)
36+
KBUILD_CFLAGS += $(call cc-disable-warning, gnu)
37+
KBUILD_CFLAGS += -Wno-pointer-sign
38+
# Disable relocation relaxation in case the link is not PIE.
39+
-KBUILD_CFLAGS += $(call as-option,-Wa$(comma)-mrelax-relocations=no)
40+
+KBUILD_CFLAGS += $(call cc-option,-Wa$(comma)-mrelax-relocations=no)
41+
42+
KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
43+
GCOV_PROFILE := n
44+
45+
base-commit: 44613a259decccddd2bd4520f73cc4d5107546c6
46+
--
47+
2.50.0
48+
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
From bd32b4960e2bbcbb84df8fde0eb1a2efc84bf40b Mon Sep 17 00:00:00 2001
2+
From: Nathan Chancellor <[email protected]>
3+
Date: Wed, 14 Jun 2023 11:04:36 -0700
4+
Subject: [PATCH 2/9] MIPS: Move '-Wa,-msoft-float' check from as-option to
5+
cc-option
6+
7+
This patch is for linux-6.1.y and earlier, it has no direct mainline
8+
equivalent.
9+
10+
In order to backport commit d5c8d6e0fa61 ("kbuild: Update assembler
11+
calls to use proper flags and language target") to resolve a separate
12+
issue regarding PowerPC, the problem noticed and fixed by
13+
commit 80a20d2f8288 ("MIPS: Always use -Wa,-msoft-float and eliminate
14+
GAS_HAS_SET_HARDFLOAT") needs to be addressed. Unfortunately, 6.1 and
15+
earlier do not contain commit e4412739472b ("Documentation: raise
16+
minimum supported version of binutils to 2.25"), so it cannot be assumed
17+
that all supported versions of GNU as have support for -msoft-float.
18+
19+
In order to switch from KBUILD_CFLAGS to KBUILD_AFLAGS in as-option
20+
without consequence, move the '-Wa,-msoft-float' check to cc-option,
21+
including '$(cflags-y)' directly to avoid the issue mentioned in
22+
commit 80a20d2f8288 ("MIPS: Always use -Wa,-msoft-float and eliminate
23+
GAS_HAS_SET_HARDFLOAT").
24+
25+
Signed-off-by: Nathan Chancellor <[email protected]>
26+
---
27+
arch/mips/Makefile | 2 +-
28+
1 file changed, 1 insertion(+), 1 deletion(-)
29+
30+
diff --git a/arch/mips/Makefile b/arch/mips/Makefile
31+
index e2a2e5df4fde..4542258027a7 100644
32+
--- a/arch/mips/Makefile
33+
+++ b/arch/mips/Makefile
34+
@@ -107,7 +107,7 @@ endif
35+
# (specifically newer than 2.24.51.20140728) we then also need to explicitly
36+
# set ".set hardfloat" in all files which manipulate floating point registers.
37+
#
38+
-ifneq ($(call as-option,-Wa$(comma)-msoft-float,),)
39+
+ifneq ($(call cc-option,$(cflags-y) -Wa$(comma)-msoft-float,),)
40+
cflags-y += -DGAS_HAS_SET_HARDFLOAT -Wa,-msoft-float
41+
endif
42+
43+
--
44+
2.50.0
45+
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
From 53842cd1ecb80f2347244af2a4fdfd2956e010b6 Mon Sep 17 00:00:00 2001
2+
From: Nick Desaulniers <[email protected]>
3+
Date: Wed, 11 Jan 2023 20:05:01 -0700
4+
Subject: [PATCH 3/9] kbuild: Update assembler calls to use proper flags and
5+
language target
6+
7+
commit d5c8d6e0fa61401a729e9eb6a9c7077b2d3aebb0 upstream.
8+
9+
as-instr uses KBUILD_AFLAGS, but as-option uses KBUILD_CFLAGS. This can
10+
cause as-option to fail unexpectedly when CONFIG_WERROR is set, because
11+
clang will emit -Werror,-Wunused-command-line-argument for various -m
12+
and -f flags in KBUILD_CFLAGS for assembler sources.
13+
14+
Callers of as-option and as-instr should be adding flags to
15+
KBUILD_AFLAGS / aflags-y, not KBUILD_CFLAGS / cflags-y. Use
16+
KBUILD_AFLAGS in all macros to clear up the initial problem.
17+
18+
Unfortunately, -Wunused-command-line-argument can still be triggered
19+
with clang by the presence of warning flags or macro definitions because
20+
'-x assembler' is used, instead of '-x assembler-with-cpp', which will
21+
consume these flags. Switch to '-x assembler-with-cpp' in places where
22+
'-x assembler' is used, as the compiler is always used as the driver for
23+
out of line assembler sources in the kernel.
24+
25+
Finally, add -Werror to these macros so that they behave consistently
26+
whether or not CONFIG_WERROR is set.
27+
28+
[nathan: Reworded and expanded on problems in commit message
29+
Use '-x assembler-with-cpp' in a couple more places]
30+
31+
Link: https://github.com/ClangBuiltLinux/linux/issues/1699
32+
Suggested-by: Masahiro Yamada <[email protected]>
33+
Signed-off-by: Nick Desaulniers <[email protected]>
34+
Signed-off-by: Nathan Chancellor <[email protected]>
35+
Tested-by: Linux Kernel Functional Testing <[email protected]>
36+
Tested-by: Anders Roxell <[email protected]>
37+
Signed-off-by: Masahiro Yamada <[email protected]>
38+
Signed-off-by: Nathan Chancellor <[email protected]>
39+
---
40+
scripts/Kbuild.include | 8 ++++----
41+
1 file changed, 4 insertions(+), 4 deletions(-)
42+
43+
diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include
44+
index 5d247d8f1e04..e6bbe1fd7add 100644
45+
--- a/scripts/Kbuild.include
46+
+++ b/scripts/Kbuild.include
47+
@@ -99,16 +99,16 @@ try-run = $(shell set -e; \
48+
fi)
49+
50+
# as-option
51+
-# Usage: cflags-y += $(call as-option,-Wa$(comma)-isa=foo,)
52+
+# Usage: aflags-y += $(call as-option,-Wa$(comma)-isa=foo,)
53+
54+
as-option = $(call try-run,\
55+
- $(CC) $(KBUILD_CFLAGS) $(1) -c -x assembler /dev/null -o "$$TMP",$(1),$(2))
56+
+ $(CC) -Werror $(KBUILD_AFLAGS) $(1) -c -x assembler-with-cpp /dev/null -o "$$TMP",$(1),$(2))
57+
58+
# as-instr
59+
-# Usage: cflags-y += $(call as-instr,instr,option1,option2)
60+
+# Usage: aflags-y += $(call as-instr,instr,option1,option2)
61+
62+
as-instr = $(call try-run,\
63+
- printf "%b\n" "$(1)" | $(CC) $(KBUILD_AFLAGS) -c -x assembler -o "$$TMP" -,$(2),$(3))
64+
+ printf "%b\n" "$(1)" | $(CC) -Werror $(KBUILD_AFLAGS) -c -x assembler-with-cpp -o "$$TMP" -,$(2),$(3))
65+
66+
# __cc-option
67+
# Usage: MY_CFLAGS += $(call __cc-option,$(CC),$(MY_CFLAGS),-march=winchip-c6,-march=i586)
68+
--
69+
2.50.0
70+
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
From 817da77779e9bca5e52da4c1a93dff706732ff91 Mon Sep 17 00:00:00 2001
2+
From: Nathan Chancellor <[email protected]>
3+
Date: Wed, 11 Jan 2023 20:05:09 -0700
4+
Subject: [PATCH 4/9] drm/amd/display: Do not add '-mhard-float' to dml_ccflags
5+
for clang
6+
7+
commit 7db038d9790eda558dd6c1dde4cdd58b64789c47 upstream.
8+
9+
When clang's -Qunused-arguments is dropped from KBUILD_CPPFLAGS, it
10+
warns:
11+
12+
clang-16: error: argument unused during compilation: '-mhard-float' [-Werror,-Wunused-command-line-argument]
13+
14+
Similar to commit 84edc2eff827 ("selftest/fpu: avoid clang warning"),
15+
just add this flag to GCC builds. Commit 0f0727d971f6 ("drm/amd/display:
16+
readd -msse2 to prevent Clang from emitting libcalls to undefined SW FP
17+
routines") added '-msse2' to prevent clang from emitting software
18+
floating point routines.
19+
20+
Signed-off-by: Nathan Chancellor <[email protected]>
21+
Acked-by: Alex Deucher <[email protected]>
22+
Tested-by: Linux Kernel Functional Testing <[email protected]>
23+
Tested-by: Anders Roxell <[email protected]>
24+
Signed-off-by: Masahiro Yamada <[email protected]>
25+
Signed-off-by: Nathan Chancellor <[email protected]>
26+
---
27+
drivers/gpu/drm/amd/display/dc/dml/Makefile | 3 ++-
28+
1 file changed, 2 insertions(+), 1 deletion(-)
29+
30+
diff --git a/drivers/gpu/drm/amd/display/dc/dml/Makefile b/drivers/gpu/drm/amd/display/dc/dml/Makefile
31+
index 8df251626e22..26cb8f78f516 100644
32+
--- a/drivers/gpu/drm/amd/display/dc/dml/Makefile
33+
+++ b/drivers/gpu/drm/amd/display/dc/dml/Makefile
34+
@@ -24,7 +24,8 @@
35+
# It provides the general basic services required by other DAL
36+
# subcomponents.
37+
38+
-dml_ccflags := -mhard-float -msse
39+
+dml_ccflags-$(CONFIG_CC_IS_GCC) := -mhard-float
40+
+dml_ccflags := $(dml_ccflags-y) -msse
41+
42+
ifdef CONFIG_CC_IS_GCC
43+
ifeq ($(call cc-ifversion, -lt, 0701, y), y)
44+
--
45+
2.50.0
46+
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
From ee72d68bba47e0a0f045ff33638601ef7ec14260 Mon Sep 17 00:00:00 2001
2+
From: Nathan Chancellor <[email protected]>
3+
Date: Thu, 1 Jun 2023 11:38:24 -0700
4+
Subject: [PATCH 5/9] mips: Include KBUILD_CPPFLAGS in CHECKFLAGS invocation
5+
6+
commit 08f6554ff90ef189e6b8f0303e57005bddfdd6a7 upstream.
7+
8+
A future change will move CLANG_FLAGS from KBUILD_{A,C}FLAGS to
9+
KBUILD_CPPFLAGS so that '--target' is available while preprocessing.
10+
When that occurs, the following error appears when building ARCH=mips
11+
with clang (tip of tree error shown):
12+
13+
clang: error: unsupported option '-mabi=' for target 'x86_64-pc-linux-gnu'
14+
15+
Add KBUILD_CPPFLAGS in the CHECKFLAGS invocation to keep everything
16+
working after the move.
17+
18+
Signed-off-by: Nathan Chancellor <[email protected]>
19+
Signed-off-by: Masahiro Yamada <[email protected]>
20+
Signed-off-by: Nathan Chancellor <[email protected]>
21+
---
22+
arch/mips/Makefile | 2 +-
23+
1 file changed, 1 insertion(+), 1 deletion(-)
24+
25+
diff --git a/arch/mips/Makefile b/arch/mips/Makefile
26+
index 4542258027a7..cc6f8265f28c 100644
27+
--- a/arch/mips/Makefile
28+
+++ b/arch/mips/Makefile
29+
@@ -319,7 +319,7 @@ KBUILD_CFLAGS += -fno-asynchronous-unwind-tables
30+
KBUILD_LDFLAGS += -m $(ld-emul)
31+
32+
ifdef CONFIG_MIPS
33+
-CHECKFLAGS += $(shell $(CC) $(KBUILD_CFLAGS) -dM -E -x c /dev/null | \
34+
+CHECKFLAGS += $(shell $(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) -dM -E -x c /dev/null | \
35+
egrep -vw '__GNUC_(MINOR_|PATCHLEVEL_)?_' | \
36+
sed -e "s/^\#define /-D'/" -e "s/ /'='/" -e "s/$$/'/" -e 's/\$$/&&/g')
37+
endif
38+
--
39+
2.50.0
40+
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
From b7e68767a827168474d68a6f5ab998eac82f8c90 Mon Sep 17 00:00:00 2001
2+
From: Nathan Chancellor <[email protected]>
3+
Date: Thu, 1 Jun 2023 12:50:39 -0700
4+
Subject: [PATCH 6/9] kbuild: Add CLANG_FLAGS to as-instr
5+
6+
commit cff6e7f50bd315e5b39c4e46c704ac587ceb965f upstream.
7+
8+
A future change will move CLANG_FLAGS from KBUILD_{A,C}FLAGS to
9+
KBUILD_CPPFLAGS so that '--target' is available while preprocessing.
10+
When that occurs, the following errors appear multiple times when
11+
building ARCH=powerpc powernv_defconfig:
12+
13+
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'
14+
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'
15+
16+
Diffing the .o.cmd files reveals that -DHAVE_AS_ATHIGH=1 is not present
17+
anymore, because as-instr only uses KBUILD_AFLAGS, which will no longer
18+
contain '--target'.
19+
20+
Mirror Kconfig's as-instr and add CLANG_FLAGS explicitly to the
21+
invocation to ensure the target information is always present.
22+
23+
Signed-off-by: Nathan Chancellor <[email protected]>
24+
Signed-off-by: Masahiro Yamada <[email protected]>
25+
Signed-off-by: Nathan Chancellor <[email protected]>
26+
---
27+
scripts/Kbuild.include | 2 +-
28+
1 file changed, 1 insertion(+), 1 deletion(-)
29+
30+
diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include
31+
index e6bbe1fd7add..1aa02e7125e7 100644
32+
--- a/scripts/Kbuild.include
33+
+++ b/scripts/Kbuild.include
34+
@@ -108,7 +108,7 @@ as-option = $(call try-run,\
35+
# Usage: aflags-y += $(call as-instr,instr,option1,option2)
36+
37+
as-instr = $(call try-run,\
38+
- printf "%b\n" "$(1)" | $(CC) -Werror $(KBUILD_AFLAGS) -c -x assembler-with-cpp -o "$$TMP" -,$(2),$(3))
39+
+ printf "%b\n" "$(1)" | $(CC) -Werror $(CLANG_FLAGS) $(KBUILD_AFLAGS) -c -x assembler-with-cpp -o "$$TMP" -,$(2),$(3))
40+
41+
# __cc-option
42+
# Usage: MY_CFLAGS += $(call __cc-option,$(CC),$(MY_CFLAGS),-march=winchip-c6,-march=i586)
43+
--
44+
2.50.0
45+
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
From a846e1c74e2c17443e84efefb632f0d759d5f6e1 Mon Sep 17 00:00:00 2001
2+
From: Masahiro Yamada <[email protected]>
3+
Date: Sun, 9 Apr 2023 23:53:57 +0900
4+
Subject: [PATCH 7/9] kbuild: add $(CLANG_FLAGS) to KBUILD_CPPFLAGS
5+
6+
commit feb843a469fb0ab00d2d23cfb9bcc379791011bb upstream.
7+
8+
When preprocessing arch/*/kernel/vmlinux.lds.S, the target triple is
9+
not passed to $(CPP) because we add it only to KBUILD_{C,A}FLAGS.
10+
11+
As a result, the linker script is preprocessed with predefined macros
12+
for the build host instead of the target.
13+
14+
Assuming you use an x86 build machine, compare the following:
15+
16+
$ clang -dM -E -x c /dev/null
17+
$ clang -dM -E -x c /dev/null -target aarch64-linux-gnu
18+
19+
There is no actual problem presumably because our linker scripts do not
20+
rely on such predefined macros, but it is better to define correct ones.
21+
22+
Move $(CLANG_FLAGS) to KBUILD_CPPFLAGS, so that all *.c, *.S, *.lds.S
23+
will be processed with the proper target triple.
24+
25+
[Note]
26+
After the patch submission, we got an actual problem that needs this
27+
commit. (CBL issue 1859)
28+
29+
Link: https://github.com/ClangBuiltLinux/linux/issues/1859
30+
Reported-by: Tom Rini <[email protected]>
31+
Signed-off-by: Masahiro Yamada <[email protected]>
32+
Reviewed-by: Nathan Chancellor <[email protected]>
33+
Tested-by: Nathan Chancellor <[email protected]>
34+
Signed-off-by: Nathan Chancellor <[email protected]>
35+
---
36+
Makefile | 3 +--
37+
1 file changed, 1 insertion(+), 2 deletions(-)
38+
39+
diff --git a/Makefile b/Makefile
40+
index cc8e29781c25..624dc619104a 100644
41+
--- a/Makefile
42+
+++ b/Makefile
43+
@@ -568,8 +568,7 @@ ifneq ($(LLVM_IAS),1)
44+
CLANG_FLAGS += -no-integrated-as
45+
endif
46+
CLANG_FLAGS += -Werror=unknown-warning-option
47+
-KBUILD_CFLAGS += $(CLANG_FLAGS)
48+
-KBUILD_AFLAGS += $(CLANG_FLAGS)
49+
+KBUILD_CPPFLAGS += $(CLANG_FLAGS)
50+
export CLANG_FLAGS
51+
endif
52+
53+
--
54+
2.50.0
55+

0 commit comments

Comments
 (0)