mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] x86/boot/startup: Disable LTO
@ 2025-04-14 19:26 Nathan Chancellor
  2025-04-14 19:28 ` Ard Biesheuvel
  2025-04-17 10:19 ` [tip: x86/boot] x86/boot/startup: Disable LTO for the startup code tip-bot2 for Nathan Chancellor
  0 siblings, 2 replies; 3+ messages in thread
From: Nathan Chancellor @ 2025-04-14 19:26 UTC (permalink / raw)
  To: Ingo Molnar, Ard Biesheuvel, x86
  Cc: linux-kernel, llvm, Linux Kernel Functional Testing, Nathan Chancellor

When building with CONFIG_LTO_CLANG, there is an error in the x86 boot
startup code because it builds with a different code model than the rest
of the kernel:

  ld.lld: error: Function Import: link error: linking module flags 'Code Model': IDs have conflicting values: 'i32 2' from vmlinux.a(head64.o at 1302448), and 'i32 1' from vmlinux.a(map_kernel.o at 1314208)
  ld.lld: error: Function Import: link error: linking module flags 'Code Model': IDs have conflicting values: 'i32 2' from vmlinux.a(common.o at 1306108), and 'i32 1' from vmlinux.a(gdt_idt.o at 1314148)

As this directory is for code that only runs during early system
initialization, LTO is not very important, so filter out the LTO flags
from KBUILD_CFLAGS for arch/x86/boot/startup to resolve the build error.

Fixes: 4cecebf200ef ("x86/boot: Move the early GDT/IDT setup code into startup/")
Reported-by: Linux Kernel Functional Testing <lkft@linaro.org>
Closes: https://lore.kernel.org/CA+G9fYvnun+bhYgtt425LWxzOmj+8Jf3ruKeYxQSx-F6U7aisg@mail.gmail.com/
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
---
 arch/x86/boot/startup/Makefile | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/x86/boot/startup/Makefile b/arch/x86/boot/startup/Makefile
index ccdfc42a4d59..bb7c826e586c 100644
--- a/arch/x86/boot/startup/Makefile
+++ b/arch/x86/boot/startup/Makefile
@@ -7,8 +7,9 @@ KBUILD_CFLAGS		+= -D__DISABLE_EXPORTS -mcmodel=small -fPIC \
 			   -fno-stack-protector -D__NO_FORTIFY \
 			   -include $(srctree)/include/linux/hidden.h
 
-# disable ftrace hooks
+# disable ftrace hooks and LTO
 KBUILD_CFLAGS	:= $(subst $(CC_FLAGS_FTRACE),,$(KBUILD_CFLAGS))
+KBUILD_CFLAGS	:= $(filter-out $(CC_FLAGS_LTO),$(KBUILD_CFLAGS))
 KASAN_SANITIZE	:= n
 KCSAN_SANITIZE	:= n
 KMSAN_SANITIZE	:= n

---
base-commit: 9287216a0c8f7bf7b485e18ad71584b434b59bb6
change-id: 20250414-x86-boot-startup-lto-error-26e0825706a3

Best regards,
-- 
Nathan Chancellor <nathan@kernel.org>


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] x86/boot/startup: Disable LTO
  2025-04-14 19:26 [PATCH] x86/boot/startup: Disable LTO Nathan Chancellor
@ 2025-04-14 19:28 ` Ard Biesheuvel
  2025-04-17 10:19 ` [tip: x86/boot] x86/boot/startup: Disable LTO for the startup code tip-bot2 for Nathan Chancellor
  1 sibling, 0 replies; 3+ messages in thread
From: Ard Biesheuvel @ 2025-04-14 19:28 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: Ingo Molnar, x86, linux-kernel, llvm, Linux Kernel Functional Testing

On Mon, 14 Apr 2025 at 21:26, Nathan Chancellor <nathan@kernel.org> wrote:
>
> When building with CONFIG_LTO_CLANG, there is an error in the x86 boot
> startup code because it builds with a different code model than the rest
> of the kernel:
>
>   ld.lld: error: Function Import: link error: linking module flags 'Code Model': IDs have conflicting values: 'i32 2' from vmlinux.a(head64.o at 1302448), and 'i32 1' from vmlinux.a(map_kernel.o at 1314208)
>   ld.lld: error: Function Import: link error: linking module flags 'Code Model': IDs have conflicting values: 'i32 2' from vmlinux.a(common.o at 1306108), and 'i32 1' from vmlinux.a(gdt_idt.o at 1314148)
>
> As this directory is for code that only runs during early system
> initialization, LTO is not very important, so filter out the LTO flags
> from KBUILD_CFLAGS for arch/x86/boot/startup to resolve the build error.
>
> Fixes: 4cecebf200ef ("x86/boot: Move the early GDT/IDT setup code into startup/")
> Reported-by: Linux Kernel Functional Testing <lkft@linaro.org>
> Closes: https://lore.kernel.org/CA+G9fYvnun+bhYgtt425LWxzOmj+8Jf3ruKeYxQSx-F6U7aisg@mail.gmail.com/
> Signed-off-by: Nathan Chancellor <nathan@kernel.org>
> ---
>  arch/x86/boot/startup/Makefile | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>

Thanks for the fix

Acked-by: Ard Biesheuvel <ardb@kernel.org>


