GNU Development Tools
list symbols from object files。列出编入目标文件或二进制文件的所有符号。可以查看执行文件或库文件的符号。
编译器在编译源码时会产生符号来描述这些变量、函数的地址和空间。
一种用途是查看程序调用什么函数,另一个用途是查看一个给定的库或者目标文件是否提供了所需的函数。
nm [options] file
如果没有目标文件,nm默认文件为a.out。
对于每个符号,nm会列出符号的值,类型,名字。
对于符号的类型,小写的表明是本地的,大定的表明是全局的或外部的。
Aabsolute,该符号的值是绝对的,在以后的链接过程中,不允许改变。这样的符号值,常常出现在中断向量表中。B该符号的值出现在未初始化数据段BSS中。Ccommon,该符号是未初始化的数据。D该符号位于初始化数据中。G位于初始化数据段中,主要用于小对象的访问。I其它符号的间接引用,是GNU的一种扩展。Ndebugging符号R位于只读数据区S位于非初始化数据段中,主要用于小对象的访问T位于text段,代码段U符号是非定义的Va weak object。When a weak defined symol is linked with a normal defined symol, the normal defined symbol is used with no error. When a weak undefined symbol is linked and the symbol is not defined, the value of the weak symbol becomes zero with no error.Wa weak symbol that has not been specifically tagged as a weak object symbol. When a weak defined symbol is linked with a normal defined symbol, the normal defined symbol is used with no error. When a weak undefined symbol is linked and the symbol is not defined, the value of the weak symbol becomes zero with no error.-a.out文件中的stabs symbol
? 非定义的类型
参数
-A -o --print-file-name 在每个符号前列出文件名,而不是只列出一次。
-a --debug-syms 显示所有的符号,包括只用于debugger的符号(正常是不列出来的)
-B --format=bsd
-C --demangle[=style] 把低级符号名解码成用户级符号名,这可以使C++的函数名可读。
--no-demangle 不解码低级符号,这是默认值。
-D --dynamic 显示动态符号名。这选项对动态目标有意义,例如某共享库中的类型。
-f format --format=format 指定输出格式 bsd sysv posix,默认值是bsd.
-g --extern-only 只显示外部符号
-l --line-numbers 显示行号
-n -v --numeric-sort 以地址进行数字排序
-p --no-sort 不进行排序
-P --portability POSIX.2的标准输出格式,等同于-f posix
-S --print-size 对于bsd输出格式,打印出已定义符号的大小。
-s --print-armap 从库成员中列出符号时,显示出索引。
-r --reverse-sort 倒序显示
--size-sort 以大小进行排序
-t radix --radix=radix 指定显示的基数,d十进制,o八进制,x十六进制
--target=bfdname 指定目标代码格式
-u --undefined-only 只显示未定义的符号
--defined-only 只显示定义的符号
-V --version 显示版本号