[LLVMdev] [lld] adding demangler for symbol resolution

Shankar Easwaran
2014-04-02T18:47:02Z

On 4/2/2014 1:23 PM, Reid Kleckner wrote:
> On Wed, Apr 2, 2014 at 11:02 AM, Shankar Easwaran
> <shankare at codeaurora.org <mailto:shankare at
codeaurora.org>> wrote:
>
>     On 4/2/2014 12:23 PM, Nick Kledzik wrote:
>
>         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.
>
>     Are you mentioning that one demangle function in LinkingContext ?
>
>     One demangle method wouldnt work as the ItaniumABI uses one method
>     to demangle, ARMCXXABI uses a different method, and MSVC uses a
>     different one. I am not sure about Mach-O here ?
>
>
> First, it's really easy to detect which ABI is being used based on the
> prefix:
> _Z -> standard Itanium demangler (__cxa_demangle)
> __Z -> Itanium with a leading _
> ? -> MSVC
>
> We don't need a virtual method.  MinGW people might be linking Itanium
> symbols on Windows, and that should demangle just fine if
> __cxa_demangle is available.
>
> Second, __cxa_demangle is not available on all platforms, so lld
> should just test for it's availability and use it for Itanium symbols
> if available.
>
> I think the LLVM project has a demangler floating around (libc++?).
>  It might be nice to find a way to reuse that across projects like
> this so the output of LLVM tools doesn't change based on the
> capabilities of the host.  In other words, it'd be nice if we had a
> good story for demangled diagnostics while cross-linking.
>
Thanks for the info, Reid.

We will have a single demangler then, cross-linking is a very good point
that you raised.

The demangler will check if the first character was a _ and if
__cxa_demangle is available, call __cxa_demangle

If the first character is a ?, and if MSVC is defined, call
UnDecorateSymbolName

The above should suffice for now, I think, and if there is a need we
could add more to it.

-

Shankar Easwaran

--
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by the
Linux Foundation

-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://lists.llvm.org/pipermail/llvm-dev/attachments/20140402/a4ec8bd3/attachment.html>