The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] x86/boot/compressed: Disable jump tables for clang
@ 2026-06-23 21:47 Nathan Chancellor
  2026-06-24  9:36 ` Ingo Molnar
  0 siblings, 1 reply; 5+ messages in thread
From: Nathan Chancellor @ 2026-06-23 21:47 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	Ard Biesheuvel
  Cc: Nick Desaulniers, Bill Wendling, Justin Stitt, linux-kernel, llvm,
	stable, Nathan Chancellor

After a recent upstream LLVM change to start generating jump and lookup
tables in switch statements in more instances [1], linking the
compressed x86 boot image when CONFIG_KERNEL_ZSTD is enabled fails with:

  ld.lld: error: Unexpected run-time relocations (.rela) detected!

Dumping the relocations in misc.o, which is the only file influenced by
CONFIG_KERNEL_ZSTD in the decompressor, shows dynamic relocations to
some string constants, which correspond to the string literals in the
switch statement in handle_zstd_error():

  Relocation section '.rela.data.rel.ro' at offset 0x277b0 contains 31 entries:
      Offset             Info             Type               Symbol's Value  Symbol's Name + Addend
  0000000000000000  0000006600000001 R_X86_64_64            0000000000000000 .rodata.str1.1 + 73a
  0000000000000008  0000006600000001 R_X86_64_64            0000000000000000 .rodata.str1.1 + 78e
  0000000000000010  0000006600000001 R_X86_64_64            0000000000000000 .rodata.str1.1 + 78e
  0000000000000018  0000006600000001 R_X86_64_64            0000000000000000 .rodata.str1.1 + 78e
  ...

This optimization is problematic for the decompressor environment, as it
is built as -fPIE without any explicit absolute references (as described
at the top of misc.c) while not applying any dynamic relocations, hence
the linker assertion. To opt out of this optimization, which is of
little value in this special early boot code, disable jump tables in the
decompressor when building with clang. This mirrors the other x86
startup code in arch/x86/boot/startup.

Cc: stable@vger.kernel.org
Closes: https://github.com/ClangBuiltLinux/linux/issues/2165
Link: https://github.com/llvm/llvm-project/commit/fa02a6ed66b1700c996b49c96c6bc0eb014c9518 [1]
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
---
 arch/x86/boot/compressed/Makefile | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
index 07e0e64b9a98..1c0d29e3eeba 100644
--- a/arch/x86/boot/compressed/Makefile
+++ b/arch/x86/boot/compressed/Makefile
@@ -31,6 +31,7 @@ KBUILD_CFLAGS += -Wundef
 KBUILD_CFLAGS += -DDISABLE_BRANCH_PROFILING
 cflags-$(CONFIG_X86_32) := -march=i386
 cflags-$(CONFIG_X86_64) := -mcmodel=small -mno-red-zone
+cflags-$(CONFIG_CC_IS_CLANG) += -fno-jump-tables
 KBUILD_CFLAGS += $(cflags-y)
 KBUILD_CFLAGS += -mno-mmx -mno-sse
 KBUILD_CFLAGS += -ffreestanding -fshort-wchar

---
base-commit: 4708cac0e22cfd217f48f7cec3c35e5922efcccd
change-id: 20260622-x86-boot-compressed-disable-jt-clang-ef1dfca25098

Best regards,
--  
Cheers,
Nathan


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

* Re: [PATCH] x86/boot/compressed: Disable jump tables for clang
  2026-06-23 21:47 [PATCH] x86/boot/compressed: Disable jump tables for clang Nathan Chancellor
@ 2026-06-24  9:36 ` Ingo Molnar
  2026-06-24  9:38   ` Peter Zijlstra
  0 siblings, 1 reply; 5+ messages in thread
From: Ingo Molnar @ 2026-06-24  9:36 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	Ard Biesheuvel, Nick Desaulniers, Bill Wendling, Justin Stitt,
	linux-kernel, llvm, stable


* Nathan Chancellor <nathan@kernel.org> wrote:

> After a recent upstream LLVM change to start generating jump and lookup
> tables in switch statements in more instances [1], linking the
> compressed x86 boot image when CONFIG_KERNEL_ZSTD is enabled fails with:
> 
>   ld.lld: error: Unexpected run-time relocations (.rela) detected!
> 
> Dumping the relocations in misc.o, which is the only file influenced by
> CONFIG_KERNEL_ZSTD in the decompressor, shows dynamic relocations to
> some string constants, which correspond to the string literals in the
> switch statement in handle_zstd_error():
> 
>   Relocation section '.rela.data.rel.ro' at offset 0x277b0 contains 31 entries:
>       Offset             Info             Type               Symbol's Value  Symbol's Name + Addend
>   0000000000000000  0000006600000001 R_X86_64_64            0000000000000000 .rodata.str1.1 + 73a
>   0000000000000008  0000006600000001 R_X86_64_64            0000000000000000 .rodata.str1.1 + 78e
>   0000000000000010  0000006600000001 R_X86_64_64            0000000000000000 .rodata.str1.1 + 78e
>   0000000000000018  0000006600000001 R_X86_64_64            0000000000000000 .rodata.str1.1 + 78e
>   ...
> 
> This optimization is problematic for the decompressor environment, as it
> is built as -fPIE without any explicit absolute references (as described
> at the top of misc.c) while not applying any dynamic relocations, hence
> the linker assertion. To opt out of this optimization, which is of
> little value in this special early boot code, disable jump tables in the
> decompressor when building with clang. This mirrors the other x86
> startup code in arch/x86/boot/startup.
> 
> Cc: stable@vger.kernel.org
> Closes: https://github.com/ClangBuiltLinux/linux/issues/2165
> Link: https://github.com/llvm/llvm-project/commit/fa02a6ed66b1700c996b49c96c6bc0eb014c9518 [1]
> Signed-off-by: Nathan Chancellor <nathan@kernel.org>
> ---
>  arch/x86/boot/compressed/Makefile | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
> index 07e0e64b9a98..1c0d29e3eeba 100644
> --- a/arch/x86/boot/compressed/Makefile
> +++ b/arch/x86/boot/compressed/Makefile
> @@ -31,6 +31,7 @@ KBUILD_CFLAGS += -Wundef
>  KBUILD_CFLAGS += -DDISABLE_BRANCH_PROFILING
>  cflags-$(CONFIG_X86_32) := -march=i386
>  cflags-$(CONFIG_X86_64) := -mcmodel=small -mno-red-zone
> +cflags-$(CONFIG_CC_IS_CLANG) += -fno-jump-tables

So, shouldn't we just use -fno-jump-tables for *all* compilers,
like we do in arch/x86/boot/startup/Makefile?

The point wouldn't be to just work around any Clang
jump-table optimization complications alone, but also
to synchronize the build options of very early code and such.

Thanks,

	Ingo

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

* Re: [PATCH] x86/boot/compressed: Disable jump tables for clang
  2026-06-24  9:36 ` Ingo Molnar
