[PATCH v2 1/2] riscv: add platform-specific double word shifts for riscv32

Dmitry Antipov dmantipov at yandex.ru
Fri Apr 10 03:49:31 PDT 2026


On Thu, 2026-04-09 at 16:22 -0700, Charlie Jenkins wrote:

> However, this change causes the libstub to bypass these new functions
> you have introduced. lib-ashldi3.o and lib-lshrdi3.o use the following
> rule to compile the generic arch libs:
> 
> $(obj)/lib-%.o: $(srctree)/lib/%.c FORCE
> 	$(call if_changed_rule,cc_o_c)
> 
> This is specifically for the efi libstub, the regular kernel (like in
> your test case in the next patch) will use these newly introduced
> functions.
> 
> One solution is to use this change instead:
> 
> diff --git a/drivers/firmware/efi/libstub/Makefile b/drivers/firmware/efi/libstub/Makefile
> index e386ffd009b7..775c34d80179 100644
> --- a/drivers/firmware/efi/libstub/Makefile
> +++ b/drivers/firmware/efi/libstub/Makefile
> @@ -96,7 +96,7 @@ CFLAGS_zboot-decompress-gzip.o        += -I$(srctree)/lib/zlib_inflate
>  zboot-obj-$(CONFIG_KERNEL_ZSTD)        := zboot-decompress-zstd.o lib-xxhash.o
>  CFLAGS_zboot-decompress-zstd.o += -I$(srctree)/lib/zstd
> 
> -zboot-obj-$(CONFIG_RISCV)      += lib-clz_ctz.o lib-ashldi3.o
> +zboot-obj-$(CONFIG_RISCV)      += lib-clz_ctz.o ../../../../arch/riscv/lib/ashldi3.o ../../../../arch/riscv/lib/lshrdi3.o
>  lib-$(CONFIG_EFI_ZBOOT)                += zboot.o $(zboot-obj-y)
> 
>  lib-$(CONFIG_UNACCEPTED_MEMORY) += unaccepted_memory.o bitmap.o find.o
> 
> This will link against the correct shifting libraries.

1) This seems wrong for riscv64 which can have CONFIG_EFI_ZBOOT=y as
   well but doesn't need these 64-on-32 quirks.

2) IIUC EFI stub executes just once before the kernel is booting, so it
   doesn't seem too critical to link arch-specific (optimized) things
   against it.

So I'm voting for something like:

diff --git a/drivers/firmware/efi/Kconfig b/drivers/firmware/efi/Kconfig
index 29e0729299f5..55fb5a20aa25 100644
--- a/drivers/firmware/efi/Kconfig
+++ b/drivers/firmware/efi/Kconfig
@@ -85,6 +85,10 @@ config EFI_ZBOOT
 	  provided that the loader implements the decompression algorithm.
 	  (The compression algorithm used is described in the zboot header)
 
+config EFI_ZBOOT_EXTRAS
+	bool
+	default y if RISCV && 32BIT
+
 config EFI_ARMSTUB_DTB_LOADER
 	bool "Enable the DTB loader"
 	depends on EFI_GENERIC_STUB && !RISCV && !LOONGARCH
diff --git a/drivers/firmware/efi/libstub/Makefile
b/drivers/firmware/efi/libstub/Makefile
index f83301a19dc5..8f199b99d0f6 100644
--- a/drivers/firmware/efi/libstub/Makefile
+++ b/drivers/firmware/efi/libstub/Makefile
@@ -96,7 +96,8 @@ CFLAGS_zboot-decompress-gzip.o	+= -
I$(srctree)/lib/zlib_inflate
 zboot-obj-$(CONFIG_KERNEL_ZSTD)	:= zboot-decompress-zstd.o lib-
xxhash.o
 CFLAGS_zboot-decompress-zstd.o	+= -I$(srctree)/lib/zstd
 
-zboot-obj-$(CONFIG_RISCV)	+= lib-clz_ctz.o lib-ashldi3.o lib-lshrdi3.o
+zboot-obj-extras-$(CONFIG_EFI_ZBOOT_EXTRAS) += lib-ashldi3.o lib-lshrdi3.o
+zboot-obj-$(CONFIG_RISCV)	+= lib-clz_ctz.o $(zboot-obj-extras-y)
 lib-$(CONFIG_EFI_ZBOOT)		+= zboot.o $(zboot-obj-y)
 
 lib-$(CONFIG_UNACCEPTED_MEMORY) += unaccepted_memory.o bitmap.o find.o

Kindly ask you to test this. And it will be even more helpful if you can test
building an running riscv64 as well :-).

Dmitry



More information about the linux-riscv mailing list