nm
Display symbol tables from object files, libraries, and executables
Syntax
nm [options] [object-file...]
Basic Usage
Display symbols from executable
nm program
Shows the symbol table of the specified executable.
Display symbols from object file
nm file.o
Display symbols from library
nm libexample.so
Common Options
-a, --debug-syms: Display all symbols including debug symbols-A, --print-file-name: Print filename before each symbol-B: Use BSD format output-C, --demangle: Decode mangled C++ names-D, --dynamic: Display dynamic symbols only-f format: Output format (bsd, sysv, posix)-g, --extern-only: Display external symbols only-l, --line-numbers: Display source file and line number-n, --numeric-sort: Sort symbols numerically by address-p, --no-sort: Don't sort symbols-r, --reverse-sort: Reverse sort order-S, --print-size: Show size of symbols-t format: Output format (radix)-u, --undefined-only: Display undefined symbols only-v, --version: Display version information
Practical Examples
Show all symbols with demangling
nm -C program
Show only undefined symbols
nm -u program
Show symbols with sizes
nm -S program
Show external symbols only
nm -g program
Show symbols with line numbers
nm -l program
Show symbols sorted by address
nm -n program
Show dynamic symbols from shared library
nm -D libexample.so
Show symbols in POSIX format
nm -f posix program
Understanding Output
Symbol Types
A: Absolute symbolB: Uninitialized data (BSS)C: Common symbolD: Initialized dataG: Global symbolI: Indirect symbolN: Debugging symbolR: Read-only dataT: Text section symbolU: Undefined symbolV: Weak symbolW: Weak symbol-: Local symbol
Output Format
Default output shows: address type symbol_name
address: Memory address (or size for undefined symbols)type: Symbol type (see above)symbol_name: Name of the symbol
Best Practices
Use Cases
- Debugging binary files and executables
- Reverse engineering and analysis
- Checking library dependencies
- Verifying symbol exports in shared libraries
- Understanding program structure
Important Notes
- Symbol information may be stripped from release builds
- Use -C flag for readable C++ function names
- Dynamic symbols are different from static symbols
- Addresses shown are virtual addresses, not physical
- Some symbols may be optimized away by the compiler