Re: [PATCH v2 0/3] lib: Add software mul/div helpers and use them from nios2
From: Arnd Bergmann
Date: Tue Nov 03 2026 - 12:36:19 EST
On Tue, Nov 3, 2026, at 14:30, Simon Schuster wrote:
> Recently, there have been linking failures on nios2 regarding libgcc
> symbols that we reexport to modules (in particular __mulsi3 [0], and
> __divsi3_table [1]).
>
> In the resulting discussion, Arnd suggested [2] dropping the libgcc
> dependency altogether, as -- while specific functions might be fine --
> libgcc does not expect to run in a kernel-like freestanding environment.
>
> To this end, Dinh Nguyen was kind enough to locate and extract
> GPLv2-compliant versions of the software mul/div/mod functions required
> by nios2 gcc and integrate them into the kernel. As Arnd also suggested
> [3] that these might be helpful to other smaller architectures (such as
> arc or openrisc), I've further extracted them to lib/ with corresponding
> CONFIG_GENERIC_LIB_* options that allow selectively enabling and
> exporting these as required.
>
Looks good to me. I'll wait for Vineet to comment, as he wants to
use these on ARC as well, but plan to merge these in the asm-generic
tree for 7.5 then. I also tried the patch below on top of your
series to make openrisc build without libgcc, which worked.
I tried the same on parisc but failed because that one needs
several extra libgcc files.
I would have added the __divsi3_table symbol to lib/ as well for
consistency, but there is no difference in practice as other
architectures don't use this, so I don't mind.
> Furthermore -Wno-attribute-alias -Wno-missing-prototypes
> -Wno-missing-declarations and -Wno-unused-function were required due
> to unrelated Werror-related compilation issues, but as this series
> concerns compiler intrinsics that are never explicitly referenced
> in code and it links fine this seems acceptable to me
It's certainly worth fixing these properly rather than turning them
off, but I agree that is clearly unrelated. For most of these it
should be sufficient to either mark functions as 'static' where
possible, or include the correct headers, and both of these are
generally good ideas anyway.
Arnd
diff --git a/arch/openrisc/Kconfig b/arch/openrisc/Kconfig
index 6aaedc67a5e0..5be29befd86c 100644
--- a/arch/openrisc/Kconfig
+++ b/arch/openrisc/Kconfig
@@ -22,6 +22,16 @@ config OPENRISC
select GENERIC_IRQ_CHIP
select GENERIC_IRQ_PROBE
select GENERIC_IRQ_SHOW
+ select GENERIC_LIB_LSHRDI3
+ select GENERIC_LIB_ASHLDI3
+ select GENERIC_LIB_ASHRDI3
+ select GENERIC_LIB_MULDI3
+ select GENERIC_LIB_UCMPDI2
+ select GENERIC_LIB_DIVSI3
+ select GENERIC_LIB_MODSI3
+ select GENERIC_LIB_UDIVSI3
+ select GENERIC_LIB_UMODSI3
+ select GENERIC_LIB_MULSI3
select GENERIC_PCI_IOMAP
select GENERIC_IOREMAP
select GENERIC_CPU_DEVICES
diff --git a/arch/openrisc/Makefile b/arch/openrisc/Makefile
index 68249521db5a..38dc87bc6a3a 100644
--- a/arch/openrisc/Makefile
+++ b/arch/openrisc/Makefile
@@ -18,7 +18,6 @@
KBUILD_DEFCONFIG := or1ksim_defconfig
OBJCOPYFLAGS := -O binary -R .note -R .comment -S
-LIBGCC := $(shell $(CC) $(KBUILD_CFLAGS) -print-libgcc-file-name)
KBUILD_CFLAGS += -pipe -ffixed-r10 -D__linux__
KBUILD_CFLAGS += -msfimm -mshftimm
@@ -55,8 +54,6 @@ ifeq ($(CONFIG_OPENRISC_HAVE_INST_SEXT),y)
KBUILD_CFLAGS += $(call cc-option,-msext)
endif
-libs-y += $(LIBGCC)
-
PHONY += vmlinux.bin
vmlinux.bin: vmlinux
diff --git a/arch/openrisc/kernel/or32_ksyms.c b/arch/openrisc/kernel/or32_ksyms.c
index 84a937a64e2a..7ae38030a9d4 100644
--- a/arch/openrisc/kernel/or32_ksyms.c
+++ b/arch/openrisc/kernel/or32_ksyms.c
@@ -27,19 +27,6 @@
#include <asm/hardirq.h>
#include <asm/delay.h>
-#define DECLARE_EXPORT(name) extern void name(void); EXPORT_SYMBOL(name)
-
-/* compiler generated symbols */
-DECLARE_EXPORT(__udivsi3);
-DECLARE_EXPORT(__divsi3);
-DECLARE_EXPORT(__umodsi3);
-DECLARE_EXPORT(__modsi3);
-DECLARE_EXPORT(__muldi3);
-DECLARE_EXPORT(__ashrdi3);
-DECLARE_EXPORT(__ashldi3);
-DECLARE_EXPORT(__lshrdi3);
-DECLARE_EXPORT(__ucmpdi2);
-
EXPORT_SYMBOL(__copy_tofrom_user);
EXPORT_SYMBOL(__clear_user);
EXPORT_SYMBOL(memset);