C++ Mangled Names

I have encountered a need for manually generating the mangled name of an arbitrary C++ function. The only way I currently know how to do this is to generate a dummy C++ source file, compile it, and look at the output. This approach is so ugly that I would like for it never to see the light of day. The c++filt tool generates demangled C++ names given the mangled ones, which is the opposite of what I want to do. Does anyone know how to "run c++filt in reverse"?


It's not so simple. Assuming you limit yourself to the ABI used by the GNU compiler, there is still an awful lot of information needed in the most general case. See:


for the mangling scheme (although the actual GCC implementation sometimes deviates from that for less common cases).

If you're only dealing with non-local named functions and types plus ordinary type composition and exclude function templates (or at least, function templates with dependent expressions in the signature), it's probably not too hard (i.e., just a day or a few days work) to code up a mangler. If more is needed (local types, decltype, lambdas, etc.), it gets messier quite quickly.


Clang contains a mangler. You just have to extract the code into a standalone tool.


It would be lovely to have a declspec that adds an additional user given to label routines if required.