mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Arnd Bergmann" <arnd@arndb.de>
To: "schuster.simon@siemens-energy.com"
	<schuster.simon@siemens-energy.com>,
	"Dinh Nguyen" <dinguyen@kernel.org>,
	"Andrew Morton" <akpm@linux-foundation.org>
Cc: "Sasha Levin" <sashal@kernel.org>,
	linux-kernel@vger.kernel.org, "Vineet Gupta" <vgupta@kernel.org>,
	"Jonas Bonn" <jonas@southpole.se>,
	"Stefan Kristiansson" <stefan.kristiansson@saunalahti.fi>,
	"Stafford Horne" <shorne@gmail.com>,
	linux-openrisc@vger.kernel.org
Subject: Re: [PATCH v2 0/3] lib: Add software mul/div helpers and use them from nios2
Date: Tue, 03 Nov 2026 16:40:44 +0100	[thread overview]
Message-ID: <b289ed06-4d9a-434b-b3db-b7e38dadbb58@app.fastmail.com> (raw)
In-Reply-To: <20261103-nios2-remove-usage-of-libgcc-v2-0-5fabbedc49ec@siemens-energy.com>

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);

      parent reply	other threads:[~2026-11-03 15:41 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-03 13:30 Simon Schuster
2026-11-03 13:30 ` [PATCH v2 1/3] lib: extract 32bit mul/div helpers from nios2 into GENERIC_LIB Simon Schuster
2026-11-03 13:30 ` [PATCH v2 2/3] nios2: export __divsi3_table Simon Schuster
2026-11-03 13:30 ` [PATCH v2 3/3] nios2: Drop usage of libgcc in favour of GENERIC_LIB_* Simon Schuster
2026-11-03 15:40 ` Arnd Bergmann [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b289ed06-4d9a-434b-b3db-b7e38dadbb58@app.fastmail.com \
    --to=arnd@arndb.de \
    --cc=akpm@linux-foundation.org \
    --cc=dinguyen@kernel.org \
    --cc=jonas@southpole.se \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-openrisc@vger.kernel.org \
    --cc=sashal@kernel.org \
    --cc=schuster.simon@siemens-energy.com \
    --cc=shorne@gmail.com \
    --cc=stefan.kristiansson@saunalahti.fi \
    --cc=vgupta@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®