Commit 914873bc authored by Linus Torvalds's avatar Linus Torvalds
Browse files

Merge tag 'x86-build-2025-05-25' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip

Pull x86 build updates from Ingo Molnar:
 "Add the CONFIG_X86_NATIVE_CPU=y build option to locally optimize the
  kernel build with '-march=native'"

* tag 'x86-build-2025-05-25' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
  x86/kbuild/64: Restrict clang versions that can use '-march=native'
  x86/kbuild/64: Test for the availability of the -mtune=native compiler flag
  x86/kbuild/64: Add the CONFIG_X86_NATIVE_CPU option to locally optimize the kernel with '-march=native'
parents 24244df0 ad9b8618
Loading
Loading
Loading
Loading
+24 −0
Original line number Diff line number Diff line
@@ -245,6 +245,30 @@ config MATOM

endchoice

config CC_HAS_MARCH_NATIVE
	# This flag might not be available in cross-compilers:
	def_bool $(cc-option, -march=native)
	# LLVM 18 has an easily triggered internal compiler error in core
	# networking code with '-march=native' on certain systems:
	# https://github.com/llvm/llvm-project/issues/72026
	# LLVM 19 introduces an optimization that resolves some high stack
	# usage warnings that only appear wth '-march=native'.
	depends on CC_IS_GCC || CLANG_VERSION >= 190100

config X86_NATIVE_CPU
	bool "Build and optimize for local/native CPU"
	depends on X86_64
	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
	  local machine.

	  Note that such a kernel might not work optimally on a
	  different x86 machine.

	  If unsure, say N.

config X86_GENERIC
	bool "Generic x86 support"
	depends on X86_32
+5 −0
Original line number Diff line number Diff line
@@ -173,8 +173,13 @@ else
	# Use -mskip-rax-setup if supported.
	KBUILD_CFLAGS += $(call cc-option,-mskip-rax-setup)

ifdef CONFIG_X86_NATIVE_CPU
        KBUILD_CFLAGS += -march=native
        KBUILD_RUSTFLAGS += -Ctarget-cpu=native
else
        KBUILD_CFLAGS += -march=x86-64 -mtune=generic
        KBUILD_RUSTFLAGS += -Ctarget-cpu=x86-64 -Ztune-cpu=generic
endif

        KBUILD_CFLAGS += -mno-red-zone
        KBUILD_CFLAGS += -mcmodel=kernel