From da15acbd68cb9c60aef5a4e51a5383641c65147d Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Sat, 15 Sep 2018 18:27:09 +0000 Subject: lld-link: print demangled symbol names for "undefined symbol" diagnostics MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. This doesn't yet do the right thing for symbols starting with __imp_, but that can be improved in a follow-up. Differential Revision: https://reviews.llvm.org/D52104 llvm-svn: 342332 --- lld/Common/Strings.cpp | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) (limited to 'lld/Common/Strings.cpp') diff --git a/lld/Common/Strings.cpp b/lld/Common/Strings.cpp index 36f4f77d847..581a0795482 100644 --- a/lld/Common/Strings.cpp +++ b/lld/Common/Strings.cpp @@ -16,14 +16,6 @@ #include #include -#if defined(_MSC_VER) -#include - -// DbgHelp.h must be included after Windows.h. -#include -#pragma comment(lib, "dbghelp.lib") -#endif - using namespace llvm; using namespace lld; @@ -45,18 +37,15 @@ Optional lld::demangleItanium(StringRef Name) { return S; } -Optional lld::demangleMSVC(StringRef S) { -#if defined(_MSC_VER) - // UnDecorateSymbolName is not thread-safe, so we need a mutex. - static std::mutex Mu; - std::lock_guard Lock(Mu); - - char Buf[4096]; - if (S.startswith("?")) - if (size_t Len = UnDecorateSymbolName(S.str().c_str(), Buf, sizeof(Buf), 0)) - return std::string(Buf, Len); -#endif - return None; +Optional lld::demangleMSVC(StringRef Name) { + if (!Name.startswith("?")) + return None; + char *Buf = microsoftDemangle(Name.str().c_str(), nullptr, nullptr, nullptr); + if (!Buf) + return None; + std::string S(Buf); + free(Buf); + return S; } StringMatcher::StringMatcher(ArrayRef Pat) { -- cgit v1.2.3