Function
Lists Symbol Information in. O. A. So, including the value, type, and name of a symbol. Symbols usually refer to defined functions, global variables, and so on.
Use
NM [option (s)]
UsefulOptions:
- -A prints the object file name before each symbol information;
- -C: name of the demangle symbol;
- -D: Print dynamic symbols;
- -L use the debugging information in the object file to print the source file and row number;
- -N is sorted by address/Symbol value;
- -U prints undefined symbols;
CommonSymbol type:
- A. The value of this symbol will not change in future links;
- B. Place the symbol in the BSS segment, usually those uninitialized global variables.
- D. Place the symbol in a common data segment, usually the initialized global variables.
- T this symbol is placed in the Code section, which is usually a global non-static function.
- U is undefined and must be linked from other object files.
- W is not explicitly specified as a weak link symbol. Other Object files with the same link are defined as above, otherwise, a system-specific default value is used.
Notes:
- -C always applies to object files compiled by C ++. Do you still remember the heavy load in C ++? To distinguish between overloaded functions, the C ++ compiler attaches the function return value/parameter information to the function name to form a mangle symbol. When this option is used to list symbols, perform an inverse operation to output the original and understandable Symbol names.
- when using-l, you must ensure that your object file contains symbolic information, this usually requires you to specify a-g option during compilation. For details, see Linux: GCC.
- before using nm, use Linux: file View the processor architecture of the object file, and then use the corresponding cross-version of the NM tool.
Example
For more details, see man page. Here is an example:
-
Nm-u hello. o
-
The undefined characters in hello. O are displayed and need to be linked to other object files.
-
nm-A/usr/lib/* 2>/dev/null | grep "t memset"
Find out which library file defines the memset function in the/usr/lib/directory.