LinuxCommandLibrary

c++filt

Demangle C++ symbol names

SYNOPSIS

c++filt [OPTION...] [SYMBOL...]

PARAMETERS

SYMBOL...
    One or more mangled symbols to be demangled. If no symbols are provided, c++filt reads from standard input.

--strip-underscore, -_
    Strips a leading underscore from the symbol. This is sometimes added by compilers on certain platforms (e.g., macOS, Windows) for historical reasons.

--no-strip-underscore, -n
    Prevents stripping a leading underscore from the symbol. This is the default behavior on most Unix-like systems for GNU tools.

--types, -t
    Includes argument types in the demangled output. This is typically the default for C++ demangling unless a format like 'java' is specified.

--format=FORMAT
    Specifies the mangling style or Application Binary Interface (ABI) to use for demangling. Common formats include gnu (default), auto, arm, hp, lucid, sgi, edg, gnu-v3, and java.

--help
    Displays a help message and exits.

--version
    Displays version information and exits.

DESCRIPTION

The c++filt command is a utility designed to demangle encoded C++ and Java symbols, converting them into a human-readable format. Compilers like GCC mangle (or decorate) C++ symbols to include vital information such as argument types, namespaces, and return types, ensuring unique names for overloaded functions and methods, and supporting features like templates. This mangling process, while crucial for the linker, makes symbols unintelligible to humans.

c++filt reverses this process, taking a mangled symbol as input (either from standard input or directly as a command-line argument) and outputting its demangled counterpart. This is particularly useful when analyzing linker error messages, examining symbol tables with nm, disassembling code with objdump, or inspecting debugger output, where raw mangled symbols would otherwise be obscure. It supports various C++ Application Binary Interfaces (ABIs) and also has specific support for Java symbol demangling.

CAVEATS

The effectiveness of c++filt relies on its knowledge of specific compiler mangling schemes (ABIs). If the input symbol adheres to an unknown or unsupported mangling format, c++filt may fail to demangle it correctly or output it unchanged. It does not perform any linking or runtime analysis; it purely applies pattern matching based on known ABI rules. For Java symbols, use --format=java as the mangling rules are distinct from C++.

USAGE WITH OTHER COMMANDS

c++filt is often used in conjunction with other command-line utilities. For instance, to demangle all C++ symbols found in an executable or object file, you might pipe the output of nm or objdump through c++filt:

nm my_program | c++filt
objdump -t my_library.so | c++filt

This allows for easier analysis of an application's symbol table.

MANGLED VS. DEMANGLED SYMBOLS

Mangled symbols are internal representations used by compilers and linkers to uniquely identify functions, variables, and other program elements, particularly in C++ where features like function overloading and namespaces require more complex naming conventions. For example, a C++ function like

void MyNamespace::myFunction(int, double)
might be mangled into something like
_ZN10MyNamespace10myFunctionEif
. c++filt reverses this transformation to its original, understandable form.

HISTORY

The c++filt utility is an integral part of the GNU Binutils collection, a set of programming tools for creating and managing binary programs, object files, libraries, profile data, and assembly source files. Binutils has been a cornerstone of the GNU Project since its early days, evolving alongside the GCC compiler to support various C++ standards and their associated Application Binary Interfaces (ABIs). Its core function—translating mangled C++ symbols into human-readable forms—has remained consistent, with updates primarily focused on incorporating new demangling rules as C++ language features and compiler ABIs (like the Itanium C++ ABI, which is widely adopted) have developed over time.

SEE ALSO

nm(1), objdump(1), readelf(1), gdb(1), ld(1)

Copied to clipboard