LinuxCommandLibrary

gcc-nm-4.8

List symbols from object files (gcc-4.8)

SYNOPSIS

nm [options] [files...]

PARAMETERS

-a
    Display all symbols, including debugger-only symbols and those with no address.

-C, --demangle
    Demangle low-level symbol names (e.g., C++ mangled names) into user-level readable names.

-D, --dynamic
    Display dynamic symbols only (from the dynamic symbol table for shared objects).

-g, --extern-only
    Display only external (global) symbols.

-l, --line-numbers
    Use source file and line number information for each symbol, if available in debugging info.

-n, --numeric-sort
    Sort symbols by their address (numeric value) instead of alphabetically by name.

-P, --portability
    Use the POSIX.2 standard format for output, ensuring consistent parsing across systems.

-r, --reverse-sort
    Reverse the order of the sort (e.g., descending for numeric sort, Z-A for alphabetical).

-S, --print-size
    Print the size of defined symbols in addition to their value.

-s, --print-sections
    Print the section name for each symbol (e.g., .text, .data, .bss).

-t <radix>
    Specify the radix for printing symbol values: d (decimal), o (octal), or x (hexadecimal).

-u, --undefined-only
    Display only undefined symbols, which are referenced by the file but not defined within it.

-V, --version
    Print `nm`'s version number and exit.

DESCRIPTION

The `nm` utility is a diagnostic tool that inspects object files, archives, or shared libraries and lists the symbols (e.g., functions, global variables, static variables) defined or referenced within them.

It displays crucial information such as the symbol's name, its value (typically an address), its type (e.g., 'T' for text, 'D' for data, 'U' for undefined), and the section it resides in. This is fundamental for debugging, understanding program structure, analyzing compilation and linking issues, and low-level system programming.

`gcc-nm-4.8` refers to the `nm` utility bundled with the GNU Compiler Collection (GCC) 4.8 toolchain, providing consistent functionality for analyzing binaries compiled by that specific GCC version or other compatible toolchains.

CAVEATS

The exact output format and available options for `nm` can vary slightly between different versions of GNU Binutils or other `nm` implementations, as well as across operating systems. `gcc-nm-4.8` specifically refers to the version bundled with the GCC 4.8 release; while generally compatible, using it with binaries compiled by significantly different toolchains might sometimes yield unexpected symbol information due to underlying ABI or object file format differences.

`nm` is primarily designed for object files and archives; some features might not be fully supported or relevant when analyzing raw executables or shared libraries without embedded debugging symbols.

SYMBOL TYPE CHARACTERS

`nm` uses single characters to denote a symbol's type, which is key to interpreting its output. Uppercase letters typically denote global symbols, while lowercase denotes local symbols.

Common types include:
T (or t): Symbol in the .text (code) section.
D (or d): Symbol in the .data (initialized data) section.
B (or b): Symbol in the .bss (uninitialized data) section.
U: Undefined symbol (referenced, but defined elsewhere, usually in a library).
W (or w): Weak symbol (can be overridden by a strong symbol).
A: Absolute symbol (value is fixed, not relative to any section).
V: Weak object symbol.
C: Common symbol.

DEFAULT OUTPUT FORMAT

By default, `nm`'s output for each symbol typically consists of three columns:
1. The symbol's value (address), usually in hexadecimal. This column is empty for undefined symbols.
2. A single character representing the symbol's type (as described above).
3. The symbol's name.

Example output:
0000000000400520 T main
U puts@@GLIBC_2.2.5
0000000000601030 D my_global_var

Options like `--portability` (`-P`) can alter this structure for easier programmatic parsing, while `--demangle` (`-C`) helps interpret C++ symbol names.

HISTORY

`nm` has been a fundamental utility in Unix-like operating systems since their early development, providing a crucial mechanism for inspecting the internal structure of compiled binaries. It originated as part of the Programmer's Workbench (PWB) and subsequently became a standard component of Unix toolchains.

Its core purpose—to list and categorize symbols—remains essential for debugging, understanding program linkages, and low-level software analysis. `gcc-nm-4.8` specifically denotes the version of `nm` that shipped as part of the GNU Binutils package distributed alongside GCC version 4.8, ensuring compatibility and consistency within that particular compiler environment.

SEE ALSO

objdump(1), readelf(1), ldd(1), strip(1), ar(1)

Copied to clipboard