nm | |
Author: | Dennis Ritchie, Ken Thompson (AT&T Bell Laboratories) |
Developer: | Various open-source and commercial developers |
Programming Language: | C |
Operating System: | Unix, Unix-like, Plan 9 |
Platform: | Cross-platform |
Genre: | Command |
License: | Plan 9: MIT License |
'''nm'''
is a Unix command used to dump the symbol table and their attributes from a binary executable file (including libraries, compiled object modules, shared-object files, and standalone executables).
The output from nm
distinguishes between various symbol types. For example, it differentiates between a function that is supplied by an object module and a function that is required by it. nm
is used as an aid for debugging, to help resolve problems arising from name conflicts and C++ name mangling, and to validate other parts of the toolchain.
This command is shipped with a number of later versions of Unix and similar operating systems including Plan 9. The GNU Project ships an implementation of nm
as part of the GNU Binutils package.
int global_var;int global_var_init = 26;
static int static_var;static int static_var_init = 25;
static int static_function
int global_function(int p)
int global_function2
extern "C"
void non_mangled_function
int main(void)
If the previous code is compiled with the gcc C compiler, the output of the nm
command is the following:
0000000a T global_function00000025 T global_function200000004 C global_var00000000 D global_var_init00000004 b local_static_var.125500000008 d local_static_var_init.12560000003b T main00000036 T non_mangled_function00000000 t static_function00000000 b static_var00000004 d static_var_init
When the C++ compiler is used, the output differs:
0000000a T _Z15global_functioni00000025 T _Z16global_function2v00000004 b _ZL10static_var00000000 t _ZL15static_functionv00000004 d _ZL15static_var_init00000008 b _ZZ15global_functioniE16local_static_var00000008 d _ZZ15global_functioniE21local_static_var_init U __gxx_personality_v000000000 B global_var00000000 D global_var_init0000003b T main00000036 T non_mangled_function
The differences between the outputs also show an example of solving the name mangling problem by using extern "C" in C++ code.
Symbol type ! Description | ||
---|---|---|
A | Global absolute symbol | |
a | Local absolute symbol | |
B | Global bss symbol | |
b | Local bss symbol | |
D | Global data symbol | |
d | Local data symbol | |
f | Source file name symbol | |
L | Global thread-local symbol (TLS) | |
l | Static thread-local symbol (TLS) | |
R | Global read-only symbol | |
r | Local read-only symbol | |
T | Global text symbol | |
t | Local text symbol | |
U | Undefined symbol |