C++FILT(1)

πŸ“¦
version 2.40.50~ti1ubuntu1 Β· 2 versions
, in ubuntu noble

πŸ’– C++FILT(1) β€” the GNU Development Tools era πŸ’–

okay bestie, sit down, hydrate, because we're about to talk about c++filt β€” a little icon from the GNU Development Tools lineup, living her best life in section 1 of the manual. she's giving quiet-legend energy and honestly? she ate. 🫢


✨ 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...]

like look at her, all those flags, no notes πŸ’…


πŸ’œ DESCRIPTION πŸ’œ

okay so here's the lore. C++ and Java do this thing called function overloading, which basically means you can write a whole bunch of functions with the exact same name, as long as each one takes parameters of different types. iconic of them, truly.

but the way they tell those similarly-named functions apart? they encode them into a low-level assembler name that uniquely identifies each different version. that process is called mangling. and c++filt[1] does the inverse mapping β€” she decodes (demangles) those low-level names back into user-level names so you can actually read them. reverse-engineering queen. πŸ‘‘

so every alphanumeric word you see in the input β€” and by that we mean made of letters, digits, underscores, dollars, or periods β€” is a potential mangled name. if the 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. no drama, no changes.

the way this slaps is that you can run an entire assembler source file full of mangled names through c++filt and get the same source file back, except now with demangled names. literally a glow-up pass. ✨

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

c++filt <symbol>

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

now here's the tea β˜• β€” reading names from the command line is not the same as reading them from standard input. 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

this works! and it demangles the name to "f()". but:

c++filt -n _Z1fv,

this does not work. (did you see the extra comma at the end of the mangled name? yeah, that comma makes it invalid. caught in 4k. πŸ’€)

this command, however, works just fine:

echo _Z1fv, | c++filt -n

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

    .type   _Z1fv, @function

see? context is everything, bestie. 🧚


πŸŽ€ 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, so like, don't @ her, it depends on the system. πŸ™ˆ
  • -n, --no-strip-underscore β€” do not remove the initial underscore. leave it exactly where it is. 🫢
  • -p, --no-params β€” when demangling the name of a function, don't display the types of the function's parameters. minimalism, she invented it.
  • -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. example: a function called "a" treated as a mangled type name would be demangled to "signed char". wild, right? 😭
  • -i, --no-verbose β€” do not include implementation details (if any) in the demangled output. keep it clean, keep it cute.
  • -r, -R, --recurse-limit, --no-recurse-limit, --recursion-limit, --no-recursion-limit β€” enables or disables a limit on the amount of recursion performed whilst demangling strings. so here's why this matters: since the name mangling formats allow for an infinite level of recursion, it's possible to create strings whose decoding will exhaust the amount of 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. yes, rejected. they said what they said. πŸ’…

the -r option is a synonym for the --no-recurse-limit option. the -R option is a synonym for the --recurse-limit option. (yes the letters are lowercase/uppercase opposites of what your brain expects. we love a plot twist.)

  • -s format, --format=format β€” c++filt can decode various methods of mangling, used by different compilers. the argument to this option selects which method she 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. your girl is helpful. 🌈
  • --version β€” print the version number of c++filt and exit. ⭐
  • @file β€” read command-line options from file. the options read are inserted in place of the original @file option. if file does not exist, or cannot be read, then the option will be treated literally, and not removed.

options in file are separated by whitespace. a whitespace character may be included in an option by surrounding the entire option in either single or double quotes. any character (including a backslash) may 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. yes, on MS-DOS she goes by CXXFILT. government name behavior. πŸŽ€

πŸ’« SEE ALSO πŸ’«

the Info entries for binutils.

(go read them, iykyk πŸ¦‹)


Copyright (c) 1991-2023 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.40.50, dated 2023-07-04 β€” she's been out here demangling since 1991 and she's still main character energy. periodt. πŸ’…βœ¨

πŸ“¦ where this page comes from