Function
Lists the symbolic information in. O. A, including values such as symbols, symbol types, and symbol names. The so-called symbols, usually refers to defined functions, global variables and so on.
Use
NM [option (s)] [file (s)]
Useful Options:
- -A prints the name of the object file in front of each symbol information;
- -C output demangle the symbol name;
- -D print dynamic symbols;
- -L Print out the source file and line number using debugging information in object file;
- -N is sorted by address/symbol value;
- -U prints out those undefined symbols;
Common symbol Types :
- A the value of the symbol will no longer change in future links;
- B the symbol is placed in the BSS section, usually those uninitialized global variables;
- D the symbol is placed in a normal data segment, usually those that have already been initialized in the global variable;
- T This symbol is placed in the code snippet, usually those global non-static functions;
- U This symbol is undefined and needs to be linked in from other object files;
- W does not explicitly specify a weak link symbol, and the other object file with the link has its definition, otherwise it is specified with a system-specific default value.
Note the points:
- -C is always available for C + + compiled object files. Remember that there are overloads in C + +? To differentiate between overloaded functions, the C + + compiler appends information such as function return values/parameters to the function name to form a mangle symbol, which, when listed with this option, does an inverse operation, outputting the original, understandable symbol names.
- When you use-l, you must ensure that your object file has symbolic-mode information, which generally requires you to specify a-G option when compiling, see LINUX:GCC.
- Before using NM, it is a good idea to use Linux:file to view the processor architecture of the object file and then use the corresponding cross-version of the NM tool.
Example
See the man page for more details. Here are some examples:
-
nm-u hello.o
-
displays undefined symbols in the hello.o and needs 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.
Linux NM command to view symbols in dynamic libraries and static libraries