@ 2026-06-24  9:38   ` Peter Zijlstra
  2026-06-24  9:51     ` Ingo Molnar
  0 siblings, 1 reply; 5+ messages in thread
From: Peter Zijlstra @ 2026-06-24  9:38 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: Nathan Chancellor, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, x86, Ard Biesheuvel, Nick Desaulniers, Bill Wendling,
	Justin Stitt, linux-kernel, llvm, stable

On Wed, Jun 24, 2026 at 11:36:46AM +0200, Ingo Molnar wrote:
> 
> * Nathan Chancellor <nathan@kernel.org> wrote:
> 
> > After a recent upstream LLVM change to start generating jump and lookup
> > tables in switch statements in more instances [1], linking the
> > compressed x86 boot image when CONFIG_KERNEL_ZSTD is enabled fails with:
> > 
> >   ld.lld: error: Unexpected run-time relocations (.rela) detected!
> > 
> > Dumping the relocations in misc.o, which is the only file influenced by
> > CONFIG_KERNEL_ZSTD in the decompressor, shows dynamic relocations to
> > some string constants, which correspond to the string literals in the
> > switch statement in handle_zstd_error():
> > 
> >   Relocation section '.rela.data.rel.ro' at offset 0x277b0 contains 31 entries:
> >       Offset             Info             Type               Symbol's Value  Symbol's Name + Addend
> >   0000000000000000  0000006600000001 R_X86_64_64            0000000000000000 .rodata.str1.1 + 73a
> >   0000000000000008  0000006600000001 R_X86_64_64            0000000000000000 .rodata.str1.1 + 78e
> >   0000000000000010  0000006600000001 R_X86_64_64            0000000000000000 .rodata.str1.1 + 78e
> >   0000000000000018  0000006600000001 R_X86_64_64            0000000000000000 .rodata.str1.1 + 78e
> >   ...
> > 
> > This optimization is problematic for the decompressor environment, as it
> > is built as -fPIE without any explicit absolute references (as described
> > at the top of misc.c) while not applying any dynamic relocations, hence
> > the linker assertion. To opt out of this optimization, which is of
> > little value in this special early boot code, disable jump tables in the
> > decompressor when building with clang. This mirrors the other x86
> > startup code in arch/x86/boot/startup.
> > 
> > Cc: stable@vger.kernel.org
> > Closes: https://github.com/ClangBuiltLinux/linux/issues/2165
> > Link: https://github.com/llvm/llvm-project/commit/fa02a6ed66b1700c996b49c96c6bc0eb014c9518 [1]
> > Signed-off-by: Nathan Chancellor <nathan@kernel.org>
> > ---
> >  arch/x86/boot/compressed/Makefile | 1 +
> >  1 file changed, 1 insertion(+)
> > 
> > diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
> > index 07e0e64b9a98..1c0d29e3eeba 100644
> > --- a/arch/x86/boot/compressed/Makefile
> > +++ b/arch/x86/boot/compressed/Makefile
> > @@ -31,6 +31,7 @@ KBUILD_CFLAGS += -Wundef
> >  KBUILD_CFLAGS += -DDISABLE_BRANCH_PROFILING
> >  cflags-$(CONFIG_X86_32) := -march=i386
> >  cflags-$(CONFIG_X86_64) := -mcmodel=small -mno-red-zone
> > +cflags-$(CONFIG_CC_IS_CLANG) += -fno-jump-tables
> 
> So, shouldn't we just use -fno-jump-tables for *all* compilers,
> like we do in arch/x86/boot/startup/Makefile?
> 
> The point wouldn't be to just work around any Clang
> jump-table optimization complications alone, but also
> to synchronize the build options of very early code and such.

