Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GCC C++ Name mangling reference

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?).

like image 705
Mona the Monad Avatar asked Jan 07 '17 18:01

Mona the Monad


People also ask

Does C have name mangling?

Since C is a programming language that does not support name function overloading, it does no name mangling.

Why is C++ 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.

Why do compilers mangle names?

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.

Is C++ name mangling standard?

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.


1 Answers

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

like image 99
Schtolc Avatar answered Oct 03 '22 22:10

Schtolc