LinuxCommandLibrary

llvm-nm

List symbols from object files

TLDR

View documentation for the original command

$ tldr nm
copy

SYNOPSIS

llvm-nm [options] [file...]

PARAMETERS

-a, --all
    Display all symbols, even debugger-only symbols.

-B, --format bsd
    Use BSD output format.

-C, --demangle
    Demangle symbol names.

-D, --dynamic
    Display dynamic symbols only.

-defined-only
    Only show defined symbols.

-g, --global
    Display only global symbols.

-j, --just-symbol-name
    Print just the symbol names.

-n, --numeric-sort
    Sort numerically by address.

-P, --portability
    Use POSIX.2 rules to reduce command variations

-r, --reverse-sort
    Reverse the sort order.

-S, --size-sort
    Sort by size.

-u, --undefined-only
    Display only undefined symbols.

-U, --no-sort
    Don't sort symbols.

--help
    Display help message.

--version
    Display version information.

DESCRIPTION

The `llvm-nm` command lists the symbols from object files, archives, and executable files. It's part of the LLVM toolchain and provides functionality similar to the GNU `nm` command. `llvm-nm` displays a table of symbols including their addresses, types (such as code, data, or bss), and names. It can be used to inspect the contents of object files and libraries, helping developers understand the organization and dependencies of their code. It can be invaluable for debugging, reverse engineering, and understanding the internal workings of compiled programs. Various options allow filtering symbols based on their type or visibility, sorting results, and specifying the output format.

CAVEATS

Symbol information depends on the object file format (e.g., ELF, Mach-O). The behavior and output may vary depending on the target architecture and build configuration.

SYMBOL TYPES

The output of `llvm-nm` includes a character representing the symbol type. Some common types are:
T: Text (code) section
D: Initialized data section
B: Uninitialized data section (BSS)
U: Undefined symbol
W: Weak symbol
C: Common Symbol

DEMANGLING

C++ symbols are often mangled to include type information. The `-C` option demangles these names, making them more readable. This is very useful when examining C++ object files.

EXIT STATUS

`llvm-nm` returns 0 on success. A non-zero exit status indicates an error, such as an invalid option or failure to open a specified file.

HISTORY

llvm-nm is a part of the LLVM project, a collection of modular and reusable compiler and toolchain technologies. It was developed as an alternative to the GNU toolchain commands, offering potentially improved performance and a more modular architecture. Its usage has grown as the LLVM toolchain has become more prevalent in software development.

SEE ALSO

nm(1), objdump(1), readelf(1)

Copied to clipboard