[LLVMdev] C++ Mangled Names

David Vandevoorde daveed at vandevoorde.com
Tue Feb 15 07:41:20 PST 2011


On Feb 15, 2011, at 3:10 AM, Patrick Simmons wrote:

> 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:

	http://www.codesourcery.com/public/cxx-abi/abi.html#mangling

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.

	Daveed





More information about the llvm-dev mailing list