* [PATCH v3 0/2] x86: Avoid CONFIG_X86_NATIVE_CPU=y when cross compiling
@ 2026-11-25 6:43 Nathan Chancellor
2026-11-25 6:43 ` [PATCH v3 1/2] kbuild: Introduce CONFIG_CROSS_COMPILING Nathan Chancellor
2026-11-25 6:43 ` [PATCH v3 2/2] x86/build: Do not allow X86_NATIVE_CPU to be enabled when cross compiling Nathan Chancellor
0 siblings, 2 replies; 4+ messages in thread
From: Nathan Chancellor @ 2026-11-25 6:43 UTC (permalink / raw)
To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen,
Nathan Chancellor, Nicolas Schier
Cc: x86, H. Peter Anvin, Nick Desaulniers, Bill Wendling,
Justin Stitt, Julian Braha, linux-kernel, llvm, linux-kbuild,
stable, Linus Torvalds
This series addresses an massive spew of warnings that I see when cross
compiling x86 allmodconfig on certain ARM machines. To resolve these
warnings, introduce a Kconfig symbol for when cross compiling and avoid
allowing CONFIG_X86_NATIVE_CPU to be enabled when it is set.
This could go through either the kbuild or -tip tree, I don't have a
strong preference.
---
Changes in v3:
- Introduce CONFIG_CROSS_COMPILING to perform the host == target check
from v1 in a generic way and make CONFIG_X86_NATIVE_CPU depend on it
not being set (Linus)
- Add bug link to second patch (Nick)
- Link to v2: https://patch.msgid.link/20261115-x86-no-march-native-on-non-x86_64-v2-1-fb3f9634b1bc@kernel.org
Changes in v2:
- Rather than checking if host == target, just make X86_NATIVE_CPU
depend on !COMPILE_TEST, which makes sense anyways (Borislav)
- Link to v1: https://patch.msgid.link/20261113-x86-no-march-native-on-non-x86_64-v1-1-cbc8b096d1c4@kernel.org
---
Nathan Chancellor (2):
kbuild: Introduce CONFIG_CROSS_COMPILING
x86/build: Do not allow X86_NATIVE_CPU to be enabled when cross compiling
MAINTAINERS | 1 +
arch/x86/Kconfig.cpu | 1 +
scripts/Kconfig.toolchain | 3 +++
scripts/check-cross-compiling.sh | 26 ++++++++++++++++++++++++++
4 files changed, 31 insertions(+)
---
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
base-tree: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
change-id: 20261113-x86-no-march-native-on-non-x86_64-88233b48a7d7
Best regards,
--
Cheers,
Nathan
^ permalink raw reply [flat|nested] 4+ messages in thread* [PATCH v3 1/2] kbuild: Introduce CONFIG_CROSS_COMPILING
2026-11-25 6:43 [PATCH v3 0/2] x86: Avoid CONFIG_X86_NATIVE_CPU=y when cross compiling Nathan Chancellor
@ 2026-11-25 6:43 ` Nathan Chancellor
2026-11-25 10:27 ` Thomas Weißschuh
2026-11-25 6:43 ` [PATCH v3 2/2] x86/build: Do not allow X86_NATIVE_CPU to be enabled when cross compiling Nathan Chancellor
1 sibling, 1 reply; 4+ messages in thread
From: Nathan Chancellor @ 2026-11-25 6:43 UTC (permalink / raw)
To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen,
Nathan Chancellor, Nicolas Schier
Cc: x86, H. Peter Anvin, Nick Desaulniers, Bill Wendling,
Justin Stitt, Julian Braha, linux-kernel, llvm, linux-kbuild,
stable, Linus Torvalds
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
$ make ... run-command KBUILD_RUN_COMMAND='$(srctree)/scripts/check-cross-compiling.sh "$(HOSTCC)" "$(CC) $(CLANG_FLAGS)"'
Cc: stable@vger.kernel.org # dependency of future change
Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Link: https://lore.kernel.org/CAHk-=wgmkoWHWwaQ6nsGoCiBp0hrpJuiwmoVbQ=Efun8JyUNKw@mail.gmail.com/
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
---
MAINTAINERS | 1 +
scripts/Kconfig.toolchain | 3 +++
scripts/check-cross-compiling.sh | 26 ++++++++++++++++++++++++++
3 files changed, 30 insertions(+)
diff --git a/MAINTAINERS b/MAINTAINERS
index 93abbb315065..fb76f9e82f65 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -14454,6 +14454,7 @@ F: scripts/Kbuild*
F: scripts/Makefile*
F: scripts/bash-completion/
F: scripts/basic/
+F: scripts/check-cross-compiling.sh
F: scripts/clang-tools/
F: scripts/container
F: scripts/dummy-tools/
diff --git a/scripts/Kconfig.toolchain b/scripts/Kconfig.toolchain
index 2acbd40a38f1..ac2e3de50ac0 100644
--- a/scripts/Kconfig.toolchain
+++ b/scripts/Kconfig.toolchain
@@ -32,6 +32,9 @@ config CLANG_VERSION
default $(cc-version) if CC_IS_CLANG
default 0
+config CROSS_COMPILING
+ def_bool $(success,$(srctree)/scripts/check-cross-compiling.sh "$(HOSTCC)" "$(CC) $(CLANG_FLAGS)")
+
config AS_IS_GNU
def_bool $(success,test "$(as-name)" = GNU)
diff --git a/scripts/check-cross-compiling.sh b/scripts/check-cross-compiling.sh
new file mode 100755
index 000000000000..4c1e6a061b3b
--- /dev/null
+++ b/scripts/check-cross-compiling.sh
@@ -0,0 +1,26 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+
+HOSTCC="$1"
+CC="$2"
+
+get_target() {
+ "$@" -v 2>&1 | grep -o 'Target: \([^-]\+\)'
+}
+
+if ! hostcc_target=$(get_target $HOSTCC); then
+ echo >&2 "$0: Could not get target for HOSTCC!"
+ exit 1
+fi
+
+if ! cc_target=$(get_target $CC); then
+ echo >&2 "$0: Could not get target for CC!"
+ exit 1
+fi
+
+echo "HOSTCC: '$hostcc_target'"
+echo "CC: '$cc_target'"
+
+if [ "$hostcc_target" = "$cc_target" ]; then
+ exit 1
+fi
--
2.56.1
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH v3 1/2] kbuild: Introduce CONFIG_CROSS_COMPILING
2026-11-25 6:43 ` [PATCH v3 1/2] kbuild: Introduce CONFIG_CROSS_COMPILING Nathan Chancellor
@ 2026-11-25 10:27 ` Thomas Weißschuh
0 siblings, 0 replies; 4+ messages in thread
From: Thomas Weißschuh @ 2026-11-25 10:27 UTC (permalink / raw)
To: Nathan Chancellor
Cc: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen,
Nicolas Schier, x86, H. Peter Anvin, Nick Desaulniers,
Bill Wendling, Justin Stitt, Julian Braha, linux-kernel, llvm,
linux-kbuild, stable, Linus Torvalds
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@vger.kernel.org # dependency of future change
> Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
> Link: https://lore.kernel.org/CAHk-=wgmkoWHWwaQ6nsGoCiBp0hrpJuiwmoVbQ=Efun8JyUNKw@mail.gmail.com/
> Signed-off-by: Nathan Chancellor <nathan@kernel.org>
> ---
> MAINTAINERS | 1 +
> scripts/Kconfig.toolchain | 3 +++
> scripts/check-cross-compiling.sh | 26 ++++++++++++++++++++++++++
> 3 files changed, 30 insertions(+)
(...)
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v3 2/2] x86/build: Do not allow X86_NATIVE_CPU to be enabled when cross compiling
2026-11-25 6:43 [PATCH v3 0/2] x86: Avoid CONFIG_X86_NATIVE_CPU=y when cross compiling Nathan Chancellor
2026-11-25 6:43 ` [PATCH v3 1/2] kbuild: Introduce CONFIG_CROSS_COMPILING Nathan Chancellor
@ 2026-11-25 6:43 ` Nathan Chancellor
1 sibling, 0 replies; 4+ messages in thread
From: Nathan Chancellor @ 2026-11-25 6:43 UTC (permalink / raw)
To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen,
Nathan Chancellor, Nicolas Schier
Cc: x86, H. Peter Anvin, Nick Desaulniers, Bill Wendling,
Justin Stitt, Julian Braha, linux-kernel, llvm, linux-kbuild,
stable
When cross compiling x86_64 from an aarch64 machine using clang with
CONFIG_X86_NATIVE_CPU enabled (such as when using allmodconfig), there
may be a slew of warnings from each .c file, which makes it nearly
impossible to find real issues.
'+crc' is not a recognized feature for this target (ignoring feature)
'+fp-armv8' is not a recognized feature for this target (ignoring feature)
'+lse' is not a recognized feature for this target (ignoring feature)
'+neon' is not a recognized feature for this target (ignoring feature)
'+sha2' is not a recognized feature for this target (ignoring feature)
'+sha3' is not a recognized feature for this target (ignoring feature)
'-rand' is not a recognized feature for this target (ignoring feature)
'-sme' is not a recognized feature for this target (ignoring feature)
'-sme2' is not a recognized feature for this target (ignoring feature)
'-sve' is not a recognized feature for this target (ignoring feature)
Internally, clang expands '-march=native' into a list of target features
to enable based on the detected CPU. The x86 part of the clang driver
notes
// FIXME: Reject attempts to use -march=native unless the target matches
// the host.
which was first added by the initial '-march=native' support in clang in
2009 [1] (other architecture drivers appear to have a similar problem).
Due to the lack of validation that the host CPU is an x86_64 CPU,
'-march=native' is expanded using the aarch64 host CPU's target
features, which are unrecognized by the x86 backend.
While this should obviously be fixed in the compiler [2], this does not
help currently released toolchains that have this issue. As a simple
workaround that makes sense regardless of the toolchain issue, only
allow CONFIG_X86_NATIVE_CPU to be enabled when CONFIG_CROSS_COMPILING is
not set (i.e., it is known that the host and target architectures are
the same).
Cc: stable@vger.kernel.org
Fixes: ea1dcca1de12 ("x86/kbuild/64: Add the CONFIG_X86_NATIVE_CPU option to locally optimize the kernel with '-march=native'")
Link: https://github.com/llvm/llvm-project/commit/e13ada6a3b236f505b24501d456dec2518e4944c [1]
Link: https://github.com/llvm/llvm-project/issues/243260
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
---
arch/x86/Kconfig.cpu | 1 +
1 file changed, 1 insertion(+)
diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
index 6e7a366f0798..4643b3482d94 100644
--- a/arch/x86/Kconfig.cpu
+++ b/arch/x86/Kconfig.cpu
@@ -217,6 +217,7 @@ config RUSTC_HAS_APXF
config X86_NATIVE_CPU
bool "Build and optimize for local/native CPU"
depends on X86_64
+ depends on !CROSS_COMPILING
depends on CC_HAS_MARCH_NATIVE
depends on !RUST || RUSTC_HAS_APXF
help
--
2.56.1
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-25 10:27 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-25 6:43 [PATCH v3 0/2] x86: Avoid CONFIG_X86_NATIVE_CPU=y when cross compiling Nathan Chancellor
2026-11-25 6:43 ` [PATCH v3 1/2] kbuild: Introduce CONFIG_CROSS_COMPILING Nathan Chancellor
2026-11-25 10:27 ` Thomas Weißschuh
2026-11-25 6:43 ` [PATCH v3 2/2] x86/build: Do not allow X86_NATIVE_CPU to be enabled when cross compiling Nathan Chancellor
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®