]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
kbuild: add $(CLANG_FLAGS) to KBUILD_CPPFLAGS
authorMasahiro Yamada <masahiroy@kernel.org>
Sun, 9 Apr 2023 14:53:57 +0000 (23:53 +0900)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 27 Jun 2025 10:04:10 +0000 (11:04 +0100)
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)

Link: https://github.com/ClangBuiltLinux/linux/issues/1859
Reported-by: Tom Rini <trini@konsulko.com>
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-by: Nathan Chancellor <nathan@kernel.org>
Tested-by: Nathan Chancellor <nathan@kernel.org>
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Makefile

index 7d94034c906d19641651864979dd637bfdae7801..f8eafb0046869303a1138f1f75a6630fb475e69b 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -586,8 +586,7 @@ else
 CLANG_FLAGS    += -fno-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