Linux nm 命令使用及符号含义

1 nm 命令介绍

NAME
       nm - list symbols from object files

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] [-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] [--size-sort] [--special-syms]
          [--synthetic] [--target=bfdname]
          [objfile...]

DESCRIPTION
       GNU nm lists the symbols from object files objfile....  If no object
       files are listed as arguments, nm assumes the file a.out.

       For each symbol, nm shows:
        # ... run man nm for detials.

简单说的话,就是可以帮你列举出该目标中定义的符合要求的符号。要求可以很多,主要通过参数实现:外部引入的、内部定义的、动态的... 也可以添加参数使nm同时打印行号、文件名等相关信息。

2 nm 结果含义

nm 将找到的符号值使用十六进制缺省表示,并在函数前添加其类型,类型主要有:

Value Descripition Note
A The symbol's value is absolute, and will not be changed by further linking. 符号绝对,链接过程不会改变
B/b The symbol is in the uninitialized data section (known as BSS). 非初始化符号
C The symbol is common. 公有符号,链接时会被同名符号覆盖
D/d The symbol is in the initialized data section. 初始化符号
G/g The symbol is in an initialized data section for small objects. 初始化符号,面向小数据访问优化
I The symbol is an indirect reference to another symbol. 其它符号的间接引用
N The symbol is a debugging symbol. 调试符号
P The symbols is in a stack unwind section. 栈区符号(清空)
R/r The symbol is in a read only data section. 符号只读
S/s The symbol is in an uninitialized data section for small objects. 非初始化符号,面向小数据访问优化
T/t The symbol is in the text (code) section. 代码区符号
U The symbol is undefined. 未定义或在外部定义的符号
u The symbol is a unique global symbol. 全局唯一,GNU保留符
V/v The symbol is a weak object. 弱定义符(详见C++强弱符号定义)
W/w The symbol is a weak symbol that has not been specifically tagged as a weak object symbol. emm...绕口令符号
- The symbol is a stabs symbol in an a.out object file. stabs格式符号
? The symbol type is unknown, or object file format specific. NM也不认识的符号

 


你可能感兴趣的:(Linux)