Wiki

by yszheda

View project onGitHub

nm

Common Usage

$ nm
# is equivalent to
$ nm a.out
# output format: <symbol value>, <symbol class>, <symbol name>
$ nm a.o
# sort in a reversed order
$ nm -r a.o
$ nm --reverse-sort a.o

sort by size

# output format: <symbol size>, <symbol class>, <symbol name>
# <symbol size> means the size of the object which the symbol points to
# will not output undefined symbols
$ nm --size-sort a.o
$ nm --size-sort -r a.o
# include <symbol value> in the output
$ nm --size-sort -S a.o

output format (bsd by default)

# SysmtemV
$ nm -f sysv a.o
# POSIX
$ nm -f posix a.o
# [-A | -o | --print-file-name]
# show the source file names of symbols when processing multiple object files
$ nm -A *.o | grep <symbol>
# show the source file names of symbols when processing static linkage library
$ nm -A /usr/lib/libc.a

show dynamic symbols

$ nm -D a.out
$ nm --dynamic a.out

Symbol Class

section symbol class scope
text T global
  t local
data D global
  d local
  G global, for small objects (有些环境下使用近距离symbol的效率更高)
  g local, for small objects (有些环境下使用近距离symbol的效率更高)
read-only R global
  r local
bss B global
  b local
  S global, for small objects
  s local, for small objects
weak object V global
  v local
weak symbol W global
  w local
share C global
debug info N global
  n local
  - stabs
absolute value A global
  a local
undefined U global
indirect references I global
  i local
unknown ?  

demangle

$ nm foo.o
00000000 T _Z3fooi
$ nm foo.o | c++filt
00000000 T foo(int)
$ nm --demangle foo.o
00000000 T foo(int)