Re: [PATCH v3 1/2] kbuild: Introduce CONFIG_CROSS_COMPILING
From: Thomas Weißschuh
Date: Wed Nov 25 2026 - 05:27:17 EST
On 2026-11-24 23:43:12-0700, Nathan Chancellor wrote:
> There are times where decisions may want to be made within Kconfig when
> cross compiling. Introduce a small script to call '$(HOSTCC) -v' and
> '$(CC) -v' and compare the first part of the target triples to see if
> they match.
>
> This check is cheap but approximate, as Kconfig does not have all the
> information available such as endianness and bit width for the target to
> pass along to compiler. For example, a user building for x86 with a
> compiler that can build both with '-m32' / '-m64' may have
> CONFIG_CROSS_COMPILING set depending on the default value of the
> toolchain and what's being targeted. Should this become problematic in
> the future, the logic can be expanded to cover these corner cases but
> for now, keep the implementation simple and cover the majority of cases.
> Leave some informational prints to make it easy to debug future reports
> with
The expansion to bit width and endianess will be a lot of busy-work.
See the CC_CAN_LINK infrastructure.
We already have host-architecture detection in kbuild through
scripts/subarch.include. So CC_HAS_MARCH_NATIVE could depend on
$(ARCH) = $(SUBARCH), after exporting SUBARCH. Or maybe give the
variable a better name, like HOSTARCH.
This would avoid the introduction of a new, not-really-correct flag
and also the whack-a-mole that Boris complained about.
> $ make ... run-command KBUILD_RUN_COMMAND='$(srctree)/scripts/check-cross-compiling.sh "$(HOSTCC)" "$(CC) $(CLANG_FLAGS)"'
>
> Cc: stable@xxxxxxxxxxxxxxx # dependency of future change
> Suggested-by: Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx>
> Link: https://lore.kernel.org/CAHk-=wgmkoWHWwaQ6nsGoCiBp0hrpJuiwmoVbQ=Efun8JyUNKw@xxxxxxxxxxxxxx/
> Signed-off-by: Nathan Chancellor <nathan@xxxxxxxxxx>
> ---
> MAINTAINERS | 1 +
> scripts/Kconfig.toolchain | 3 +++
> scripts/check-cross-compiling.sh | 26 ++++++++++++++++++++++++++
> 3 files changed, 30 insertions(+)
(...)