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

From: Ingo Molnar <[email-masked]>
Date: Mon, 24 Mar 2025 08:10:00 +0100

* Stephen Rothwell <[email-masked]> wrote:

> Hi,
> 
> On Sun, 23 Mar 2025 23:29:20 -0700 "H. Peter Anvin" <[email-masked]> 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 <[email-masked]>
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 <[email-masked]>
Signed-off-by: Ingo Molnar <[email-masked]>
Cc: Tor Vic <[email-masked]>
Cc: Andy Lutomirski <[email-masked]>
Cc: Brian Gerst <[email-masked]>
Cc: Juergen Gross <[email-masked]>
Cc: H. Peter Anvin <[email-masked]>
Cc: Kees Cook <[email-masked]>
Cc: Josh Poimboeuf <[email-masked]>
Cc: Linus Torvalds <[email-masked]>
Link: https://lore.kernel.org/r/[email-masked]
---
 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