Linux EFI development
 help / color / mirror / Atom feed
* [PATCH 0/3] efi/libstub: Fix library dependencies
@ 2026-11-26 15:50 Ard Biesheuvel
  2026-11-26 15:50 ` [PATCH 1/3] efi/libstub: loongarch: Provide 64-bit integer shift helpers for 32-bit Ard Biesheuvel
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Ard Biesheuvel @ 2026-11-26 15:50 UTC (permalink / raw)
  To: linux-efi
  Cc: loongarch, Ard Biesheuvel, Dmitry Antipov, Huacai Chen,
	WANG Xuerui

From: Ard Biesheuvel <ardb@kernel.org>

Dmitry reports that 32-bit LoongArch builds with EFI_ZBOOT disabled fail
to link, due to missing helpers for 64-bit integer shifts.

Fix this, and while at it, tweak the build so some of these dependencies
can be dropped for the zboot build.

Cc: Dmitry Antipov <dmantipov@yandex.ru>
Cc: Huacai Chen <chenhuacai@kernel.org>
Cc: WANG Xuerui <kernel@xen0n.name>

Ard Biesheuvel (3):
  efi/libstub: loongarch: Provide 64-bit integer shift helpers for
    32-bit
  efi/zboot: Eliminate unused code from the zboot executable
  efi/libstub: Provide library helpers only where needed

 drivers/firmware/efi/libstub/Makefile       | 18 +++++++++++-------
 drivers/firmware/efi/libstub/Makefile.zboot |  3 ++-
 drivers/firmware/efi/libstub/zboot.lds      |  4 ++--
 3 files changed, 15 insertions(+), 10 deletions(-)

-- 
2.56.1.839.g22a8290db9-goog


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

* [PATCH 1/3] efi/libstub: loongarch: Provide 64-bit integer shift helpers for 32-bit
  2026-11-26 15:50 [PATCH 0/3] efi/libstub: Fix library dependencies Ard Biesheuvel
@ 2026-11-26 15:50 ` Ard Biesheuvel
  2026-11-26 15:50 ` [PATCH 2/3] efi/zboot: Eliminate unused code from the zboot executable Ard Biesheuvel
  2026-11-26 15:50 ` [PATCH 3/3] efi/libstub: Provide library helpers only where needed Ard Biesheuvel
  2 siblings, 0 replies; 4+ messages in thread
From: Ard Biesheuvel @ 2026-11-26 15:50 UTC (permalink / raw)
  To: linux-efi
  Cc: loongarch, Ard Biesheuvel, Dmitry Antipov, Huacai Chen,
	WANG Xuerui, kernel test robot

From: Ard Biesheuvel <ardb@kernel.org>

The EFI stub's copy of lib/cmdline.c performs 64-bit shifts in
memparse() [which is never actually called from the stub], and so it
needs library routines when running on 32-bit CPUs that lack native
instructions for this.

The LoongArch 32-bit EFI stub build already pulls in the library helpers
that are needed for this, but only when CONFIG_EFI_ZBOOT=y, which is not
sufficient, given that the same helpers will be needed in the vmlinux
build for the builtin copy of the EFI stub.

On other architectures, the builtin copy will call vmlinux's versions of
those routines, which are exposed to the stub via aliases in the linker
script. However, on LoongArch, those are C implementations that may be
instrumented and therefore unsuitable for use in the EFI stub.

Reported-by: Dmitry Antipov <dmantipov@yandex.ru>
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/20261122125352.gAcg5yLx-lkp@intel.com/
Fixes: 442082297e3d ("riscv: fix building compressed EFI image")
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
 drivers/firmware/efi/libstub/Makefile | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/firmware/efi/libstub/Makefile b/drivers/firmware/efi/libstub/Makefile
index bbab12b8eb4b..ba6c9e763862 100644
--- a/drivers/firmware/efi/libstub/Makefile
+++ b/drivers/firmware/efi/libstub/Makefile
@@ -88,7 +88,9 @@ lib-$(CONFIG_ARM64)		+= kaslr.o arm64.o arm64-stub.o smbios.o
 lib-$(CONFIG_X86)		+= x86-stub.o smbios.o
 lib-$(CONFIG_X86_64)		+= x86-5lvl.o
 lib-$(CONFIG_RISCV)		+= kaslr.o riscv.o riscv-stub.o
-lib-$(CONFIG_LOONGARCH)		+= loongarch.o loongarch-stub.o
+lib-loongarch-$(CONFIG_32BIT)	+= lib-ashldi3.o lib-lshrdi3.o
+lib-$(CONFIG_LOONGARCH)		+= loongarch.o loongarch-stub.o \
+				   $(lib-loongarch-y)
 
 CFLAGS_arm32-stub.o		:= -DTEXT_OFFSET=$(TEXT_OFFSET)
 
