Bug 27487 - nm: Add --just-symbol-name
Summary: nm: Add --just-symbol-name
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: Nick Clifton
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-02-28 20:50 UTC by Fangrui Song
Modified: 2021-03-15 10:57 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed: 2021-03-12 00:00:00


Attachments
Proposed patch (3.07 KB, patch)
2021-03-12 15:50 UTC, Nick Clifton
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Fangrui Song 2021-02-28 20:50:37 UTC
llvm-nm supports --just-symbol-name which omits the address and the symbol key.

% llvm-nm -D --just-symbol-name =cat
_ITM_deregisterTMCloneTable
_ITM_registerTMCloneTable
__ctype_b_loc@GLIBC_2.3
__ctype_get_mb_cur_max@GLIBC_2.2.5
__cxa_atexit@GLIBC_2.2.5
__cxa_finalize@GLIBC_2.2.5
__errno_location@GLIBC_2.2.5
...

% llvm-nm --just-symbol-name a.o 
__llvm_profile_filename
__llvm_profile_raw_version
__profd_foo
__profd_main
foo
main
puts

Without the option, the user can pipe the output to cut

% nm a.o | cut -c20-

20 needs to be tuned for ELFCLASS32.
Comment 1 Nick Clifton 2021-03-12 15:50:08 UTC
Created attachment 13305 [details]
Proposed patch
Comment 2 Nick Clifton 2021-03-12 15:51:19 UTC
Hi Fangrui,

  To me this option sounds like a new output format.  So please take a
  look at the attached patch which adds --format=just-symbols (or -j for
  short).  Does this meet your needs ?

Cheers
  Nick
Comment 3 Fangrui Song 2021-03-13 01:24:01 UTC
Hi Nick, thanks for the patch! --format=just-symbols and -j look good to me. I wonder whether it is necessary to reserve -J. -J can probably be used for other purposes.
Comment 4 cvs-commit@gcc.gnu.org 2021-03-15 10:56:11 UTC
The master branch has been updated by Nick Clifton <nickc@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=1996d0f12cd57391e01e0eebe32e44510e6ec17d

commit 1996d0f12cd57391e01e0eebe32e44510e6ec17d
Author: Nick Clifton <nickc@redhat.com>
Date:   Mon Mar 15 10:55:49 2021 +0000

    Add a symbols-only mode to nm.
    
            PR 27487
            * nm.c (FORMAT_JUST_SYMBOLS): Define.
            (struct optput_fns): Add entry for FORMAT_JUST_SYMBOLS.
            (long_options): Add just-symbols.
            (set_output_format): Add support for just-symbols.
            (get_print_format): Likewise.
            (do_not_print_object_filename): New function.
            (do_not_print_archive_filename): New function.
            (do_not_print_archive_member): New function.
            (do_not_print_symbol_filename): New function.
            (just_print_symbol_name): New function.
            (main): Handle --just-symbols.
            * NEWS: Mention the new feature.
            * doc/binutils.texi: Document the new feature.
Comment 5 Nick Clifton 2021-03-15 10:57:03 UTC
Good point.  '-J' removed.  Patch committed. :-)