I'm sitting on a patch to unconditionally disable jump-tables for
x86_64:

  https://web.git.kernel.org/pub/scm/linux/kernel/git/peterz/queue.git/log/?h=x86/syscall

I need to fix the robot fallout and then actually post this.

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

* Re: [PATCH] x86/boot/compressed: Disable jump tables for clang
  2026-06-24  9:38   ` Peter Zijlstra
@ 2026-06-24  9:51     ` Ingo Molnar
  2026-06-24  9:55       ` Ingo Molnar
  0 siblings, 1 reply; 5+ messages in thread
From: Ingo Molnar @ 2026-06-24  9:51 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: Nathan Chancellor, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, x86, Ard Biesheuvel, Nick Desaulniers, Bill Wendling,
	Justin Stitt, linux-kernel, llvm, stable


* Peter Zijlstra <peterz@infradead.org> wrote:

> On Wed, Jun 24, 2026 at 11:36:46AM +0200, Ingo Molnar wrote:
> > 
> > * Nathan Chancellor <nathan@kernel.org> wrote:
> > 
> > > After a recent upstream LLVM change to start generating jump and lookup
> > > tables in switch statements in more instances [1], linking the
> > > compressed x86 boot image when CONFIG_KERNEL_ZSTD is enabled fails with:
> > > 
> > >   ld.lld: error: Unexpected run-time relocations (.rela) detected!
> > > 
> > > Dumping the relocations in misc.o, which is the only file influenced by
> > > CONFIG_KERNEL_ZSTD in the decompressor, shows dynamic relocations to
> > > some string constants, which correspond to the string literals in the
> > > switch statement in handle_zstd_error():
> > > 
> > >   Relocation section '.rela.data.rel.ro' at offset 0x277b0 contains 31 entries:
> > >       Offset             Info             Type               Symbol's Value  Symbol's Name + Addend
> > >   0000000000000000  0000006600000001 R_X86_64_64            0000000000000000 .rodata.str1.1 + 73a
> > >   0000000000000008  0000006600000001 R_X86_64_64            0000000000000000 .rodata.str1.1 + 78e
> > >   0000000000000010  0000006600000001 R_X86_64_64            0000000000000000 .rodata.str1.1 + 78e
> > >   0000000000000018  0000006600000001 R_X86_64_64            0000000000000000 .rodata.str1.1 + 78e
> > >   ...
> > > 
> > > This optimization is problematic for the decompressor environment, as it
> > > is built as -fPIE without any explicit absolute references (as described
> > > at the top of misc.c) while not applying any dynamic relocations, hence
> > > the linker assertion. To opt out of this optimization, which is of
> > > little value in this special early boot code, disable jump tables in the
> > > decompressor when building with clang. This mirrors the other x86
> > > startup code in arch/x86/boot/startup.
> > > 
> > > Cc: stable@vger.kernel.org
> > > Closes: https://github.com/ClangBuiltLinux/linux/issues/2165
> > > Link: https://github.com/llvm/llvm-project/commit/fa02a6ed66b1700c996b49c96c6bc0eb014c9518 [1]
> > > Signed-off-by: Nathan Chancellor <nathan@kernel.org>
> > > ---
> > >  arch/x86/boot/compressed/Makefile | 1 +
> > >  1 file changed, 1 insertion(+)
> > > 
> > > diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
> > > index 07e0e64b9a98..1c0d29e3eeba 100644
> > > --- a/arch/x86/boot/compressed/Makefile
> > > +++ b/arch/x86/boot/compressed/Makefile
> > > @@ -31,6 +31,7 @@ KBUILD_CFLAGS += -Wundef
> > >  KBUILD_CFLAGS += -DDISABLE_BRANCH_PROFILING
> > >  cflags-$(CONFIG_X86_32) := -march=i386
> > >  cflags-$(CONFIG_X86_64) := -mcmodel=small -mno-red-zone
> > > +cflags-$(CONFIG_CC_IS_CLANG) += -fno-jump-tables
> > 
> > So, shouldn't we just use -fno-jump-tables for *all* compilers,
> > like we do in arch/x86/boot/startup/Makefile?
> > 
> > The point wouldn't be to just work around any Clang
> > jump-table optimization complications alone, but also
> > to synchronize the build options of very early code and such.
> 
> I'm sitting on a patch to unconditionally disable jump-tables for
> x86_64:
> 
>   https://web.git.kernel.org/pub/scm/linux/kernel/git/peterz/queue.git/log/?h=x86/syscall

In particular:

  https://web.git.kernel.org/pub/scm/linux/kernel/git/peterz/queue.git/commit/?h=x86/syscall&id=76612388fe7aa41a8eb88f890d451bc17255eda0

> I need to fix the robot fallout and then actually post this.

That's perfect, thanks!

	Ingo

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

* Re: [PATCH] x86/boot/compressed: Disable jump tables for clang
  2026-06-24  9:51     ` Ingo Molnar
