What is nm Linux command?
The Linux nm command is a powerful tool used to display symbol information from object files. It helps users examine binary files and libraries to understand the symbols present within them. This command is commonly used in debugging and analyzing compiled programs.
nm Syntax:
nm Options:
Option | Description |
---|---|
-A, —print-file-name | Print the name of the file before its symbols. |
-C, —demangle | Decode (demangle) low-level symbol names into user-level names. |
-D, —dynamic | Display dynamic symbols instead of normal symbols. |
-f | Specify the output format for the symbols. |
-l, —line-numbers | Show line numbers where symbols were found. |
-n, —numeric-sort | Sort symbols numerically. |
-p, —no-sort | Do not sort the symbols. |
-t | Sort symbols on the specified column. |
-S, —print-size | Show the size of the symbols. |
-u, —undefined-only | Show only undefined symbols. |
Parameters:
Parameter | Description |
---|---|
object-file | The object file to examine for symbols. |
nm Command Usage Examples:
Display Symbols in a Binary File
Displays the symbols (functions and variables) in the binary file “ls”.
Display Only External Symbols
Displays only the external symbols in the binary file “ls”.
Display Symbols in a Shared Library
Displays the symbols in the shared library “libc.so”.
Display Demangled C++ Symbols
Displays demangled C++ symbols in the binary file “program”.
Filter Symbols by Name
Filters and displays symbols with the name “my_function” in the binary file “program”.
How do I use nm in Linux?
To use the nm command in bash, execute the following command:
What are the common options used with nm in Linux?
To display the symbol table of an object file using nm in Linux, you can use the -S
option. Here’s an example:
How can I filter the output of nm in Linux?
You can filter the output of nm in Linux by using grep to search for specific symbols. For example:
How do I show only undefined symbols with nm in Linux?
To display only undefined symbols using nm in Linux, you can use the -u
option. Here’s how you can do it:
How can I demangle C++ symbol names with nm in Linux?
To demangle C++ symbol names when using nm in Linux, you can use the --demangle
option. Here’s an example:
How do I display the size of symbols with nm in Linux?
You can display the size of symbols using nm in Linux by using the -S
and -l
options together. Here’s how you can do it:
How can I get the full path for symbols with nm in Linux?
To show the full path for each symbol when using nm in Linux, you can use the -A
option. Here’s an example:
How do I list only external defined symbols with nm in Linux?
To list only external defined symbols using nm in Linux, you can use the -g
and -D
options together. Here’s an example:
Applications of the nm command
- Display symbols from object files
- List shared library dependencies
- Show the type of symbols (e.g., function, object, etc.)
- Check for the presence of specific symbols in binary files
- Identify undefined symbols in an object file