@@ -99,8 +101,7 @@ CFLAGS_zboot-decompress-zstd.o	+= -I$(srctree)/lib/zstd
 
 zboot-riscv-obj-$(CONFIG_32BIT)	:= lib-ashldi3.o lib-lshrdi3.o
 zboot-obj-$(CONFIG_RISCV)	+= lib-clz_ctz.o $(zboot-riscv-obj-y)
-zboot-loongarch-obj-$(CONFIG_32BIT) := lib-ashldi3.o lib-lshrdi3.o
-zboot-obj-$(CONFIG_LOONGARCH)	+= lib-clz_ctz.o $(zboot-loongarch-obj-y)
+zboot-obj-$(CONFIG_LOONGARCH)	+= lib-clz_ctz.o
 lib-$(CONFIG_EFI_ZBOOT)		+= zboot.o $(zboot-obj-y)
 
 lib-$(CONFIG_UNACCEPTED_MEMORY) += unaccepted_memory.o bitmap.o find.o
-- 
2.56.1.839.g22a8290db9-goog


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

* [PATCH 2/3] efi/zboot: Eliminate unused code from the zboot executable
  2026-11-26 15:50 [PATCH 0/3] efi/libstub: Fix library dependencies Ard Biesheuvel
  2026-11-26 15:50 ` [PATCH 1/3] efi/libstub: loongarch: Provide 64-bit integer shift helpers for 32-bit Ard Biesheuvel
@ 2026-11-26 15:50 ` Ard Biesheuvel
  2026-11-26 15:50 ` [PATCH 3/3] efi/libstub: Provide library helpers only where needed Ard Biesheuvel
  2 siblings, 0 replies; 4+ messages in thread
From: Ard Biesheuvel @ 2026-11-26 15:50 UTC (permalink / raw)
  To: linux-efi
  Cc: loongarch, Ard Biesheuvel, Dmitry Antipov, Huacai Chen,
	WANG Xuerui

From: Ard Biesheuvel <ardb@kernel.org>

Wire up -ffunction-sections and --gc-sections so that unused functions
are dropped from the build. This saves some space, but more importantly,
will allow us to get rid of library routines that are never called
(64-bit shift on 32-bit, clz/ctz on RISC-V)

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
 drivers/firmware/efi/libstub/Makefile       | 2 ++
 drivers/firmware/efi/libstub/Makefile.zboot | 3 ++-
 drivers/firmware/efi/libstub/zboot.lds      | 4 ++--
 3 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/firmware/efi/libstub/Makefile b/drivers/firmware/efi/libstub/Makefile
index ba6c9e763862..20b5b77956d1 100644
--- a/drivers/firmware/efi/libstub/Makefile
+++ b/drivers/firmware/efi/libstub/Makefile
@@ -34,6 +34,8 @@ cflags-$(CONFIG_LOONGARCH)	+= -fpie
 
 cflags-$(CONFIG_EFI_PARAMS_FROM_FDT)	+= -I$(srctree)/scripts/dtc/libfdt
 
+cflags-$(CONFIG_EFI_ZBOOT)	+= -ffunction-sections
+
 KBUILD_CFLAGS			:= $(subst $(CC_FLAGS_FTRACE),,$(cflags-y)) \
 				   -Os -DDISABLE_BRANCH_PROFILING \
 				   -include $(srctree)/include/linux/hidden.h \
diff --git a/drivers/firmware/efi/libstub/Makefile.zboot b/drivers/firmware/efi/libstub/Makefile.zboot
index 52baacf3e9d9..3b827e4b571d 100644
--- a/drivers/firmware/efi/libstub/Makefile.zboot
+++ b/drivers/firmware/efi/libstub/Makefile.zboot
@@ -50,7 +50,8 @@ endif
 
 ZBOOT_DEPS := $(obj)/zboot-header.o $(objtree)/drivers/firmware/efi/libstub/lib.a
 
-LDFLAGS_vmlinuz.efi.elf := -T $(srctree)/drivers/firmware/efi/libstub/zboot.lds
+LDFLAGS_vmlinuz.efi.elf := -T $(srctree)/drivers/firmware/efi/libstub/zboot.lds \
+			   --gc-sections
 $(obj)/vmlinuz.efi.elf: $(obj)/vmlinuz.o $(ZBOOT_DEPS) FORCE
 	$(call if_changed,ld)
 
diff --git a/drivers/firmware/efi/libstub/zboot.lds b/drivers/firmware/efi/libstub/zboot.lds
index a785c0123749..f3d4342c8a08 100644
--- a/drivers/firmware/efi/libstub/zboot.lds
+++ b/drivers/firmware/efi/libstub/zboot.lds
@@ -16,7 +16,7 @@ SECTIONS
 
 	.rodata : ALIGN(8) {
 		__efistub__gzdata_start = .;
-		*(.gzdata)
+		KEEP(*(.gzdata))
 		__efistub_payload_size = . - 4;
 		__efistub__gzdata_end = .;
 		*(.rodata* .init.rodata* .srodata*)
@@ -31,7 +31,7 @@ SECTIONS
 
         .sbat : ALIGN(4096) {
 		_sbat = .;
-		*(.sbat)
+		KEEP(*(.sbat))
 		_esbat = ALIGN(4096);
 		. = _esbat;
 	}
-- 
2.56.1.839.g22a8290db9-goog


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

* [PATCH 3/3] efi/libstub: Provide library helpers only where needed
  2026-11-26 15:50 [PATCH 0/3] efi/libstub: Fix library dependencies Ard Biesheuvel
  2026-11-26 15:50 ` [PATCH 1/3] efi/libstub: loongarch: Provide 64-bit integer shift helpers for 32-bit Ard Biesheuvel
  2026-11-26 15:50 ` [PATCH 2/3] efi/zboot: Eliminate unused code from the zboot executable Ard Biesheuvel
@ 2026-11-26 15:50 ` Ard Biesheuvel
  2 siblings, 0 replies; 4+ messages in thread
