Skip to content

Latest commit

 

History

History
316 lines (243 loc) · 4.27 KB

nm.md

File metadata and controls

316 lines (243 loc) · 4.27 KB

nm (Name List) Command Cheatsheet

Installation Instructions

Windows

# Using MinGW
pacman -S binutils    # If using MSYS2
# Or via Chocolatey
choco install mingw-w64

Linux

# Debian/Ubuntu
sudo apt-get install binutils

# RHEL/CentOS
sudo yum install binutils

# Arch Linux
sudo pacman -S binutils

macOS

# Using Homebrew
brew install binutils
# Command might be available as 'gnm'

Basic Usage

  1. List all symbols:
nm binary_file
  1. Show dynamic symbols:
nm -D binary_file
  1. Show debug symbols:
nm --debug-syms binary_file

Symbol Types and Filtering

  1. Show only external symbols:
nm -g binary_file
  1. Show only undefined symbols:
nm -u binary_file
  1. Show only defined symbols:
nm -U binary_file
  1. Sort symbols by address:
nm -n binary_file
  1. Sort symbols alphabetically:
nm -p binary_file

Output Formatting

  1. Display size of symbols:
nm --size-sort binary_file
  1. Show symbol value and size:
nm --print-size binary_file
  1. Display in BSD format:
nm -B binary_file
  1. Display in POSIX format:
nm -P binary_file

Advanced Filtering

  1. Show only functions:
nm binary_file | grep -w "T"
  1. Show only global variables:
nm binary_file | grep -w "D"
  1. Show only static symbols:
nm binary_file | grep -w "t"

Special Operations

  1. Demangle C++ symbols:
nm --demangle binary_file
  1. Show symbol types:
nm -t x binary_file
  1. Print line numbers:
nm --line-numbers binary_file

Multiple File Operations

  1. Process multiple files:
nm file1.o file2.o
  1. Show filename with symbols:
nm --print-file-name file1.o file2.o

Symbol Analysis

  1. Find main function:
nm binary_file | grep " main$"
  1. List all constructors:
nm binary_file | grep "_init"
  1. List all destructors:
nm binary_file | grep "_fini"

Advanced Usage

  1. Generate output in portable format:
nm -P --portability binary_file
  1. Show synthetic symbols:
nm --synthetic binary_file
  1. Show all symbols with addresses:
nm -A binary_file

Integration with Other Tools

  1. Sort by symbol size:
nm --print-size --size-sort binary_file
  1. Format output for processing:
nm -p -g binary_file | cut -d' ' -f3
  1. Count symbols by type:
nm binary_file | awk '{print $2}' | sort | uniq -c

Specialized Analysis

  1. Find weak symbols:
nm binary_file | grep " W "
  1. List read-only data:
nm binary_file | grep " R "
  1. Find unitialized data:
nm binary_file | grep " B "

Architecture-Specific Options

  1. Display 32-bit format:
nm -32 binary_file
  1. Display 64-bit format:
nm -64 binary_file
  1. Show target specific symbol types:
nm --target=target_type binary_file

Debug Information

  1. Show debugging symbols only:
nm --debug-syms binary_file
  1. Show demangled symbols with types:
nm -C --demangle binary_file
  1. Display symbol versions:
nm --version-info binary_file

Export and Import Analysis

  1. List imported functions:
nm -D --undefined-only binary_file
  1. List exported functions:
nm -D --defined-only binary_file

Symbol Classification

  1. Show only private symbols:
nm --private-symbols binary_file
  1. Show only public symbols:
nm --public-symbols binary_file
  1. List external symbols:
nm --extern-only binary_file

Special Symbol Types

  1. Find thread-local symbols:
nm binary_file | grep " TLS "
  1. List common symbols:
nm binary_file | grep " C "
  1. Show absolute symbols:
nm binary_file | grep " A "

Output Manipulation

  1. Generate wide output:
nm --wide binary_file
  1. Show numeric radix:
nm -t d binary_file  # decimal
nm -t x binary_file  # hexadecimal
nm -t o binary_file  # octal

Archive Operations

  1. List archive symbols:
nm --print-armap archive.a
  1. Process all archive members:
nm --print-file-name archive.a