The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: "Wentao Guan" <guanwentao@uniontech.com>
To: "Nathan Chancellor" <nathan@kernel.org>
Cc: nsc <nsc@kernel.org>, tamird <tamird@kernel.org>,
	linux-kbuild <linux-kbuild@vger.kernel.org>,
	linux-kernel <linux-kernel@vger.kernel.org>,
	"Petr Pavlu" <petr.pavlu@suse.com>
Subject: Re: [PATCH] kbuild: try readelf first in gen_symversions
Date: Thu, 4 Jun 2026 11:44:29 +0800	[thread overview]
Message-ID: <tencent_5A209D3D5BB5B16325067261@qq.com> (raw)
In-Reply-To: <20260604013858.GB1329739@ax162>

Hello,

> On Thu, Jun 04, 2026 at 12:17:32AM +0800, Wentao Guan wrote:
> > Use readelf to dig out if <file>.o contain a __export_symbol_*.
> >
> > Instead of nm, readelf is more faster, and significantly improve speed
> > when enable CONFIG_MODVERSIONS.
> >
> > Build x86_64_defconfigs in 2C4T cloud server with CONFIG_MODVERSIONS=y:
> > With patch:
> > real    17m21.019s
> > user    61m48.388s
> > sys     4m27.709s
> > Without patch:
> > real    17m39.435s
> > user    62m24.686s
> > sys     5m3.200s
> >
> > Link: https://lore.kernel.org/all/tencent_2FA16E0A18D6D0C0703F5D49@qq.com/
> > Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
> > ---
> >  scripts/Makefile.build | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/scripts/Makefile.build b/scripts/Makefile.build
> > index 3498d25b15e85..54a91bc144cce 100644
> > --- a/scripts/Makefile.build
> > +++ b/scripts/Makefile.build
> > @@ -233,7 +233,7 @@ ifdef CONFIG_MODVERSIONS
> >  #   be compiled and linked to the kernel and/or modules.
> > 
> >  gen_symversions = \
> > - if $(NM) $@ 2>/dev/null | grep -q ' __export_symbol_'; then \
> > + if $(READELF) -sW $@ 2>/dev/null | grep -q ' __export_symbol_'; then \
> 
> This breaks modversioning for Clang LTO builds, as llvm-nm can read LLVM
> bitcode but llvm-readelf cannot, it expects strictly ELF.
Oh, is it worth to use the following logic to detect LLVM or LLVM-LTO or not ?
+ifeq ($(LLVM),)
+  SYM_CHECK = $(READELF) -sW
+else
+  SYM_CHECK = $(NM)
+endif 
 gen_symversions =								\
-	if $(NM) $@ 2>/dev/null | grep -q ' __export_symbol_'; then		\
+	if $(SYM_CHECK) $@ 2>/dev/null | grep -q ' __export_symbol_'; then	\

> Is there any performance gain with adding '-m1' to the grep command so
> that it stops looking for a match after the first export symbol is
> found?
Small, there are my test result in make x86_64_defconfig + enable CONFIG_MODVERSIONS:
1. readelf
if $(READELF) $@ 2>/dev/null | grep -q ' __export_symbol_';
real    10m44.359s
user    37m43.596s
sys     3m2.424s
2. nm
if $(NM) $@ 2>/dev/null | grep -q ' __export_symbol_';
real    11m8.008s
user    38m51.644s
sys     3m29.798s
3. nm + grep -m1 -q
if $(NM) $@ 2>/dev/null | grep -m1 -q ' __export_symbol_';
real    10m56.891s
user    38m8.136s
sys     3m28.096s

These test based on default gcc toolchain in ubuntu noble.
I will do more test which use llvm-nm and llvm-readelf.

BRs
Wentao Guan

  reply	other threads:[~2026-06-04  3:45 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-03 16:17 [PATCH] kbuild: try readelf first in gen_symversions Wentao Guan
2026-06-04  1:38 ` Nathan Chancellor
2026-06-04  3:44   ` Wentao Guan [this message]
2026-06-05  6:22     ` Nathan Chancellor
2026-06-05 11:03       ` Wentao Guan

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=tencent_5A209D3D5BB5B16325067261@qq.com \
    --to=guanwentao@uniontech.com \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nathan@kernel.org \
    --cc=nsc@kernel.org \
    --cc=petr.pavlu@suse.com \
    --cc=tamird@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