C++ Name mangling

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
B B
Reply | Threaded
Open this post in threaded view
|

C++ Name mangling

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

_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: C++ Name mangling

Reid Kleckner-2
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.

On Thu, May 9, 2013 at 8:38 AM, B B <[hidden email]> wrote:

> 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
>
> _______________________________________________
> LLVM Developers mailing list
> [hidden email]         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>
_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: C++ Name mangling

Tim Northover-2
In reply to this post by B B
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.
_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: C++ Name mangling

Tim Northover-2
In reply to this post by Reid Kleckner-2
> 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.
_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
B B
Reply | Threaded
Open this post in threaded view
|

Re: C++ Name mangling

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



2013/5/9 Tim Northover <[hidden email]>
> 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.


_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: C++ Name mangling

João Matos
In reply to this post by Tim Northover-2
On Thu, May 9, 2013 at 1:55 PM, Tim Northover <[hidden email]> wrote:
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.

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

 
--
João Matos
_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev