c++linuxfunctioncompilationc++filt

My c++filt doesn't seem to work properly, no output changes


On my linux, I've a .cpp file having

void f(){}
struct C{void f(){}};

I compiled it and strings the binary, try to de-mangle the function name:

$c++filt __Z1gv
__Z1gv
$c++filt __ZN1C1fEv
__ZN1C1fEv

Well, it doesn't seem to work as I expected. Did I get anything wrong here? Do I have to add some letters or remove some letters to make it work?

Note these names are clang symbols, seems c++filt only work for my gcc version? Or c++filt should have newer version to support both compilers?


Solution

  • You may need to pass the -_ flag.

    $ c++filt -_ __Z1gv
    g()
    $ c++filt -_ __ZN1C1fEv
    C::f()
    

    -_
    --strip-underscore

    On some systems, both the C and C++ compilers put an underscore in front of every name. For example, the C name "foo" gets the low-level name "_foo". This option removes the initial underscore. Whether c++filt removes the underscore by default is target dependent.