kbuild: add $(CLANG_FLAGS) to KBUILD_CPPFLAGS
authorMasahiro Yamada <masahiroy@kernel.org>
Sun, 9 Apr 2023 14:53:57 +0000 (23:53 +0900)
committerMasahiro Yamada <masahiroy@kernel.org>
Mon, 5 Jun 2023 00:50:44 +0000 (09:50 +0900)
commitfeb843a469fb0ab00d2d23cfb9bcc379791011bb
tree2c90f8a084b88faca0df9a9ebfb67f872544af62
parentcff6e7f50bd315e5b39c4e46c704ac587ceb965f
kbuild: add $(CLANG_FLAGS) to KBUILD_CPPFLAGS

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>
scripts/Makefile.clang