[cfe-dev] Where do we really need mangled names

Greg Clayton gclayton at apple.com
Mon Feb 17 10:02:16 PST 2014


On Feb 15, 2014, at 2:57 PM, David Blaikie <dblaikie at gmail.com> wrote:

> So when comparing Clang's debug info strings to GCC's I came across a couple of disparities hinging on the inclusion of linkage names on certain functions. Here are a few differences:
> 
> * Clang includes linkage names on file-local (static or anon namespace) functions. GCC does not.
> * Clang does not include the linkage name of member functions of function-local classes. GCC does, if the function is non-static/non-anonymous namespace and inline (ie: the member function has linkonce-odr linkage, not internal linkage)
> * Clang does not include the linkage name for constructors and destructors - this may be necessary due to the difference (GCC duplicates, Clang has one version call the other) in implementations, but I doubt it. I assume we still emit multiple member functions, one to describe each version of the ctor/dtor we're emitting.
> 
> It looks like at least for the first case, this may've been deliberate ( http://llvm.org/viewvc/llvm-project?view=revision&revision=154570 which doesn't explain why and points to rdar://11079003 which Jim Grosbach told didn't have a great deal more context) but I don't have enough context to understand why and whether it's just a GCC bug that they don't emit it, or something tools should handle better, etc.
> 
> So - any thoughts on the disparity and if/why it's necessary?

It is necessary if you want your debugger to be able to evaluate an expression that fully qualifies the name of the static:

(lldb) expr a::b::g_foo

If you don't have the mangled name, you can only do:

(lldb) expr g_foo

Then you might get many many many different versions if more than one file contains a static named "g_foo".

Also, users never tend to fully qualify names and might try to execute:

(lldb) expr b::g_foo

expecting to see "a::b::g_foo". LLDB is able to find these variables by first looking for all the variable base names that match "g_foo", then removing any whose demangled named doesn't contain "b::g_foo".

So the mangled names on statics allows debuggers to do the right thing and be able to correctly display qualified static variables and is very important for good debugging.

Greg



More information about the cfe-dev mailing list