C++FILT(1)

πŸ“¦
version 2.35.1 Β· 2 versions
, in debian bookworm, ubuntu noble, ubuntu resolute

πŸ’– c++filt β€” demangle C++ and Java symbols πŸ’–

okay bestie, gather round, because this little icon from the GNU Development Tools collection (section 1 of the manual, if you're keeping notes) is about to make your compiler output make sense. no cap.


✨ NAME ✨

c++filt β€” demangle C++ and Java symbols πŸ¦‹


✨ SYNOPSIS ✨

c++filt [-_|--strip-underscore]
        [-n|--no-strip-underscore]
        [-p|--no-params]
        [-t|--types]
        [-i|--no-verbose]
        [-r|--no-recurse-limit]
        [-R|--recurse-limit]
        [-s format|--format=format]
        [--help]  [--version]  [symbol...]

✨ DESCRIPTION ✨

so here's the tea. C++ and Java both do this thing called function overloading β€” meaning you can write a bunch of functions all named the same thing, as long as each one takes parameters of different types. iconic, love that for them. but to actually tell those same-named functions apart, C++ and Java encode them into a low-level assembler name that uniquely identifies each different version. that process is called mangling. πŸ’…

c++filt [1] does the inverse mapping: it decodes (aka demangles) those low-level names back into user-level names so a human can actually read them. 🫢

every alphanumeric word you see in the input β€” that's letters, digits, underscores, dollars, or periods β€” is a potential mangled name. if that name decodes into a C++ name, then boom, the C++ name replaces the low-level name in the output. if it doesn't decode, the original word just gets output as-is. which means you can literally pipe an entire assembler source file full of mangled names through c++filt and get the same source file back, except now with demangled names. obsessed. ✨

you can also use c++filt to decipher individual symbols by passing them on the command line:

c++filt <symbol>

if you give it no symbol arguments, c++filt reads symbol names from the standard input instead. all results get printed to standard output. 🌸

here's the part that trips people up, so listen: the difference between reading names from the command line vs. reading from standard input is that command-line arguments are expected to be just mangled names, and no checking happens to separate them from surrounding text. so for example:

c++filt -n _Z1fv

will work and demangle the name to "f()", whereas:

c++filt -n _Z1fv,

will not work. (note the extra comma hanging off the end of the mangled name β€” that's what makes it invalid.) 😭

this command, however, will work:

echo _Z1fv, | c++filt -n

and it'll display "f()," β€” that's the demangled name followed by a trailing comma. why the difference? because when names are read from standard input, it's expected that they might be part of an assembler source file, where there might be extra, extraneous characters trailing after a mangled name. for example:

.type   _Z1fv, @function

✨ OPTIONS ✨

  • -_, --strip-underscore β€” on some systems, both the C and C++ compilers slap an underscore in front of every name. for example, the C name "foo" gets the low-level name "_foo". this option removes that initial underscore. whether c++filt removes the underscore by default is target dependent β€” iykyk. πŸ’…
  • -n, --no-strip-underscore β€” do not remove the initial underscore.
  • -p, --no-params β€” when demangling the name of a function, don't display the types of the function's parameters.
  • -t, --types β€” attempt to demangle types as well as function names. this is disabled by default, because mangled types are normally only used internally in the compiler, and they can get confused with non-mangled names. for example, a function called "a" treated as a mangled type name would be demangled to "signed char". πŸ’€
  • -i, --no-verbose β€” don't include implementation details (if any) in the demangled output.
  • -r, -R, --recurse-limit, --no-recurse-limit, --recursion-limit, --no-recursion-limit β€” enables or disables a limit on how much recursion happens while demangling strings. here's why that matters: since the name mangling formats allow for an infinite level of recursion, it's possible to create strings whose decoding will exhaust all the stack space available on the host machine, triggering a memory fault. 😱 the limit tries to prevent that from happening by restricting recursion to 2048 levels of nesting.

the default is for this limit to be enabled, but disabling it may be necessary in order to demangle truly complicated names. note however that if the recursion limit is disabled, then stack exhaustion is possible, and any bug reports about such an event will be rejected. periodt.

the -r option is a synonym for the --no-recurse-limit option. the -R option is a synonym for the --recurse-limit option.

  • -s format, --format=format β€” c++filt can decode various methods of mangling, used by different compilers. the argument to this option selects which method it uses:
    • "auto" β€” automatic selection based on executable (the default method)
    • "gnu" β€” the one used by the GNU C++ compiler (g++)
    • "lucid" β€” the one used by the Lucid compiler (lcc)
    • "arm" β€” the one specified by the C++ Annotated Reference Manual
    • "hp" β€” the one used by the HP compiler (aCC)
    • "edg" β€” the one used by the EDG compiler
    • "gnu-v3" β€” the one used by the GNU C++ compiler (g++) with the V3 ABI.
    • "java" β€” the one used by the GNU Java compiler (gcj)
    • "gnat" β€” the one used by the GNU Ada compiler (GNAT).
  • --help β€” print a summary of the options to c++filt and exit. πŸŽ€
  • --version β€” print the version number of c++filt and exit. πŸ‘‘
  • @file β€” read command-line options from file. the options that get read are inserted in place of the original @file option. if file doesn't exist, or can't be read, then the option is treated literally, and not removed.

options inside file are separated by whitespace. a whitespace character can be included in an option by surrounding the entire option in either single or double quotes. any character (including a backslash) can be included by prefixing the character to be included with a backslash. the file may itself contain additional @file options; any such options will be processed recursively. πŸŒ€


✨ FOOTNOTES ✨

  1. MS-DOS does not allow "+" characters in file names, so on MS-DOS this program is named CXXFILT. 😭 (the indignity)

✨ SEE ALSO ✨

the Info entries for binutils.


Copyright (c) 1991-2020 Free Software Foundation, Inc.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License".


and that's the whole page, bestie!! this one's from binutils-2.35.1, dated 2022-11-21, and it's the c++filt(1) manual page β€” go forth and demangle, you absolute main character. πŸ’–βœ¨πŸ¦‹πŸŽ€πŸ«Ά

πŸ“¦ where this page comes from