nm的用法

NAME

​ nm - 列出对象文件中的符号

SYNOPSIS

   nm [-A|-o|--print-file-name] [-a|--debug-syms]
      [-B|--format=bsd] [-C|--demangle[=style]]
      [-D|--dynamic] [-fformat|--format=format]
      [-g|--extern-only] [-h|--help]
      [-l|--line-numbers] [--inlines]
      [-n|-v|--numeric-sort]
      [-P|--portability] [-p|--no-sort]
      [-r|--reverse-sort] [-S|--print-size]
      [-s|--print-armap] [-t radix|--radix=radix]
      [-u|--undefined-only] [-V|--version]
      [-X 32_64] [--defined-only] [--no-demangle]
      [--plugin name]
      [--no-recurse-limit|--recurse-limit]]
      [--size-sort] [--special-syms]
      [--synthetic] [--with-symbol-versions] [--target=bfdname]
      [objfile...]

DESCRIPTION

GNU nm列出了对象文件objfile…中的符号。。。。

如果参数中未指定对象文件objfile...,则nm会假定a.out文件为指定的对象文件。

对于每个符号,nm显示:

  • 符号值:会按照选项中指定的进制进行显示,默认情况下为16进制。
  • 符号类型:一般情况下按照如下约定(也有部分情况取决于对象文件的格式):小写符号,表示本地(Local),大写符号,表示全局(gloabl / external)。然而,也有一些特小写符号用于显示特定的全局符号(“u”,“v”,“w”)。
    • “A”:符号的值是绝对值,不会因进一步链接而更改。
    • “B” | “b”:该符号位于BSS段,BSS段通常是指用来存放程序中未初始化的或者初始化为0(具体行为取决于系统)的全局变量静态变量的一块内存区域。
    • “C”:The symbol is common. Common symbols are uninitialized data. When linking, multiple common symbols may appear with the same name. If the symbol is defined anywhere, the common symbols are treated as undefined references.
    • “D” | “d”:此符号位于初始化数据部分。
    • “G” | “g”:此符号位于小对象的初始化数据部分。一些对象文件格式允许更有效地访问小型数据对象,例如与大型全局数组相反的全局int型变量。
    • “i”:对于PE格式文件,该符号表示位于特定DLL实现的部分。对于ELF格式文件,该符号表示是间接函数。这是GNU对ELF符号类型标准集的扩展。它表示一个符号,如果被重新定位引用,它的计算结果不会与它的地址一致,而是必须在运行时调用。然后,运行时执行将返回要在重新定位中使用的值。It indicates a symbol which if referenced by a relocation does not evaluate to its address, but instead must be invoked at runtime. The runtime execution will then return the value to be used in the relocation.
    • “I”:该符号是对另一个符号的间接引用。
    • “N”:该符号是调试符号。
    • “n”:该符号位于只读数据部分。
    • “p”:该符号位于堆栈展开部分。
    • “R” | “r”:符号位于只读数据段中。
    • “S” | “s”:该符号表示位于未初始化或零初始化数据部分的小对象。
    • “T” | “t”:该符号位于文本(代码)部分。
    • “U”:符号未定义。
    • “u”:该符号是唯一的全局符号。这是GNU对ELF符号绑定标准集的扩展。对于这样一个符号,动态链接器将确保在整个过程中只有一个使用此名称和类型的符号。
    • “V” | “v”:The symbol is a weak object. 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. On some systems, uppercase indicates that a default value has been specified.
    • “W” | “w”:The symbol is a 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 symbol is determined in a system-specific manner without error. On some systems, uppercase indicates that a default value has been specified.
    • “-”:The symbol is a stabs symbol in an a.out object file. In this case, the next values printed are the stabs other field, the stabs desc field, and the stab type. Stabs symbols are used to hold debugging information.
    • “?”:符号类型未知,或特定于对象文件格式。
  • 符号名

OPTIONS

