[RFC PATCH] x86/boot: use zstd -19 if building for 32-bit

Mingcong Bai <[email protected]> Tue, 28 Jul 2026 22:31:35 +0800
Newsgroups gmane.linux.kbuild.devel,gmane.linux.kernel
Message-ID <[email protected]>
When using native build environments (that is, 32-bit x86 chroot/container
as build environment for 32-bit x86 binaries), `zstd -22' requests more
virtual memory than that could be allowed on 32-bit hosts.

Introduce `cmd_zstd_with_size' for CONFIG_X86_32 builds.

This is quite possibly just stupid... But there doesn't seem to be a way
to detect the host environment. So I'm sending this patch as a means to
ask for your opinions.

Any help would be greated appreciated.

Signed-off-by: Mingcong Bai <[email protected]>
---
 arch/x86/boot/compressed/Makefile | 5 +++++
 scripts/Makefile.lib              | 3 +++
 2 files changed, 8 insertions(+)

diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
index 07e0e64b9a98..2261fb0d4d1d 100644
--- a/arch/x86/boot/compressed/Makefile
+++ b/arch/x86/boot/compressed/Makefile
@@ -143,8 +143,13 @@ $(obj)/vmlinux.bin.lzo: $(vmlinux.bin.all-y) FORCE
 	$(call if_changed,lzo_with_size)
 $(obj)/vmlinux.bin.lz4: $(vmlinux.bin.all-y) FORCE
 	$(call if_changed,lz4_with_size)
+ifdef CONFIG_X86_32
+$(obj)/vmlinux.bin.zst: $(vmlinux.bin.all-y) FORCE
+	$(call if_changed,zstd_with_size)
+else
 $(obj)/vmlinux.bin.zst: $(vmlinux.bin.all-y) FORCE
 	$(call if_changed,zstd22_with_size)
+endif
 
 suffix-$(CONFIG_KERNEL_GZIP)	:= gz
 suffix-$(CONFIG_KERNEL_BZIP2)	:= bz2
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index 0718e39cedda..09910dc57af3 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -464,6 +464,9 @@ quiet_cmd_xzmisc = XZMISC  $@
 quiet_cmd_zstd = ZSTD    $@
       cmd_zstd = cat $(real-prereqs) | $(ZSTD) -19 > $@
 
+quiet_cmd_zstd = ZSTD    $@
+      cmd_zstd_with_size = { cat $(real-prereqs) | $(ZSTD) -19; $(size_append); } > $@
+
 quiet_cmd_zstd22 = ZSTD22  $@
       cmd_zstd22 = cat $(real-prereqs) | $(ZSTD) -22 --ultra > $@
 
-- 
2.55.0