[3/8] scripts/mksysmap: use sed with in-line comments

Message ID 20230308115243.82592-3-masahiroy@kernel.org
State New
Headers
Series [1/8] scripts/kallsyms: remove redundant code for omitting U and N |

Commit Message

Masahiro Yamada March 8, 2023, 11:52 a.m. UTC
  Move comments close to the code.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 scripts/mksysmap | 61 +++++++++++++++++++++++++++++-------------------
 1 file changed, 37 insertions(+), 24 deletions(-)
  

Comments

Nick Desaulniers April 7, 2023, 6:59 p.m. UTC | #1
On Wed, Mar 8, 2023 at 3:53 AM Masahiro Yamada <masahiroy@kernel.org> wrote:
>
> Move comments close to the code.

Consider adding to the commit message why you switch from grep to sed;
that's currently unclear.
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>

Orthogonal to this patch, don't .L prefixed local symbols not have
entries in the symbol table? If they're not printed with nm, why
filter them out (since they're impossible).

>
> Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
> ---
>
>  scripts/mksysmap | 61 +++++++++++++++++++++++++++++-------------------
>  1 file changed, 37 insertions(+), 24 deletions(-)
>
> diff --git a/scripts/mksysmap b/scripts/mksysmap
> index 697fc6653953..8ea1955e03c6 100755
> --- a/scripts/mksysmap
> +++ b/scripts/mksysmap
> @@ -10,32 +10,45 @@
>  #####
>  # Generate System.map (actual filename passed as second argument)
>
> -# For System.map filter away:
> -#   a - local absolute symbols
> -#   U - undefined global symbols
> -#   N - debugging symbols
> -#   w - local weak symbols
> -
>  # readprofile starts reading symbols when _stext is found, and
>  # continue until it finds a symbol which is not either of 'T', 't',
>  # 'W' or 'w'.
>  #
> -# Ignored prefixes:
> -#  $                    - local symbols for ARM, MIPS, etc.
> -#  .L                   - local labels, .LBB,.Ltmpxxx,.L__unnamed_xx,.LASANPC, etc.
> -#  __crc_               - modversions
> -#  __kstrtab_           - EXPORT_SYMBOL (symbol name)
> -#  __kstrtabns_         - EXPORT_SYMBOL (namespace)
> +
> +${NM} -n ${1} | sed >${2} -e "
> +# ---------------------------------------------------------------------------
> +# Ignored symbol types
>  #
> -# Ignored symbols:
> -#  L0                   - for LoongArch?
> -
> -$NM -n $1 | grep -v            \
> -       -e ' [aNUw] '           \
> -       -e ' \$'                \
> -       -e ' \.L'               \
> -       -e ' __crc_'            \
> -       -e ' __kstrtab_'        \
> -       -e ' __kstrtabns_'      \
> -       -e ' L0$'               \
> -> $2
> +
> +# a: local absolute symbols
> +# N: debugging symbols
> +# U: undefined global symbols
> +# w: local weak symbols
> +/ [aNUw] /d
> +
> +# ---------------------------------------------------------------------------
> +# Ignored prefixes
> +#  (do not forget a space before each pattern)
> +
> +# local symbols for ARM, MIPS, etc.
> +/ \$/d
> +
> +# local labels, .LBB, .Ltmpxxx, .L__unnamed_xx, .LASANPC, etc.
> +/ \.L/d
> +
> +# CRC from modversions
> +/ __crc_/d
> +
> +# EXPORT_SYMBOL (symbol name)
> +/ __kstrtab_/d
> +
> +# EXPORT_SYMBOL (namespace)
> +/ __kstrtabns_/d
> +
> +# ---------------------------------------------------------------------------
> +# Ignored symbols (exact match)
> +#  (do not forget a space before and '$' after each pattern)
> +
> +# for LoongArch?
> +/ L0$/d
> +"
> --
> 2.34.1
>
  
Nick Desaulniers April 7, 2023, 7:01 p.m. UTC | #2
On Fri, Apr 7, 2023 at 11:59 AM Nick Desaulniers
<ndesaulniers@google.com> wrote:
>
> On Wed, Mar 8, 2023 at 3:53 AM Masahiro Yamada <masahiroy@kernel.org> wrote:
> >
> > Move comments close to the code.
>
> Consider adding to the commit message why you switch from grep to sed;
> that's currently unclear.
> Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>

Also, perhaps scripts/mksysmap could just be replaced with a sed
input-file? Then
scripts/link-vmlinux.sh would invoke nm and pipe it into that sed script?

>
> Orthogonal to this patch, don't .L prefixed local symbols not have
> entries in the symbol table? If they're not printed with nm, why
> filter them out (since they're impossible).
>
> >
> > Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
> > ---
> >
> >  scripts/mksysmap | 61 +++++++++++++++++++++++++++++-------------------
> >  1 file changed, 37 insertions(+), 24 deletions(-)
> >
> > diff --git a/scripts/mksysmap b/scripts/mksysmap
> > index 697fc6653953..8ea1955e03c6 100755
> > --- a/scripts/mksysmap
> > +++ b/scripts/mksysmap
> > @@ -10,32 +10,45 @@
> >  #####
> >  # Generate System.map (actual filename passed as second argument)
> >
> > -# For System.map filter away:
> > -#   a - local absolute symbols
> > -#   U - undefined global symbols
> > -#   N - debugging symbols
> > -#   w - local weak symbols
> > -
> >  # readprofile starts reading symbols when _stext is found, and
> >  # continue until it finds a symbol which is not either of 'T', 't',
> >  # 'W' or 'w'.
> >  #
> > -# Ignored prefixes:
> > -#  $                    - local symbols for ARM, MIPS, etc.
> > -#  .L                   - local labels, .LBB,.Ltmpxxx,.L__unnamed_xx,.LASANPC, etc.
> > -#  __crc_               - modversions
> > -#  __kstrtab_           - EXPORT_SYMBOL (symbol name)
> > -#  __kstrtabns_         - EXPORT_SYMBOL (namespace)
> > +
> > +${NM} -n ${1} | sed >${2} -e "
> > +# ---------------------------------------------------------------------------
> > +# Ignored symbol types
> >  #
> > -# Ignored symbols:
> > -#  L0                   - for LoongArch?
> > -
> > -$NM -n $1 | grep -v            \
> > -       -e ' [aNUw] '           \
> > -       -e ' \$'                \
> > -       -e ' \.L'               \
> > -       -e ' __crc_'            \
> > -       -e ' __kstrtab_'        \
> > -       -e ' __kstrtabns_'      \
> > -       -e ' L0$'               \
> > -> $2
> > +
> > +# a: local absolute symbols
> > +# N: debugging symbols
> > +# U: undefined global symbols
> > +# w: local weak symbols
> > +/ [aNUw] /d
> > +
> > +# ---------------------------------------------------------------------------
> > +# Ignored prefixes
> > +#  (do not forget a space before each pattern)
> > +
> > +# local symbols for ARM, MIPS, etc.
> > +/ \$/d
> > +
> > +# local labels, .LBB, .Ltmpxxx, .L__unnamed_xx, .LASANPC, etc.
> > +/ \.L/d
> > +
> > +# CRC from modversions
> > +/ __crc_/d
> > +
> > +# EXPORT_SYMBOL (symbol name)
> > +/ __kstrtab_/d
> > +
> > +# EXPORT_SYMBOL (namespace)
> > +/ __kstrtabns_/d
> > +
> > +# ---------------------------------------------------------------------------
> > +# Ignored symbols (exact match)
> > +#  (do not forget a space before and '$' after each pattern)
> > +
> > +# for LoongArch?
> > +/ L0$/d
> > +"
> > --
> > 2.34.1
> >
>
>
> --
> Thanks,
> ~Nick Desaulniers
  
Masahiro Yamada April 8, 2023, 2:29 p.m. UTC | #3
On Sat, Apr 8, 2023 at 4:00 AM Nick Desaulniers <ndesaulniers@google.com> wrote:
>
> On Wed, Mar 8, 2023 at 3:53 AM Masahiro Yamada <masahiroy@kernel.org> wrote:
> >
> > Move comments close to the code.
>
> Consider adding to the commit message why you switch from grep to sed;
> that's currently unclear.



I just thought "Move comments close to the code"
explained my motivation.,


I want to insert in-line comments.
Something like the following.
Apparently, it does not work.


$NM -n $1 | grep -v             \
         # comment1
        -e ' [aNUw] '           \
         # comment2
        -e ' \$'                \
         # comment3
        -e ' \.L'               \
         # comment4
        -e ' __crc_'            \
         # comment5
        -e ' __kstrtab_'        \
         # comment6
        -e ' __kstrtabns_'      \
         # comment7
        -e ' L0$'               \
> $2






> Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
>
> Orthogonal to this patch, don't .L prefixed local symbols not have
> entries in the symbol table? If they're not printed with nm, why
> filter them out (since they're impossible).


Sorry, I could not understand your question, but
you may get something from d4c858643263cfde13f7d937eaff95c2ed87cdf1
(you reviewed it)
  
Masahiro Yamada April 8, 2023, 3:01 p.m. UTC | #4
On Sat, Apr 8, 2023 at 4:01 AM Nick Desaulniers <ndesaulniers@google.com> wrote:
>
> On Fri, Apr 7, 2023 at 11:59 AM Nick Desaulniers
> <ndesaulniers@google.com> wrote:
> >
> > On Wed, Mar 8, 2023 at 3:53 AM Masahiro Yamada <masahiroy@kernel.org> wrote:
> > >
> > > Move comments close to the code.
> >
> > Consider adding to the commit message why you switch from grep to sed;
> > that's currently unclear.
> > Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
>
> Also, perhaps scripts/mksysmap could just be replaced with a sed
> input-file? Then
> scripts/link-vmlinux.sh would invoke nm and pipe it into that sed script?



I still need shell.


The last line of the next commit 4/8 uses
shell code.
  
Masahiro Yamada April 10, 2023, 9:38 a.m. UTC | #5
On Sat, Apr 8, 2023 at 11:29 PM Masahiro Yamada <masahiroy@kernel.org> wrote:
>
> On Sat, Apr 8, 2023 at 4:00 AM Nick Desaulniers <ndesaulniers@google.com> wrote:
> >
> > On Wed, Mar 8, 2023 at 3:53 AM Masahiro Yamada <masahiroy@kernel.org> wrote:
> > >
> > > Move comments close to the code.
> >
> > Consider adding to the commit message why you switch from grep to sed;
> > that's currently unclear.
>
>
>
> I just thought "Move comments close to the code"
> explained my motivation.,
>
>
> I want to insert in-line comments.
> Something like the following.
> Apparently, it does not work.
>
>
> $NM -n $1 | grep -v             \
>          # comment1
>         -e ' [aNUw] '           \
>          # comment2
>         -e ' \$'                \
>          # comment3
>         -e ' \.L'               \
>          # comment4
>         -e ' __crc_'            \
>          # comment5
>         -e ' __kstrtab_'        \
>          # comment6
>         -e ' __kstrtabns_'      \
>          # comment7
>         -e ' L0$'               \
> > $2
>
>
>

Anyway, I will rephase the commit description.

"""
It is not feasible to insert comments in a multi-line shell command.
Use sed, and move comments close to the code.
"""



--
Best Regards
Masahiro Yamada
  

Patch

diff --git a/scripts/mksysmap b/scripts/mksysmap
index 697fc6653953..8ea1955e03c6 100755
--- a/scripts/mksysmap
+++ b/scripts/mksysmap
@@ -10,32 +10,45 @@ 
 #####
 # Generate System.map (actual filename passed as second argument)
 
-# For System.map filter away:
-#   a - local absolute symbols
-#   U - undefined global symbols
-#   N - debugging symbols
-#   w - local weak symbols
-
 # readprofile starts reading symbols when _stext is found, and
 # continue until it finds a symbol which is not either of 'T', 't',
 # 'W' or 'w'.
 #
-# Ignored prefixes:
-#  $                    - local symbols for ARM, MIPS, etc.
-#  .L                   - local labels, .LBB,.Ltmpxxx,.L__unnamed_xx,.LASANPC, etc.
-#  __crc_               - modversions
-#  __kstrtab_           - EXPORT_SYMBOL (symbol name)
-#  __kstrtabns_         - EXPORT_SYMBOL (namespace)
+
+${NM} -n ${1} | sed >${2} -e "
+# ---------------------------------------------------------------------------
+# Ignored symbol types
 #
-# Ignored symbols:
-#  L0                   - for LoongArch?
-
-$NM -n $1 | grep -v		\
-	-e ' [aNUw] '		\
-	-e ' \$'		\
-	-e ' \.L'		\
-	-e ' __crc_'		\
-	-e ' __kstrtab_'	\
-	-e ' __kstrtabns_'	\
-	-e ' L0$'		\
-> $2
+
+# a: local absolute symbols
+# N: debugging symbols
+# U: undefined global symbols
+# w: local weak symbols
+/ [aNUw] /d
+
+# ---------------------------------------------------------------------------
+# Ignored prefixes
+#  (do not forget a space before each pattern)
+
+# local symbols for ARM, MIPS, etc.
+/ \$/d
+
+# local labels, .LBB, .Ltmpxxx, .L__unnamed_xx, .LASANPC, etc.
+/ \.L/d
+
+# CRC from modversions
+/ __crc_/d
+
+# EXPORT_SYMBOL (symbol name)
+/ __kstrtab_/d
+
+# EXPORT_SYMBOL (namespace)
+/ __kstrtabns_/d
+
+# ---------------------------------------------------------------------------
+# Ignored symbols (exact match)
+#  (do not forget a space before and '$' after each pattern)
+
+# for LoongArch?
+/ L0$/d
+"