> diff --git a/arch/x86/boot/startup/Makefile b/arch/x86/boot/startup/Makefile
> index ccdfc42a4d59..bb7c826e586c 100644
> --- a/arch/x86/boot/startup/Makefile
> +++ b/arch/x86/boot/startup/Makefile
> @@ -7,8 +7,9 @@ KBUILD_CFLAGS           += -D__DISABLE_EXPORTS -mcmodel=small -fPIC \
>                            -fno-stack-protector -D__NO_FORTIFY \
>                            -include $(srctree)/include/linux/hidden.h
>
> -# disable ftrace hooks
> +# disable ftrace hooks and LTO
>  KBUILD_CFLAGS  := $(subst $(CC_FLAGS_FTRACE),,$(KBUILD_CFLAGS))
> +KBUILD_CFLAGS  := $(filter-out $(CC_FLAGS_LTO),$(KBUILD_CFLAGS))
>  KASAN_SANITIZE := n
>  KCSAN_SANITIZE := n
>  KMSAN_SANITIZE := n
>
> ---
> base-commit: 9287216a0c8f7bf7b485e18ad71584b434b59bb6
> change-id: 20250414-x86-boot-startup-lto-error-26e0825706a3
>
> Best regards,
> --
> Nathan Chancellor <nathan@kernel.org>
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [tip: x86/boot] x86/boot/startup: Disable LTO for the startup code
  2025-04-14 19:26 [PATCH] x86/boot/startup: Disable LTO Nathan Chancellor
  2025-04-14 19:28 ` Ard Biesheuvel
@ 2025-04-17 10:19 ` tip-bot2 for Nathan Chancellor
  1 sibling, 0 replies; 3+ messages in thread
From: tip-bot2 for Nathan Chancellor @ 2025-04-17 10:19 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Linux Kernel Functional Testing, Nathan Chancellor, Ingo Molnar,
	Ard Biesheuvel, H. Peter Anvin, Kees Cook, Linus Torvalds,
	David Woodhouse, llvm, x86, linux-kernel

The following commit has been merged into the x86/boot branch of tip:

Commit-ID:     498cb872a111e25021ca5e2d91af7b7a2e62630f
Gitweb:        https://git.kernel.org/tip/498cb872a111e25021ca5e2d91af7b7a2e62630f
Author:        Nathan Chancellor <nathan@kernel.org>
AuthorDate:    Mon, 14 Apr 2025 12:26:07 -07:00
Committer:     Ingo Molnar <mingo@kernel.org>
CommitterDate: Thu, 17 Apr 2025 12:09:30 +02:00

x86/boot/startup: Disable LTO for the startup code

When building with CONFIG_LTO_CLANG, there is an error in the x86 boot
startup code because it builds with a different code model than the rest
of the kernel:

  ld.lld: error: Function Import: link error: linking module flags 'Code Model': IDs have conflicting values: 'i32 2' from vmlinux.a(head64.o at 1302448), and 'i32 1' from vmlinux.a(map_kernel.o at 1314208)
  ld.lld: error: Function Import: link error: linking module flags 'Code Model': IDs have conflicting values: 'i32 2' from vmlinux.a(common.o at 1306108), and 'i32 1' from vmlinux.a(gdt_idt.o at 1314148)

As this directory is for code that only runs during early system
initialization, LTO is not very important, so filter out the LTO flags
from KBUILD_CFLAGS for arch/x86/boot/startup to resolve the build error.

Fixes: 4cecebf200ef ("x86/boot: Move the early GDT/IDT setup code into startup/")
Reported-by: Linux Kernel Functional Testing <lkft@linaro.org>
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Acked-by: Ard Biesheuvel <ardb@kernel.org>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: David Woodhouse <dwmw@amazon.co.uk>
Cc: llvm@lists.linux.dev
Link: https://lore.kernel.org/r/20250414-x86-boot-startup-lto-error-v1-1-7c8bed7c131c@kernel.org

Closes: https://lore.kernel.org/CA+G9fYvnun+bhYgtt425LWxzOmj+8Jf3ruKeYxQSx-F6U7aisg@mail.gmail.com/
---
 arch/x86/boot/startup/Makefile | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/x86/boot/startup/Makefile b/arch/x86/boot/startup/Makefile
index ccdfc42..bb7c826 100644
--- a/arch/x86/boot/startup/Makefile
+++ b/arch/x86/boot/startup/Makefile
@@ -7,8 +7,9 @@ KBUILD_CFLAGS		+= -D__DISABLE_EXPORTS -mcmodel=small -fPIC \
 			   -fno-stack-protector -D__NO_FORTIFY \
 			   -include $(srctree)/include/linux/hidden.h
 
-# disable ftrace hooks
+# disable ftrace hooks and LTO
 KBUILD_CFLAGS	:= $(subst $(CC_FLAGS_FTRACE),,$(KBUILD_CFLAGS))
+KBUILD_CFLAGS	:= $(filter-out $(CC_FLAGS_LTO),$(KBUILD_CFLAGS))
 KASAN_SANITIZE	:= n
 KCSAN_SANITIZE	:= n
 KMSAN_SANITIZE	:= n

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-04-17 10:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-04-14 19:26 [PATCH] x86/boot/startup: Disable LTO Nathan Chancellor
2025-04-14 19:28 ` Ard Biesheuvel
2025-04-17 10:19 ` [tip: x86/boot] x86/boot/startup: Disable LTO for the startup code tip-bot2 for 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®