GCC C++ Name mangling reference

Mona the Monad picture Mona the Monad · Jan 7, 2017 · Viewed 14.2k times · Source

Looking around, I see mostly questions about demangling C++ symbols rather than how to mangle them. Yes, one could invoke g++, using the -S option, on some dummy code containing the symbols to be mangled, and then examine the resulting assembly, but I haven't been able to find a good reference or specification on GCC's name mangling. The closest thing I could find was at http://www.int0x80.gr/papers/name_mangling.pdf, but it doesn't seem to cover things like how names template instantiations are mangled or why _Z3fooIN3BarEE3FooIXT_EEv would translate into Foo<Bar> foo<Bar>() (though I can kind of see how, but what the hell is IXT_EE? Why is there no N after the _Z in this one? What's that even mean?).

Answer

Pavel Golubev picture Pavel Golubev · Jan 7, 2017

Quote from gcc's sources(https://github.com/gcc-mirror/gcc/blob/master/gcc/cp/mangle.c):

This file implements mangling of C++ names according to the IA64 C++ ABI specification.

And here is the rules from this specification: https://itanium-cxx-abi.github.io/cxx-abi/abi.html#mangling