Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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'

+29
+24
arch/x86/Kconfig.cpu
··· 245 245 246 246 endchoice 247 247 248 + config CC_HAS_MARCH_NATIVE 249 + # This flag might not be available in cross-compilers: 250 + def_bool $(cc-option, -march=native) 251 + # LLVM 18 has an easily triggered internal compiler error in core 252 + # networking code with '-march=native' on certain systems: 253 + # https://github.com/llvm/llvm-project/issues/72026 254 + # LLVM 19 introduces an optimization that resolves some high stack 255 + # usage warnings that only appear wth '-march=native'. 256 + depends on CC_IS_GCC || CLANG_VERSION >= 190100 257 + 258 + config X86_NATIVE_CPU 259 + bool "Build and optimize for local/native CPU" 260 + depends on X86_64 261 + depends on CC_HAS_MARCH_NATIVE 262 + help 263 + Optimize for the current CPU used to compile the kernel. 264 + Use this option if you intend to build the kernel for your 265 + local machine. 266 + 267 + Note that such a kernel might not work optimally on a 268 + different x86 machine. 269 + 270 + If unsure, say N. 271 + 248 272 config X86_GENERIC 249 273 bool "Generic x86 support" 250 274 depends on X86_32
+5
arch/x86/Makefile
··· 173 173 # Use -mskip-rax-setup if supported. 174 174 KBUILD_CFLAGS += $(call cc-option,-mskip-rax-setup) 175 175 176 + ifdef CONFIG_X86_NATIVE_CPU 177 + KBUILD_CFLAGS += -march=native 178 + KBUILD_RUSTFLAGS += -Ctarget-cpu=native 179 + else 176 180 KBUILD_CFLAGS += -march=x86-64 -mtune=generic 177 181 KBUILD_RUSTFLAGS += -Ctarget-cpu=x86-64 -Ztune-cpu=generic 182 + endif 178 183 179 184 KBUILD_CFLAGS += -mno-red-zone 180 185 KBUILD_CFLAGS += -mcmodel=kernel