From nobody Wed Jun 17 07:37:14 2026 Received: from forward205d.mail.yandex.net (forward205d.mail.yandex.net [178.154.239.216]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 702133AF672; Mon, 27 Apr 2026 09:07:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.154.239.216 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777280845; cv=none; b=NGBqMuI6VOyLNU3/Xwi39j3VCT8rGzCkJLVhQE9Gh/W3BkEsYkmQ9DnK+8NyXukwL9536vTLabxxkTTRdbtQHJi6DUq6z3/cNYcBmOri29PCEr8lWp2zJA7yoNE5s5C8meNgNHdG0/QFRWMlXs0QVjfe0zmbQLj7FoCTWPcMtIM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777280845; c=relaxed/simple; bh=s7HRcC8pRnTfGNUBuga3UrQ9BMLCjcP+JgeRbvw4KBo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sDGjVaUcYMGwQ/vVKAAdgKk+SnsSxp/ifJ7QOJca77gFc51NssSpj39Z4Jh2FwcqPRLM+l1enmEpHr7e7NvLz5oIr9fL69vfmvnIMV0IATx8cCZ6Vq+wF0kvf+IJH5sYesdrZ9xinqDlAv7LtmKTLvArgjZ5ZGrs5m/6S8CCSPA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=yandex.ru; spf=pass smtp.mailfrom=yandex.ru; dkim=pass (1024-bit key) header.d=yandex.ru header.i=@yandex.ru header.b=bgP1eI8m; arc=none smtp.client-ip=178.154.239.216 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=yandex.ru Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=yandex.ru Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=yandex.ru header.i=@yandex.ru header.b="bgP1eI8m" Received: from forward101d.mail.yandex.net (forward101d.mail.yandex.net [IPv6:2a02:6b8:c41:1300:1:45:d181:d101]) by forward205d.mail.yandex.net (Yandex) with ESMTPS id CF64185031; Mon, 27 Apr 2026 12:01:46 +0300 (MSK) Received: from mail-nwsmtp-smtp-production-main-52.klg.yp-c.yandex.net (mail-nwsmtp-smtp-production-main-52.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:ea2:0:640:ef77:0]) by forward101d.mail.yandex.net (Yandex) with ESMTPS id 9212FC0099; Mon, 27 Apr 2026 12:01:38 +0300 (MSK) Received: by mail-nwsmtp-smtp-production-main-52.klg.yp-c.yandex.net (smtp) with ESMTPSA id X1UMu7lR5a60-vBBmAnZ1; Mon, 27 Apr 2026 12:01:37 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1777280497; bh=SfPCgNzhDXjDmJVjxPAqvTk7bkZqDRTJfwJQWV27XB8=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=bgP1eI8mxQi4SZO2v3iPIUFi44crndhzQMrMRMqEVJz0qheKUnoaaEO0h/6D4ZHdc l0EQ+jXe6yg3+Lv1TafdN//ivnOsVS0tLTMVd/UFFnD88ohXXEigqaXyprVq92Po8M cSrRDE7OFr2o4ij1HR4r/Vk37c6QDGKlPUlXrJkc= Authentication-Results: mail-nwsmtp-smtp-production-main-52.klg.yp-c.yandex.net; dkim=pass header.i=@yandex.ru From: Dmitry Antipov To: Paul Walmsley , Palmer Dabbelt , Albert Ou Cc: Andrew Morton , Andy Shevchenko , Charlie Jenkins , Alexandre Ghiti , Ard Biesheuvel , linux-riscv@lists.infradead.org, linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org, Dmitry Antipov , kernel test robot Subject: [PATCH v7 1/3] riscv: add platform-specific double word shifts for riscv32 Date: Mon, 27 Apr 2026 12:01:03 +0300 Message-ID: <20260427090105.705529-2-dmantipov@yandex.ru> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260427090105.705529-1-dmantipov@yandex.ru> References: <20260427090105.705529-1-dmantipov@yandex.ru> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add riscv32-specific '__ashldi3()', '__ashrdi3()', and '__lshrdi3()'. Initially it was intended to fix the following link error observed when building EFI-enabled kernel with CONFIG_EFI_STUB=3Dy and CONFIG_EFI_GENERIC_STUB=3Dy: riscv32-linux-gnu-ld: ./drivers/firmware/efi/libstub/lib-cmdline.stub.o: in= function `__efistub_.L49': __efistub_cmdline.c:(.init.text+0x1f2): undefined reference to `__efistub__= _ashldi3' riscv32-linux-gnu-ld: __efistub_cmdline.c:(.init.text+0x202): undefined ref= erence to `__efistub___lshrdi3' Reported at [1] trying to build https://patchew.org/linux/20260212164413.88= 9625-1-dmantipov@yandex.ru, tested with 'qemu-system-riscv32 -M virt' only. Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-kbuild-all/202603041925.KLKqpK6N-lkp@int= el.com [1] Suggested-by: Ard Biesheuvel Tested-by: Charlie Jenkins Assisted-by: gemini/gemini-3.1-pro-preview sashiko Signed-off-by: Dmitry Antipov --- v7: export for stub and optimize '__ashrdi3()' (Sashiko) v4, v5, v6: and upwards: bump version to match the series v3: more tests by Charlie Jenkins v2: adjust commit message --- arch/riscv/Kconfig | 3 --- arch/riscv/kernel/image-vars.h | 9 +++++++++ arch/riscv/lib/Makefile | 1 + arch/riscv/lib/ashldi3.S | 36 ++++++++++++++++++++++++++++++++++ arch/riscv/lib/ashrdi3.S | 36 ++++++++++++++++++++++++++++++++++ arch/riscv/lib/lshrdi3.S | 36 ++++++++++++++++++++++++++++++++++ 6 files changed, 118 insertions(+), 3 deletions(-) create mode 100644 arch/riscv/lib/ashldi3.S create mode 100644 arch/riscv/lib/ashrdi3.S create mode 100644 arch/riscv/lib/lshrdi3.S diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index d235396c4514..b1198b41c486 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -404,9 +404,6 @@ config ARCH_RV32I bool "RV32I" depends on NONPORTABLE select 32BIT - select GENERIC_LIB_ASHLDI3 - select GENERIC_LIB_ASHRDI3 - select GENERIC_LIB_LSHRDI3 select GENERIC_LIB_UCMPDI2 =20 config ARCH_RV64I diff --git a/arch/riscv/kernel/image-vars.h b/arch/riscv/kernel/image-vars.h index 3bd9d06a8b8f..7b44b94f1283 100644 --- a/arch/riscv/kernel/image-vars.h +++ b/arch/riscv/kernel/image-vars.h @@ -32,6 +32,15 @@ __efistub___init_text_end =3D __init_text_end; __efistub_sysfb_primary_display =3D sysfb_primary_display; #endif =20 +/* + * These double-word integer shifts are used by the library code, and + * the first two of them are required to link EFI stub. Note __ashrdi3() + * is not actually used by the stub but this may change in the future. + */ +PROVIDE(__efistub___lshrdi3 =3D __lshrdi3); +PROVIDE(__efistub___ashldi3 =3D __ashldi3); +PROVIDE(__efistub___ashrdi3 =3D __ashrdi3); + #endif =20 #endif /* __RISCV_KERNEL_IMAGE_VARS_H */ diff --git a/arch/riscv/lib/Makefile b/arch/riscv/lib/Makefile index 6f767b2a349d..f668b98970bd 100644 --- a/arch/riscv/lib/Makefile +++ b/arch/riscv/lib/Makefile @@ -16,6 +16,7 @@ ifeq ($(CONFIG_MMU), y) lib-$(CONFIG_RISCV_ISA_V) +=3D uaccess_vector.o endif lib-$(CONFIG_MMU) +=3D uaccess.o +lib-$(CONFIG_32BIT) +=3D ashldi3.o ashrdi3.o lshrdi3.o lib-$(CONFIG_64BIT) +=3D tishift.o lib-$(CONFIG_RISCV_ISA_ZICBOZ) +=3D clear_page.o obj-$(CONFIG_FUNCTION_ERROR_INJECTION) +=3D error-inject.o diff --git a/arch/riscv/lib/ashldi3.S b/arch/riscv/lib/ashldi3.S new file mode 100644 index 000000000000..c3408862e2f6 --- /dev/null +++ b/arch/riscv/lib/ashldi3.S @@ -0,0 +1,36 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/** + * Adopted for the Linux kernel from IPXE project, see + * https://github.com/ipxe/ipxe/blob/master/src/arch/riscv32/libgcc/llshif= t.S + */ + +#include +#include + +/** + * Shift left + * + * @v a1:a0 Value to shift + * @v a2 Shift amount + * @ret a1:a0 Shifted value + */ + +SYM_FUNC_START(__ashldi3) + + /* Perform shift by 32 bits, if applicable */ + li t0, 32 + sub t1, t0, a2 + bgtz t1, 1f + mv a1, a0 + mv a0, zero +1: /* Perform shift by modulo-32 bits, if applicable */ + andi a2, a2, 0x1f + beqz a2, 2f + srl t2, a0, t1 + sll a0, a0, a2 + sll a1, a1, a2 + or a1, a1, t2 +2: ret + +SYM_FUNC_END(__ashldi3) +EXPORT_SYMBOL(__ashldi3) diff --git a/arch/riscv/lib/ashrdi3.S b/arch/riscv/lib/ashrdi3.S new file mode 100644 index 000000000000..426de0946606 --- /dev/null +++ b/arch/riscv/lib/ashrdi3.S @@ -0,0 +1,36 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/** + * Adopted for the Linux kernel from IPXE project, see + * https://github.com/ipxe/ipxe/blob/master/src/arch/riscv32/libgcc/llshif= t.S + */ + +#include +#include + +/** + * Arithmetic shift right + * + * @v a1:a0 Value to shift + * @v a2 Shift amount + * @ret a1:a0 Shifted value + */ + +SYM_FUNC_START(__ashrdi3) + + /* Perform shift by 32 bits, if applicable */ + li t0, 32 + sub t1, t0, a2 + bgtz t1, 1f + mv a0, a1 + srai a1, a1, 31 +1: /* Perform shift by modulo-32 bits, if applicable */ + andi a2, a2, 0x1f + beqz a2, 2f + sll t2, a1, t1 + sra a1, a1, a2 + srl a0, a0, a2 + or a0, a0, t2 +2: ret + +SYM_FUNC_END(__ashrdi3) +EXPORT_SYMBOL(__ashrdi3) diff --git a/arch/riscv/lib/lshrdi3.S b/arch/riscv/lib/lshrdi3.S new file mode 100644 index 000000000000..1af03985ccb7 --- /dev/null +++ b/arch/riscv/lib/lshrdi3.S @@ -0,0 +1,36 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/** + * Adopted for the Linux kernel from IPXE project, see + * https://github.com/ipxe/ipxe/blob/master/src/arch/riscv32/libgcc/llshif= t.S + */ + +#include +#include + +/** + * Logical shift right + * + * @v a1:a0 Value to shift + * @v a2 Shift amount + * @ret a1:a0 Shifted value + */ + +SYM_FUNC_START(__lshrdi3) + + /* Perform shift by 32 bits, if applicable */ + li t0, 32 + sub t1, t0, a2 + bgtz t1, 1f + mv a0, a1 + mv a1, zero +1: /* Perform shift by modulo-32 bits, if applicable */ + andi a2, a2, 0x1f + beqz a2, 2f + sll t2, a1, t1 + srl a1, a1, a2 + srl a0, a0, a2 + or a0, a0, t2 +2: ret + +SYM_FUNC_END(__lshrdi3) +EXPORT_SYMBOL(__lshrdi3) --=20 2.53.0 From nobody Wed Jun 17 07:37:14 2026 Received: from forward206d.mail.yandex.net (forward206d.mail.yandex.net [178.154.239.215]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 15E3A379ECD; Mon, 27 Apr 2026 09:08:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.154.239.215 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777280899; cv=none; b=R6denk0XmHG3RUI2a0jy5B2ATpY/ObXOrfmUdeX+7ZgO9fW14tZla161cDQeM1n+OboUri0G85UbKmy+yKpPQmSYmGR74LEtCa0GuRR4P2jggx9GTj05iwSlqodFf0GwCp61dALh3qGtS5YmsM0+7/A2lZ8SwRmA12B7WLy98ko= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777280899; c=relaxed/simple; bh=t+JcRm5NR2mybg/9h3cRQ8HtuNpS0l6wbFDxbMeOwHU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BUqPm9UAp0cld38BIXBaeHVXCGH40MUeslop2mAOUdd8zpy7v77UXjt4drncPppLCfNM0Th3cS7tqlZsuAx6oiMaBbHatmeHBn5+L2R0Ah8NU9c7kLrx5sppvtx3A5Q0U7pIvO2/CZnUjk7AlMQXXYLmqTsi1IAMQqIf/mDOotI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=yandex.ru; spf=pass smtp.mailfrom=yandex.ru; dkim=pass (1024-bit key) header.d=yandex.ru header.i=@yandex.ru header.b=AZjLvmZU; arc=none smtp.client-ip=178.154.239.215 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=yandex.ru Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=yandex.ru Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=yandex.ru header.i=@yandex.ru header.b="AZjLvmZU" Received: from forward102d.mail.yandex.net (forward102d.mail.yandex.net [IPv6:2a02:6b8:c41:1300:1:45:d181:d102]) by forward206d.mail.yandex.net (Yandex) with ESMTPS id ACEDF83032; Mon, 27 Apr 2026 12:01:46 +0300 (MSK) Received: from mail-nwsmtp-smtp-production-main-52.klg.yp-c.yandex.net (mail-nwsmtp-smtp-production-main-52.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:ea2:0:640:ef77:0]) by forward102d.mail.yandex.net (Yandex) with ESMTPS id 657D1C00E5; Mon, 27 Apr 2026 12:01:39 +0300 (MSK) Received: by mail-nwsmtp-smtp-production-main-52.klg.yp-c.yandex.net (smtp) with ESMTPSA id X1UMu7lR5a60-D24EYp4R; Mon, 27 Apr 2026 12:01:38 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1777280498; bh=kgGSD4RFaRxsPKilZr3yCajnw4z8e4iF7+oPlH/eW88=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=AZjLvmZUF23DafnEdfSF78mpUii12CcXAKhffFnq2CJxaOyqWacJVbRi7jHMALI7Y 3KKLNR/bnicDJsI4UmfbGoFq8RKO/EwDUi2ZkU5G3dl2GHSCDBHd15A1da2+HzheDF KPyYZ5uWdTm89bgVocKA0ufe7ZlrdGDvpjLyiAuk= Authentication-Results: mail-nwsmtp-smtp-production-main-52.klg.yp-c.yandex.net; dkim=pass header.i=@yandex.ru From: Dmitry Antipov To: Paul Walmsley , Palmer Dabbelt , Albert Ou Cc: Andrew Morton , Andy Shevchenko , Charlie Jenkins , Alexandre Ghiti , Ard Biesheuvel , linux-riscv@lists.infradead.org, linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org, Dmitry Antipov Subject: [PATCH v7 2/3] lib: kunit: add tests for __ashldi3(), __ashrdi3(), and __lshrdi3() Date: Mon, 27 Apr 2026 12:01:04 +0300 Message-ID: <20260427090105.705529-3-dmantipov@yandex.ru> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260427090105.705529-1-dmantipov@yandex.ru> References: <20260427090105.705529-1-dmantipov@yandex.ru> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add KUnit tests for '__ashldi3()', '__ashrdi3()', and '__lshrdi3()' helper functions used to implement 64-bit arithmetic shift left, arithmetic shift right and logical shift right, respectively, on a 32-bit CPUs. Tested with 'qemu-system-riscv32 -M virt' and 'qemu-system-arm -M virt'. Reviewed-by: Andy Shevchenko Tested-by: Charlie Jenkins Signed-off-by: Dmitry Antipov --- v4 and upwards: bump version to match the series v3: more tests by Charlie Jenkins v2: include test-specific headers rather than generic linux/kernel.h --- lib/Kconfig.debug | 10 +++ lib/tests/Makefile | 1 + lib/tests/shdi3_kunit.c | 175 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 186 insertions(+) create mode 100644 lib/tests/shdi3_kunit.c diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index 8ff5adcfe1e0..ea036ebce64f 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -2971,6 +2971,16 @@ config BITS_TEST =20 If unsure, say N. =20 +config SHDI3_KUNIT_TEST + tristate "KUnit test for __ashldi3(), __ashrdi3(), and __lshrdi3()" + depends on KUNIT + depends on (32BIT || ARM) + help + This builds the unit test for __ashldi3(), __ashrdi3(), and + __lshrdi3() helper functions used to implement 64-bit arithmetic + shift left, arithmetic shift right and logical shift right, + respectively, on a 32-bit CPUs. + config SLUB_KUNIT_TEST tristate "KUnit test for SLUB cache error detection" if !KUNIT_ALL_TESTS depends on SLUB_DEBUG && KUNIT diff --git a/lib/tests/Makefile b/lib/tests/Makefile index 7e9c2fa52e35..4ead57602eac 100644 --- a/lib/tests/Makefile +++ b/lib/tests/Makefile @@ -8,6 +8,7 @@ obj-$(CONFIG_BASE64_KUNIT) +=3D base64_kunit.o obj-$(CONFIG_BITOPS_KUNIT) +=3D bitops_kunit.o obj-$(CONFIG_BITFIELD_KUNIT) +=3D bitfield_kunit.o obj-$(CONFIG_BITS_TEST) +=3D test_bits.o +obj-$(CONFIG_SHDI3_KUNIT_TEST) +=3D shdi3_kunit.o obj-$(CONFIG_BLACKHOLE_DEV_KUNIT_TEST) +=3D blackhole_dev_kunit.o obj-$(CONFIG_CHECKSUM_KUNIT) +=3D checksum_kunit.o obj-$(CONFIG_CMDLINE_KUNIT_TEST) +=3D cmdline_kunit.o diff --git a/lib/tests/shdi3_kunit.c b/lib/tests/shdi3_kunit.c new file mode 100644 index 000000000000..44f65e66512b --- /dev/null +++ b/lib/tests/shdi3_kunit.c @@ -0,0 +1,175 @@ +// SPDX-License-Identifier: GPL-2.0-or-later OR Apache-2.0 +/* + * Test cases for __ashldi3(), __ashrdi3(), and __lshrdi3(). + */ + +#include +#include +#include +#include + +struct shdi3_test_entry { + long long input; + int shift; + long long result; +}; + +static const struct shdi3_test_entry ashldi3_testdata[] =3D { + /* https://github.com/llvm/llvm-project/compiler-rt/test/builtins/Unit/as= hldi3_test.c */ + { 0x0123456789ABCDEFLL, 0, 0x123456789ABCDEFLL }, + { 0x0123456789ABCDEFLL, 1, 0x2468ACF13579BDELL }, + { 0x0123456789ABCDEFLL, 2, 0x48D159E26AF37BCLL }, + { 0x0123456789ABCDEFLL, 3, 0x91A2B3C4D5E6F78LL }, + { 0x0123456789ABCDEFLL, 4, 0x123456789ABCDEF0LL }, + { 0x0123456789ABCDEFLL, 28, 0x789ABCDEF0000000LL }, + { 0x0123456789ABCDEFLL, 29, 0xF13579BDE0000000LL }, + { 0x0123456789ABCDEFLL, 30, 0xE26AF37BC0000000LL }, + { 0x0123456789ABCDEFLL, 31, 0xC4D5E6F780000000LL }, + { 0x0123456789ABCDEFLL, 32, 0x89ABCDEF00000000LL }, + { 0x0123456789ABCDEFLL, 33, 0x13579BDE00000000LL }, + { 0x0123456789ABCDEFLL, 34, 0x26AF37BC00000000LL }, + { 0x0123456789ABCDEFLL, 35, 0x4D5E6F7800000000LL }, + { 0x0123456789ABCDEFLL, 36, 0x9ABCDEF000000000LL }, + { 0x0123456789ABCDEFLL, 60, 0xF000000000000000LL }, + { 0x0123456789ABCDEFLL, 61, 0xE000000000000000LL }, + { 0x0123456789ABCDEFLL, 62, 0xC000000000000000LL }, + { 0x0123456789ABCDEFLL, 63, 0x8000000000000000LL }, +}; + +static void shdi3_test_ashldi3(struct kunit *test) +{ + const struct shdi3_test_entry *e; + long long ret; + + for (e =3D ashldi3_testdata; + e < ashldi3_testdata + ARRAY_SIZE(ashldi3_testdata); e++) { + ret =3D __ashldi3(e->input, e->shift); + KUNIT_EXPECT_EQ_MSG(test, ret, e->result, + " when evaluating __ashldi3(%lld, %d)", + e->input, e->shift); + } +} + +static const struct shdi3_test_entry ashrdi3_testdata[] =3D { + /* https://github.com/llvm/llvm-project/compiler-rt/test/builtins/Unit/as= hrdi3_test.c */ + { 0x0123456789ABCDEFLL, 0, 0x123456789ABCDEFLL }, + { 0x0123456789ABCDEFLL, 1, 0x91A2B3C4D5E6F7LL }, + { 0x0123456789ABCDEFLL, 2, 0x48D159E26AF37BLL }, + { 0x0123456789ABCDEFLL, 3, 0x2468ACF13579BDLL }, + { 0x0123456789ABCDEFLL, 4, 0x123456789ABCDELL }, + { 0x0123456789ABCDEFLL, 28, 0x12345678LL }, + { 0x0123456789ABCDEFLL, 29, 0x91A2B3CLL }, + { 0x0123456789ABCDEFLL, 30, 0x48D159ELL }, + { 0x0123456789ABCDEFLL, 31, 0x2468ACFLL }, + { 0x0123456789ABCDEFLL, 32, 0x1234567LL }, + { 0x0123456789ABCDEFLL, 33, 0x91A2B3LL }, + { 0x0123456789ABCDEFLL, 34, 0x48D159LL }, + { 0x0123456789ABCDEFLL, 35, 0x2468ACLL }, + { 0x0123456789ABCDEFLL, 36, 0x123456LL }, + { 0x0123456789ABCDEFLL, 60, 0 }, + { 0x0123456789ABCDEFLL, 61, 0 }, + { 0x0123456789ABCDEFLL, 62, 0 }, + { 0x0123456789ABCDEFLL, 63, 0 }, + { 0xFEDCBA9876543210LL, 0, 0xFEDCBA9876543210LL }, + { 0xFEDCBA9876543210LL, 1, 0xFF6E5D4C3B2A1908LL }, + { 0xFEDCBA9876543210LL, 2, 0xFFB72EA61D950C84LL }, + { 0xFEDCBA9876543210LL, 3, 0xFFDB97530ECA8642LL }, + { 0xFEDCBA9876543210LL, 4, 0xFFEDCBA987654321LL }, + { 0xFEDCBA9876543210LL, 28, 0xFFFFFFFFEDCBA987LL }, + { 0xFEDCBA9876543210LL, 29, 0xFFFFFFFFF6E5D4C3LL }, + { 0xFEDCBA9876543210LL, 30, 0xFFFFFFFFFB72EA61LL }, + { 0xFEDCBA9876543210LL, 31, 0xFFFFFFFFFDB97530LL }, + { 0xFEDCBA9876543210LL, 32, 0xFFFFFFFFFEDCBA98LL }, + { 0xFEDCBA9876543210LL, 33, 0xFFFFFFFFFF6E5D4CLL }, + { 0xFEDCBA9876543210LL, 34, 0xFFFFFFFFFFB72EA6LL }, + { 0xFEDCBA9876543210LL, 35, 0xFFFFFFFFFFDB9753LL }, + { 0xFEDCBA9876543210LL, 36, 0xFFFFFFFFFFEDCBA9LL }, + { 0xAEDCBA9876543210LL, 60, 0xFFFFFFFFFFFFFFFALL }, + { 0xAEDCBA9876543210LL, 61, 0xFFFFFFFFFFFFFFFDLL }, + { 0xAEDCBA9876543210LL, 62, 0xFFFFFFFFFFFFFFFELL }, + { 0xAEDCBA9876543210LL, 63, 0xFFFFFFFFFFFFFFFFLL }, +}; + +static void shdi3_test_ashrdi3(struct kunit *test) +{ + const struct shdi3_test_entry *e; + long long ret; + + for (e =3D ashrdi3_testdata; + e < ashrdi3_testdata + ARRAY_SIZE(ashrdi3_testdata); e++) { + ret =3D __ashrdi3(e->input, e->shift); + KUNIT_EXPECT_EQ_MSG(test, ret, e->result, + " when evaluating __ashrdi3(%lld, %d)", + e->input, e->shift); + } +} + +static const struct shdi3_test_entry lshrdi3_testdata[] =3D { + /* https://github.com/llvm/llvm-project/compiler-rt/test/builtins/Unit/ls= hrdi3_test.c */ + { 0x0123456789ABCDEFLL, 0, 0x123456789ABCDEFLL }, + { 0x0123456789ABCDEFLL, 1, 0x91A2B3C4D5E6F7LL }, + { 0x0123456789ABCDEFLL, 2, 0x48D159E26AF37BLL }, + { 0x0123456789ABCDEFLL, 3, 0x2468ACF13579BDLL }, + { 0x0123456789ABCDEFLL, 4, 0x123456789ABCDELL }, + { 0x0123456789ABCDEFLL, 28, 0x12345678LL }, + { 0x0123456789ABCDEFLL, 29, 0x91A2B3CLL }, + { 0x0123456789ABCDEFLL, 30, 0x48D159ELL }, + { 0x0123456789ABCDEFLL, 31, 0x2468ACFLL }, + { 0x0123456789ABCDEFLL, 32, 0x1234567LL }, + { 0x0123456789ABCDEFLL, 33, 0x91A2B3LL }, + { 0x0123456789ABCDEFLL, 34, 0x48D159LL }, + { 0x0123456789ABCDEFLL, 35, 0x2468ACLL }, + { 0x0123456789ABCDEFLL, 36, 0x123456LL }, + { 0x0123456789ABCDEFLL, 60, 0 }, + { 0x0123456789ABCDEFLL, 61, 0 }, + { 0x0123456789ABCDEFLL, 62, 0 }, + { 0x0123456789ABCDEFLL, 63, 0 }, + { 0xFEDCBA9876543210LL, 0, 0xFEDCBA9876543210LL }, + { 0xFEDCBA9876543210LL, 1, 0x7F6E5D4C3B2A1908LL }, + { 0xFEDCBA9876543210LL, 2, 0x3FB72EA61D950C84LL }, + { 0xFEDCBA9876543210LL, 3, 0x1FDB97530ECA8642LL }, + { 0xFEDCBA9876543210LL, 4, 0xFEDCBA987654321LL }, + { 0xFEDCBA9876543210LL, 28, 0xFEDCBA987LL }, + { 0xFEDCBA9876543210LL, 29, 0x7F6E5D4C3LL }, + { 0xFEDCBA9876543210LL, 30, 0x3FB72EA61LL }, + { 0xFEDCBA9876543210LL, 31, 0x1FDB97530LL }, + { 0xFEDCBA9876543210LL, 32, 0xFEDCBA98LL }, + { 0xFEDCBA9876543210LL, 33, 0x7F6E5D4CLL }, + { 0xFEDCBA9876543210LL, 34, 0x3FB72EA6LL }, + { 0xFEDCBA9876543210LL, 35, 0x1FDB9753LL }, + { 0xFEDCBA9876543210LL, 36, 0xFEDCBA9LL }, + { 0xAEDCBA9876543210LL, 60, 0xALL }, + { 0xAEDCBA9876543210LL, 61, 0x5LL }, + { 0xAEDCBA9876543210LL, 62, 0x2LL }, + { 0xAEDCBA9876543210LL, 63, 0x1LL }, +}; + +static void shdi3_test_lshrdi3(struct kunit *test) +{ + const struct shdi3_test_entry *e; + long long ret; + + for (e =3D lshrdi3_testdata; + e < lshrdi3_testdata + ARRAY_SIZE(lshrdi3_testdata); e++) { + ret =3D __lshrdi3(e->input, e->shift); + KUNIT_EXPECT_EQ_MSG(test, ret, e->result, + " when evaluating __lshrdi3(%lld, %d)", + e->input, e->shift); + } +} + +static struct kunit_case shdi3_test_cases[] =3D { + KUNIT_CASE(shdi3_test_ashldi3), + KUNIT_CASE(shdi3_test_ashrdi3), + KUNIT_CASE(shdi3_test_lshrdi3), + {} +}; + +static struct kunit_suite shdi3_test_suite =3D { + .name =3D "shdi3", + .test_cases =3D shdi3_test_cases, +}; +kunit_test_suite(shdi3_test_suite); + +MODULE_DESCRIPTION("Test cases for __ashldi3(), __ashrdi3(), and __lshrdi3= ()"); +MODULE_LICENSE("GPL"); --=20 2.53.0 From nobody Wed Jun 17 07:37:14 2026 Received: from forward202d.mail.yandex.net (forward202d.mail.yandex.net [178.154.239.219]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0AD8A3AF64D; Mon, 27 Apr 2026 09:09:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.154.239.219 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777280998; cv=none; b=Ezpxd7xrau9I3CqY1yRus+NkIlMf9eq2/i0wLoBP4xSt7KCO9xrDDkGCRCwywnF2g85X+BiHYCYv8tsEzFeBOCFP9VQNqnuGEJgo7wA+2GCwzkxntq3y975ji7eja1C2WuFKdkowaCnOa0SE6qxlPGj8a44nu+V7ngDpNpp/z4g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777280998; c=relaxed/simple; bh=YLXj5AmJ/++5CzxtvSLMRJMWqiR/5JVn6r6MI/gWdxk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ajfWNhD3kfndTd0e3GwX5mcCQgxuhNOiFRwBu7LtDy7sj8HbnFcgbb/bg5Fw3860Ufq6jFbRnshC+tKEM60wi8H+H++7FW7g6EIRgfoNqJMqVd4X2HWd6QDkdRLhk9xmN27+CneQyLuD2V+4l//kngUe643kAwmBcXdjXlsT6ps= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=yandex.ru; spf=pass smtp.mailfrom=yandex.ru; dkim=pass (1024-bit key) header.d=yandex.ru header.i=@yandex.ru header.b=UKkGAP0f; arc=none smtp.client-ip=178.154.239.219 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=yandex.ru Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=yandex.ru Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=yandex.ru header.i=@yandex.ru header.b="UKkGAP0f" Received: from forward100d.mail.yandex.net (forward100d.mail.yandex.net [IPv6:2a02:6b8:c41:1300:1:45:d181:d100]) by forward202d.mail.yandex.net (Yandex) with ESMTPS id C95D6854E8; Mon, 27 Apr 2026 12:01:47 +0300 (MSK) Received: from mail-nwsmtp-smtp-production-main-52.klg.yp-c.yandex.net (mail-nwsmtp-smtp-production-main-52.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:ea2:0:640:ef77:0]) by forward100d.mail.yandex.net (Yandex) with ESMTPS id 6118DC0081; Mon, 27 Apr 2026 12:01:40 +0300 (MSK) Received: by mail-nwsmtp-smtp-production-main-52.klg.yp-c.yandex.net (smtp) with ESMTPSA id X1UMu7lR5a60-Xb9gGYSr; Mon, 27 Apr 2026 12:01:39 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1777280499; bh=Ff9SdFCbk25ZtmQGhp1frc27zJiUuk0lebZaoptedLo=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=UKkGAP0fCWCVBGHrvOWdDvj4Yjc1QQ9vPO+PzzayQEI4EuTz8WfZbAp4U0hZlycHt xTmfrZCxlJcpus3bZ+CKkSmiznOZ4N2c5GJby7nZS42WD3dnO+4c73y2I9oRE/ZPF8 R0qLFHbjZ71gB644M+cWVNJsQJc/8A9PuufW+jQw= Authentication-Results: mail-nwsmtp-smtp-production-main-52.klg.yp-c.yandex.net; dkim=pass header.i=@yandex.ru From: Dmitry Antipov To: Paul Walmsley , Palmer Dabbelt , Albert Ou Cc: Andrew Morton , Andy Shevchenko , Charlie Jenkins , Alexandre Ghiti , Ard Biesheuvel , linux-riscv@lists.infradead.org, linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org, Dmitry Antipov Subject: [PATCH v7 3/3] riscv: fix building compressed EFI image Date: Mon, 27 Apr 2026 12:01:05 +0300 Message-ID: <20260427090105.705529-4-dmantipov@yandex.ru> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260427090105.705529-1-dmantipov@yandex.ru> References: <20260427090105.705529-1-dmantipov@yandex.ru> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When building vmlinuz.efi with CONFIG_EFI_ZBOOT enabled, '__lshrdi3()' is also needed to fix yet another link error: riscv32-linux-gnu-ld: drivers/firmware/efi/libstub/lib-cmdline.stub.o: in f= unction `__efistub_.L49': __efistub_cmdline.c:(.init.text+0x202): undefined reference to `__efistub__= _lshrdi3' And since riscv64 can have CONFIG_EFI_ZBOOT but doesn't need these library routines, rely on CONFIG_32BIT to manage linking of lib-ashldi3.o and lib-lshrdi3.o on riscv32 only. Reported-by: Charlie Jenkins Closes: https://lore.kernel.org/linux-riscv/20260409050018.GA371560@inky.lo= caldomain Tested-by: Charlie Jenkins Suggested-by: Ard Biesheuvel Assisted-by: gemini/gemini-3.1-pro-preview sashiko Signed-off-by: Dmitry Antipov --- v7: use lib-clz_ctz.o exactly once (Sashiko) v6: adjust to match recent upstream changes v5: rely on CONFIG_32BIT rather than dedicated Kconfig symbol (Ard) v4: use more meaningful CONFIG_EFI_ZBOOT_USE_LIBGCC and adjust tags (Andy) v3: initial version to join the series --- drivers/firmware/efi/libstub/Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/firmware/efi/libstub/Makefile b/drivers/firmware/efi/l= ibstub/Makefile index 983a438e35f3..7fc654e99305 100644 --- a/drivers/firmware/efi/libstub/Makefile +++ b/drivers/firmware/efi/libstub/Makefile @@ -95,7 +95,8 @@ CFLAGS_zboot-decompress-gzip.o +=3D -I$(srctree)/lib/zlib= _inflate zboot-obj-$(CONFIG_KERNEL_ZSTD) :=3D zboot-decompress-zstd.o lib-xxhash.o CFLAGS_zboot-decompress-zstd.o +=3D -I$(srctree)/lib/zstd =20 -zboot-obj-$(CONFIG_RISCV) +=3D lib-clz_ctz.o lib-ashldi3.o +zboot-riscv-obj-$(CONFIG_32BIT) +=3D lib-ashldi3.o lib-lshrdi3.o +zboot-obj-$(CONFIG_RISCV) +=3D lib-clz_ctz.o $(zboot-riscv-obj-y) zboot-obj-$(CONFIG_LOONGARCH) +=3D lib-clz_ctz.o lib-ashldi3.o lib-$(CONFIG_EFI_ZBOOT) +=3D zboot.o $(zboot-obj-y) =20 --=20 2.53.0