@ 2026-06-24  9:55       ` Ingo Molnar
  0 siblings, 0 replies; 5+ messages in thread
From: Ingo Molnar @ 2026-06-24  9:55 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: Nathan Chancellor, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, x86, Ard Biesheuvel, Nick Desaulniers, Bill Wendling,
	Justin Stitt, linux-kernel, llvm, stable


* Ingo Molnar <mingo@kernel.org> wrote:


> > I'm sitting on a patch to unconditionally disable jump-tables for
> > x86_64:
> > 
> >   https://web.git.kernel.org/pub/scm/linux/kernel/git/peterz/queue.git/log/?h=x86/syscall
> 
> In particular:
> 
>   https://web.git.kernel.org/pub/scm/linux/kernel/git/peterz/queue.git/commit/?h=x86/syscall&id=76612388fe7aa41a8eb88f890d451bc17255eda0

Side note: since arch/x86/boot/compressed/Makefile constructs
its own KBUILD_CFLAGS, so a change to that Makefile will still
be required to universally apply -fno-jump-tables and work
around this Clang optimization in the decompression code.

Thanks,

	Ingo

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

end of thread, other threads:[~2026-06-24  9:55 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-23 21:47 [PATCH] x86/boot/compressed: Disable jump tables for clang Nathan Chancellor
2026-06-24  9:36 ` Ingo Molnar
2026-06-24  9:38   ` Peter Zijlstra
2026-06-24  9:51     ` Ingo Molnar
2026-06-24  9:55       ` Ingo Molnar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox