[PATCH] kbuild: Fix 'no symbols' warning when CONFIG_TRIM_UNUSD_KSYMS=y

2 views
Skip to first unread message

Masahiro Yamada

unread,
Aug 14, 2021, 7:41:38 PM8/14/21
to linux-...@vger.kernel.org, linux-...@vger.kernel.org, Masahiro Yamada, Nathan Chancellor, Nick Desaulniers, Nicolas Pitre, clang-bu...@googlegroups.com
When CONFIG_TRIM_UNUSED_KSYMS is enabled, I see some warnings like this:

nm: arch/x86/entry/vdso/vdso32/note.o: no symbols

$NM (both GNU nm and llvm-nm) warns when no symbol is found in the
object. Suppress the stderr.

Fixes: bbda5ec671d3 ("kbuild: simplify dependency generation for CONFIG_TRIM_UNUSED_KSYMS")
Signed-off-by: Masahiro Yamada <masa...@kernel.org>
---

scripts/gen_ksymdeps.sh | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/scripts/gen_ksymdeps.sh b/scripts/gen_ksymdeps.sh
index 1324986e1362..5493124e8ee6 100755
--- a/scripts/gen_ksymdeps.sh
+++ b/scripts/gen_ksymdeps.sh
@@ -4,7 +4,10 @@
set -e

# List of exported symbols
-ksyms=$($NM $1 | sed -n 's/.*__ksym_marker_\(.*\)/\1/p' | tr A-Z a-z)
+#
+# If the object has no symbol, $NM warns 'no symbols'.
+# Suppress the stdout.
+ksyms=$($NM $1 2>/dev/null | sed -n 's/.*__ksym_marker_\(.*\)/\1/p' | tr A-Z a-z)

if [ -z "$ksyms" ]; then
exit 0
--
2.30.2

Nathan Chancellor

unread,
Aug 14, 2021, 9:15:36 PM8/14/21
to Masahiro Yamada, linux-...@vger.kernel.org, linux-...@vger.kernel.org, Nick Desaulniers, Nicolas Pitre, clang-bu...@googlegroups.com
On 8/14/2021 4:41 PM, Masahiro Yamada wrote:
> When CONFIG_TRIM_UNUSED_KSYMS is enabled, I see some warnings like this:
>
> nm: arch/x86/entry/vdso/vdso32/note.o: no symbols
>
> $NM (both GNU nm and llvm-nm) warns when no symbol is found in the
> object. Suppress the stderr.
>
> Fixes: bbda5ec671d3 ("kbuild: simplify dependency generation for CONFIG_TRIM_UNUSED_KSYMS")
> Signed-off-by: Masahiro Yamada <masa...@kernel.org>

Reviewed-by: Nathan Chancellor <nat...@kernel.org>

Fāng-ruì Sòng

unread,
Aug 14, 2021, 11:18:43 PM8/14/21
to Masahiro Yamada, linux-...@vger.kernel.org, Nathan Chancellor, linux-...@vger.kernel.org, Nick Desaulniers, Nicolas Pitre, clang-bu...@googlegroups.com
On Sat, Aug 14, 2021 at 6:15 PM Nathan Chancellor <nat...@kernel.org> wrote:
>
> On 8/14/2021 4:41 PM, Masahiro Yamada wrote:
> > When CONFIG_TRIM_UNUSED_KSYMS is enabled, I see some warnings like this:
> >
> > nm: arch/x86/entry/vdso/vdso32/note.o: no symbols
> >
> > $NM (both GNU nm and llvm-nm) warns when no symbol is found in the
> > object. Suppress the stderr.
> >
> > Fixes: bbda5ec671d3 ("kbuild: simplify dependency generation for CONFIG_TRIM_UNUSED_KSYMS")
> > Signed-off-by: Masahiro Yamada <masa...@kernel.org>

LGTM.

FWIW binutils>=2.37 `nm -q` can be used to suppress "no symbols"
https://sourceware.org/bugzilla/show_bug.cgi?id=27408

llvm-nm>=13.0.0 supports -q as well.

> Reviewed-by: Nathan Chancellor <nat...@kernel.org>
>
> > ---
> >
> > scripts/gen_ksymdeps.sh | 5 ++++-
> > 1 file changed, 4 insertions(+), 1 deletion(-)
> >
> > diff --git a/scripts/gen_ksymdeps.sh b/scripts/gen_ksymdeps.sh
> > index 1324986e1362..5493124e8ee6 100755
> > --- a/scripts/gen_ksymdeps.sh
> > +++ b/scripts/gen_ksymdeps.sh
> > @@ -4,7 +4,10 @@
> > set -e
> >
> > # List of exported symbols
> > -ksyms=$($NM $1 | sed -n 's/.*__ksym_marker_\(.*\)/\1/p' | tr A-Z a-z)
> > +#
> > +# If the object has no symbol, $NM warns 'no symbols'.
> > +# Suppress the stdout.
> > +ksyms=$($NM $1 2>/dev/null | sed -n 's/.*__ksym_marker_\(.*\)/\1/p' | tr A-Z a-z)
> >
> > if [ -z "$ksyms" ]; then
> > exit 0
> >
>
> --
> You received this message because you are subscribed to the Google Groups "Clang Built Linux" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to clang-built-li...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/clang-built-linux/3afe5054-8129-fe42-b5a4-00bd091b1a0c%40kernel.org.



--
宋方睿

Nicolas Pitre

unread,
Aug 14, 2021, 11:37:15 PM8/14/21
to Masahiro Yamada, linux-...@vger.kernel.org, linux-...@vger.kernel.org, Nathan Chancellor, Nick Desaulniers, clang-bu...@googlegroups.com
You mean stderr.


Nicolas


Masahiro Yamada

unread,
Aug 18, 2021, 12:29:45 AM8/18/21
to Fāng-ruì Sòng, Linux Kbuild mailing list, Nathan Chancellor, Linux Kernel Mailing List, Nick Desaulniers, Nicolas Pitre, clang-built-linux
On Sun, Aug 15, 2021 at 12:18 PM Fāng-ruì Sòng <mas...@google.com> wrote:
>
> On Sat, Aug 14, 2021 at 6:15 PM Nathan Chancellor <nat...@kernel.org> wrote:
> >
> > On 8/14/2021 4:41 PM, Masahiro Yamada wrote:
> > > When CONFIG_TRIM_UNUSED_KSYMS is enabled, I see some warnings like this:
> > >
> > > nm: arch/x86/entry/vdso/vdso32/note.o: no symbols
> > >
> > > $NM (both GNU nm and llvm-nm) warns when no symbol is found in the
> > > object. Suppress the stderr.
> > >
> > > Fixes: bbda5ec671d3 ("kbuild: simplify dependency generation for CONFIG_TRIM_UNUSED_KSYMS")
> > > Signed-off-by: Masahiro Yamada <masa...@kernel.org>
>
> LGTM.
>
> FWIW binutils>=2.37 `nm -q` can be used to suppress "no symbols"
> https://sourceware.org/bugzilla/show_bug.cgi?id=27408
>
> llvm-nm>=13.0.0 supports -q as well.


Thanks for the info.
Perhaps, I can note the future migration to -q
in a comment.






--
Best Regards
Masahiro Yamada

Masahiro Yamada

unread,
Aug 18, 2021, 12:29:47 AM8/18/21
to Nicolas Pitre, Linux Kbuild mailing list, Linux Kernel Mailing List, Nathan Chancellor, Nick Desaulniers, clang-built-linux
My bad - I will fix it in v2.
Thanks.

Masahiro Yamada

unread,
Aug 18, 2021, 8:02:04 PM8/18/21
to linux-...@vger.kernel.org, linux-...@vger.kernel.org, Masahiro Yamada, Nathan Chancellor, Nick Desaulniers, Nicolas Pitre, clang-bu...@googlegroups.com
When CONFIG_TRIM_UNUSED_KSYMS is enabled, I see some warnings like this:

nm: arch/x86/entry/vdso/vdso32/note.o: no symbols

$NM (both GNU nm and llvm-nm) warns when no symbol is found in the
object. Suppress the stderr.

Fangrui Song mentioned binutils>=2.37 `nm -q` can be used to suppress
"no symbols" [1], and llvm-nm>=13.0.0 supports -q as well.

We cannot use it for now, but note it as a TODO.

[1]: https://sourceware.org/bugzilla/show_bug.cgi?id=27408

Fixes: bbda5ec671d3 ("kbuild: simplify dependency generation for CONFIG_TRIM_UNUSED_KSYMS")
Signed-off-by: Masahiro Yamada <masa...@kernel.org>
Reviewed-by: Nathan Chancellor <nat...@kernel.org>
---

Changes in v2:
- Add TODO
- Fix 'stdout' to 'stderr' in the comment

scripts/gen_ksymdeps.sh | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/scripts/gen_ksymdeps.sh b/scripts/gen_ksymdeps.sh
index 1324986e1362..725e8c9c1b53 100755
--- a/scripts/gen_ksymdeps.sh
+++ b/scripts/gen_ksymdeps.sh
@@ -4,7 +4,13 @@
set -e

# List of exported symbols
-ksyms=$($NM $1 | sed -n 's/.*__ksym_marker_\(.*\)/\1/p' | tr A-Z a-z)
+#
+# If the object has no symbol, $NM warns 'no symbols'.
+# Suppress the stderr.
+# TODO:
+# Use -q instead of 2>/dev/null when we upgrade the minimum version of
+# binutils to 2.37, llvm to 13.0.0.
+ksyms=$($NM $1 2>/dev/null | sed -n 's/.*__ksym_marker_\(.*\)/\1/p' | tr A-Z a-z)

if [ -z "$ksyms" ]; then
exit 0
--
2.30.2

Reply all
Reply to author
Forward
0 new messages