summaryrefslogtreecommitdiff
path: root/lld/Common
diff options
context:
space:
mode:
authorNico Weber <nicolasweber@gmx.de>2018-09-15 18:27:09 +0000
committerNico Weber <nicolasweber@gmx.de>2018-09-15 18:27:09 +0000
commit7103e236678a03c704cb8961badb49c4d3dfbaaf (patch)
tree370d52c590cd74c41420dbdf9c99d316d9a1dd88 /lld/Common
parent576a83195cc6f0468bd56e894633e1b86d380069 (diff)
lld-link: print demangled symbol names for "undefined symbol" diagnostics
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
Diffstat (limited to 'lld/Common')
-rw-r--r--lld/Common/Strings.cpp29
1 files changed, 9 insertions, 20 deletions
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 <mutex>
#include <vector>
-#if defined(_MSC_VER)
-#include <Windows.h>
-
-// DbgHelp.h must be included after Windows.h.
-#include <DbgHelp.h>
-#pragma comment(lib, "dbghelp.lib")
-#endif
-
using namespace llvm;
using namespace lld;
@@ -45,18 +37,15 @@ Optional<std::string> lld::demangleItanium(StringRef Name) {
return S;
}
-Optional<std::string> 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<std::mutex> 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<std::string> 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<StringRef> Pat) {