这里显示的选项的长形式和短形式是等价的。

  • -A | -o | --print-file-name

    在每个符号前面加上找到它的输入文件(或存档成员)的名称,而不是在所有符号之前只标识一次输入文件。

  • -a

    –debug-syms

    Display all symbols, even debugger-only symbols; normally these are not listed.

  • -B

    与–format=bsd相同(与MIPS nm兼容)。

  • -C

    –demangle[=style]

    将低级符号名解码(demangle)为用户级名称。除了删除系统所提供的任何初始下划线之外,这使得C++函数名称可读。不同的编译器有不同的编译风格。可选的Demanling style参数可用于为编译器选择适当的Demanling样式。

  • –no-demangle

    不对低级符号名进行demangle。这是默认设置。

  • –recurse-limit

    –no-recurse-limit

    –recursion-limit

    –no-recursion-limit

    Enables or disables a limit on the amount of recursion performed whilst demangling strings. Since the name mangling formats allow for an inifinite level of recursion it is possible to create strings whose decoding will exhaust the amount of stack space available on the host machine, triggering a memory fault. The limit tries to prevent this from happening by restricting recursion to 2048 levels of nesting.

    The default is for this limit to be enabled, but disabling it may be necessary in order to demangle truly complicated names. Note however that if the recursion limit is disabled then stack exhaustion is possible and any bug reports about such an event will be rejected.

  • -D

    –dynamic

    显示动态符号而不是普通符号。这仅对动态对象有意义,例如某些类型的共享库。

  • -f format

    –format=format

    使用指定的格式输出,可以是“bsd”、“sysv”或“posix”。默认值为“bsd”。只有格式的第一个字符是有意义的;它可以是大写或小写。

  • -g

    –extern-only

    仅显示外部符号。

  • -h

    –help

    显示nm的帮助信息并退出。

  • -l

    –line-numbers

    For each symbol, use debugging information to try to find a filename and line number. For a defined symbol, look for the line number of the address of the symbol. For an undefined symbol, look for the line number of a relocation entry which refers to the symbol. If line number information can be found, print it after the other symbol information.

  • –inlines

    当选项-l处于活动状态时,如果地址属于内联函数,则此选项会导致将所有封闭作用域的源信息打印回第一个非内联函数。例如,如果“main”包含“callee1”,其中包含“callee2”,并且地址来自“callee2”,那么“callee1”和“main”的源信息也将被打印出来。

  • -n

    -v

    –numeric-sort

    按地址对符号进行数字排序,而不是按名称的字母顺序。

  • -p

    –no-sort

    不关心按何种顺序对符号进行排序;按遇到的顺序打印它们。

  • -r

    –reverse-sort

    颠倒排序顺序(数字或字母);让最后一个先来。

  • -S

    –print-size

    打印“bsd”输出样式定义符号的值和大小。此选项对不记录符号大小的对象格式无效,除非还使用 --size-sort,在这种情况下,将显示计算的大小。

  • -s

    –print-armap

    列出存档成员的符号时,请包括索引:一个映射(通过ar或ranlib存储在存档中),其中的模块包含哪些名称的定义。

  • -t radix

    –radix=radix

    使用基数作为打印符号值的基数。十进制必须是d,八进制必须是o,十六进制必须是x。

  • -u

    –undefined-only

    仅显示未定义的符号(每个对象文件外部的符号)。

  • -V

    –version

    显示nm的版本号并退出。

  • -X

    为了与AIX版本的nm兼容,此选项被忽略。它需要一个参数,必须是字符串32_64。AIX nm的默认模式对应于-X 32,这是GNU nm不支持的。

  • –defined-only

    仅显示每个对象文件的定义符号。

  • –plugin name

    加载名为name的插件,以添加对额外目标类型的支持。只有在工具链已启用插件支持的情况下,此选项才可用。

    如果未提供--plugin,但已启用插件支持,则nm将按字母顺序对${libdir}/bfd plugins中的文件进行迭代,并使用声称存在问题的对象的第一个插件。

    请注意,此插件搜索目录不是ld的-plugin选项使用的目录。为了让nm使用链接器插件,必须将其复制到${libdir}/bfd plugins目录。对于基于GCC的编译,链接器插件称为liblto_plugin.so.0.0.0。对于基于Clang的编译,它被称为LLVMgold.so。所以GCC插件始终与早期版本向后兼容,因此只需复制最新版本就足够了。

  • –size-sort

    按大小对符号进行排序。对于ELF对象,符号大小是从ELF读取的,对于其他对象类型,符号大小是根据符号值与符号值之间的差值计算的。如果使用“bsd”输出格式,则打印符号的大小,而不是值,并且必须使用-S,以便打印大小和值。

  • –special-syms

    显示具有特定目标特殊含义的符号。这些符号通常由目标用于某些特殊处理,当包含在正常符号列表中时通常没有帮助。例如,对于ARM目标,此选项将跳过用于标记ARM代码、拇指代码和数据之间转换的映射符号。

  • –synthetic

    在输出中包含合成符号。这些是链接器为各种目的创建的特殊符号。默认情况下不会显示它们,因为它们不是二进制文件原始源代码的一部分。

  • –with-symbol-versions

    启用符号版本信息(如果存在)的显示。版本字符串显示为符号名称的后缀,前缀为@字符。例如foo@VER_1.如果版本是解析符号的未版本引用时使用的默认版本,则它将显示为两个@字符前的后缀。例如foo@@VER_2。

  • –target=bfdname

    指定系统默认格式以外的目标代码格式。

  • @file

    从文件中读取命令行选项。将插入读取的选项以替代原始的@file选项。如果文件不存在或无法读取,则该选项将按字面意思处理,而不是删除。

    文件中的选项用空格分隔。通过将整个选项用单引号或双引号括起来,可以在选项中包含空格字符。任何字符(包括反斜杠)都可以通过在要包含反斜杠的字符前加前缀来包含。文件本身可能包含其他@file选项;任何此类选项都将被递归处理。

SEE ALSO

ar(1), objdump(1), ranlib(1), and the Info entries for binutils.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值