C++ Name mangling

Hi,
I’m trying to find a solution to the following problem: I need to generate a mangled name for given C++ function. Could I use llvm Mangler class for it?

Regards,
Blackbox dev team

No, the LLVM Mangler class really only does low-level manglings like
'_' prefixing, stdcall mangling on Windows, and escaping funny
symbols.

The Clang mangler, however, does what you want. But, you'll need to
feed it a clang AST in order to get a name out. Depending on the
parameters of your function, this may be easy or hard.

Hi,

I'm trying to find a solution to the following problem: I need to generate a
mangled name for given C++ function. Could I use llvm Mangler class for it?

I'm afraid not. That's for much lower level things like platforms
which add a leading '_' to every global symbol.

In principle the LLVM code that actually handles this is under Clang:
lib/AST/ItaniumMangle.cpp (for UNIX-like platforms) and
lib/AST/MicrosoftMangle.cpp (still incomplete, I believe). But
actually using them outside Clang would be very difficult. You'd
basically have to artificially create a Clang AST describing the
function you want to mangle (including all of its surrounding context
like the types it uses and so on) to feed in.

And even deciding on that context is much trickier than it first
appears. The following two functions are different, for example:

class A;
void foo(A*); // _Z3fooP1A

class Different;
typedef Different A;
void foo(A*); // _Z3fooP9Different

Tim.

The Clang mangler, however, does what you want. But, you'll need to
feed it a clang AST in order to get a name out. Depending on the
parameters of your function, this may be easy or hard.

By the way, does anyone know of a project which *does* call into
Clang's mangling framework from outside? I'd be interested to know
purely out of curiosity.

Cheers.

Tim.

Thanks for your helpful answers.
I guess I have to handle the mangling by myself then.

By the way, does anyone know of a project which does call into
Clang’s mangling framework from outside? I’d be interested to know
purely out of curiosity.

Tim, I’ll let you know if I manage to do this:D

Regards

My project CppSharp (https://github.com/tritao/CppSharp) does that in order to get the manglings for interoping between C++ and .NET.