For this, add a few toString() calls when printing the "undefined symbol" diagnostics; toString() already does demangling on Windows hosts.
Also make lld::demangleMSVC() (called by toString(Symbol*)) call LLVM's microsoftDemangle() instead of UnDecorateSymbolName() so that it works on non-Windows hosts – this makes both updating tests easier and provides a better user experience for people doing cross-links.
Update microsoftDemangle() to work more like itaniumDemangle() after which appears to be modeled, so that lld::demangleItanium() and lld::demangleMSVC() can look alike:
- Use same method of initializing the output stream and its buffer
- Allow a nullptr Status pointer
- Don't print the mangled name on demangling error
- Write to N (if it is non-nullptr)
This doesn't yet do the right thing for symbols starting with __imp_, but that can be improved in a follow-up.
Looks like there are two patterns how to use this function -- one way is to pass nullptr, nullptr as first two arguments, and the other is to pass an actual buffer. Can you separate that as two functions?
It looks like the latter use case is used only once, so you might be able to inline it.