1 //===- Strings.cpp -------------------------------------------------------===// 2 // 3 // The LLVM Linker 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #include "lld/Common/Strings.h" 11 #include "llvm/Demangle/Demangle.h" 12 13 using namespace llvm; 14 using namespace lld; 15 16 // Returns the demangled C++ symbol name for Name. 17 Optional<std::string> lld::demangleItanium(StringRef Name) { 18 // itaniumDemangle can be used to demangle strings other than symbol 19 // names which do not necessarily start with "_Z". Name can be 20 // either a C or C++ symbol. Don't call itaniumDemangle if the name 21 // does not look like a C++ symbol name to avoid getting unexpected 22 // result for a C symbol that happens to match a mangled type name. 23 if (!Name.startswith("_Z")) 24 return None; 25 26 char *Buf = itaniumDemangle(Name.str().c_str(), nullptr, nullptr, nullptr); 27 if (!Buf) 28 return None; 29 std::string S(Buf); 30 free(Buf); 31 return S; 32 } 33