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?).
Since C is a programming language that does not support name function overloading, it does no name mangling.
Name mangling is the encoding of function and variable names into unique names so that linkers can separate common names in the language. Type names may also be mangled. Name mangling is commonly used to facilitate the overloading feature and visibility within different scopes.
In compiler construction, name mangling (also called name decoration) is a technique used to solve various problems caused by the need to resolve unique names for programming entities in many modern programming languages.
One of the problems with name mangling is that the C++ standard (currently [ISO14882]) does not define how names have to be mangled; thus every compiler mangles names in its own way. Some compilers even change their name mangling algorithm between different versions (notably g++ 2.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With