[PATCH] x86/kbuild/64: Test for the availability of the -mtune=native compiler flag

From: Ingo Molnar
Date: Mon Mar 24 2025 - 03:10:37 EST



* Stephen Rothwell <sfr@xxxxxxxxxxxxxxxx> wrote:

> Hi,
>
> On Sun, 23 Mar 2025 23:29:20 -0700 "H. Peter Anvin" <hpa@xxxxxxxxx> wrote:
> >
> > >$ x86_64-linux-gnu-gcc --version
> > >x86_64-linux-gnu-gcc (Debian 14.2.0-12) 14.2.0
> > >
> > >cross build - ppc hosted
> > >
> >
> > Cross compiling?
>
> Yes (see above :-))

Does the patch below fix the bug?

Thanks,

Ingo

=====================>
From: Ingo Molnar <mingo@xxxxxxxxxx>
Date: Mon, 24 Mar 2025 08:05:19 +0100
Subject: [PATCH] x86/kbuild/64: Test for the availability of the -mtune=native compiler flag

Stephen reported this build failure when cross-compiling:

cc1: error: bad value 'native' for '-march=' switch

Test for the availability of the -march=native flag.

Reported-by: Stephen Rothwell <sfr@xxxxxxxxxxxxxxxx>
Signed-off-by: Ingo Molnar <mingo@xxxxxxxxxx>
Cc: Tor Vic <torvic9@xxxxxxxxxxx>
Cc: Andy Lutomirski <luto@xxxxxxxxxx>
Cc: Brian Gerst <brgerst@xxxxxxxxx>
Cc: Juergen Gross <jgross@xxxxxxxx>
Cc: H. Peter Anvin <hpa@xxxxxxxxx>
Cc: Kees Cook <keescook@xxxxxxxxxxxx>
Cc: Josh Poimboeuf <jpoimboe@xxxxxxxxxx>
Cc: Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx>
Link: https://lore.kernel.org/r/20250324172723.49fb0416@xxxxxxxxxxxxxxxx
---
arch/x86/Kconfig.cpu | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
index 9d108a54c30a..87bede96e800 100644
--- a/arch/x86/Kconfig.cpu
+++ b/arch/x86/Kconfig.cpu
@@ -245,10 +245,14 @@ config MATOM

endchoice

+config CC_HAS_MARCH_NATIVE
+ # This flag might not be available in cross-compilers:
+ def_bool $(cc-option, -march=native)
+
config X86_NATIVE_CPU
bool "Build and optimize for local/native CPU"
depends on X86_64
- default n
+ depends on CC_HAS_MARCH_NATIVE
help
Optimize for the current CPU used to compile the kernel.
Use this option if you intend to build the kernel for your