[LLVMdev] [lld] adding demangler for symbol resolution

Nick Kledzik kledzik at apple.com
Wed Apr 2 10:23:00 PDT 2014


On Apr 1, 2014, at 9:19 PM, Shankar Easwaran wrote:

> Hi Nick, Bigcheese,
> 
> When lld is used to link C++ code, it would be required to demangle symbol names by default/user driven option.
> 
> The Gnu linker has the following options :-
> 
> --demangle=[style]
> --no-demangle
> 
> I found that clang/llvm-symbolizer use __cxx_demangle function.
> 
> I would think that lld also need to call the same function, and I think the way we want to demangle is to have the function in LinkingContext as various flavors may choose to use different API's to demangle symbol names.
> 
> The API's that would be in LinkingContext would be :-
> 
>        * virtual bool canDemangle()  = 0; // Does the flavor provide a way to demangle symbol names ?
>        * virtual std::string demangle(StringRef symbolName) = 0; // demangle the symbol name
> 
> Thoughts / Suggestions ?
Wouldn't it be simpler to have one demangle() method that does nothing (returns input string) if demangling is not available, the string is not a mangled symbol, or demangling was turned off (--no-demangle).   Then, you just wrap a demangle() call around every use.  

The __cxa_demangle function has an odd interface that requires a malloc allocated block.  Having demangle() return a std::string means yet another allocation. We might not care if this is just used in diagnostic outputs, but a more efficient way would be to pass the stream object to demangle and have it write directly to the stream instead of creating a std::string.

Seems like a demangling utility might be something to add at the LLVM level.  Either directly to raw_ostream or a wrapper like format().

-Nick



More information about the llvm-dev mailing list