From: Ard Biesheuvel @ 2026-11-26 15:50 UTC (permalink / raw)
  To: linux-efi
  Cc: loongarch, Ard Biesheuvel, Dmitry Antipov, Huacai Chen,
	WANG Xuerui

From: Ard Biesheuvel <ardb@kernel.org>

Now that dead stub code is being eliminated by the linker, the only
remaining user of the 64-bit left shift and clz/ctz helper routines is
ZSTD compression, and only in some cases:

- the 64-bit left shift is only needed on 32-bit architectures
- the clz/ctz helper is needed on all RISC-V and 32-bit reduced
  LoongArch

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
 drivers/firmware/efi/libstub/Makefile | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/firmware/efi/libstub/Makefile b/drivers/firmware/efi/libstub/Makefile
index 20b5b77956d1..ba6d67e5cd78 100644
--- a/drivers/firmware/efi/libstub/Makefile
+++ b/drivers/firmware/efi/libstub/Makefile
@@ -98,14 +98,15 @@ CFLAGS_arm32-stub.o		:= -DTEXT_OFFSET=$(TEXT_OFFSET)
 
 zboot-obj-y			:= zboot-decompress-gzip.o
 CFLAGS_zboot-decompress-gzip.o	+= -I$(srctree)/lib/zlib_inflate
-zboot-obj-$(CONFIG_KERNEL_ZSTD)	:= zboot-decompress-zstd.o lib-xxhash.o
+
+zstd-obj-$(CONFIG_32BIT)	:= lib-ashldi3.o
+zstd-obj-$(CONFIG_RISCV)	+= lib-clz_ctz.o
+zstd-obj-$(CONFIG_32BIT_REDUCED) += lib-clz_ctz.o # loongarch
+zboot-obj-$(CONFIG_KERNEL_ZSTD)	:= zboot-decompress-zstd.o lib-xxhash.o \
+				   $(zstd-obj-y)
 CFLAGS_zboot-decompress-zstd.o	+= -I$(srctree)/lib/zstd
 
-zboot-riscv-obj-$(CONFIG_32BIT)	:= lib-ashldi3.o lib-lshrdi3.o
-zboot-obj-$(CONFIG_RISCV)	+= lib-clz_ctz.o $(zboot-riscv-obj-y)
-zboot-obj-$(CONFIG_LOONGARCH)	+= lib-clz_ctz.o
 lib-$(CONFIG_EFI_ZBOOT)		+= zboot.o $(zboot-obj-y)
-
 lib-$(CONFIG_UNACCEPTED_MEMORY) += unaccepted_memory.o bitmap.o find.o
 
 targets				:= $(lib-y)
-- 
2.56.1.839.g22a8290db9-goog


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

end of thread, other threads:[~2026-11-26 15:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-26 15:50 [PATCH 0/3] efi/libstub: Fix library dependencies Ard Biesheuvel
2026-11-26 15:50 ` [PATCH 1/3] efi/libstub: loongarch: Provide 64-bit integer shift helpers for 32-bit Ard Biesheuvel
2026-11-26 15:50 ` [PATCH 2/3] efi/zboot: Eliminate unused code from the zboot executable Ard Biesheuvel
2026-11-26 15:50 ` [PATCH 3/3] efi/libstub: Provide library helpers only where needed Ard Biesheuvel

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