forked from OSchip/llvm-project
parent
b940b66c60
commit
d1942133e8
|
@ -13,12 +13,9 @@
|
|||
#include "llvm/ADT/StringRef.h"
|
||||
#include "llvm/ADT/Twine.h"
|
||||
#include "llvm/Config/config.h"
|
||||
#include "llvm/Demangle/Demangle.h"
|
||||
#include <algorithm>
|
||||
|
||||
#ifdef HAVE_CXXABI_H
|
||||
#include <cxxabi.h>
|
||||
#endif
|
||||
|
||||
using namespace llvm;
|
||||
using namespace lld;
|
||||
using namespace lld::elf;
|
||||
|
@ -86,9 +83,6 @@ bool elf::isValidCIdentifier(StringRef S) {
|
|||
|
||||
// Returns the demangled C++ symbol name for Name.
|
||||
std::string elf::demangle(StringRef Name) {
|
||||
#if !defined(HAVE_CXXABI_H)
|
||||
return Name;
|
||||
#else
|
||||
// __cxa_demangle can be used to demangle strings other than symbol
|
||||
// names which do not necessarily start with "_Z". Name can be
|
||||
// either a C or C++ symbol. Don't call __cxa_demangle if the name
|
||||
|
@ -97,12 +91,10 @@ std::string elf::demangle(StringRef Name) {
|
|||
if (!Name.startswith("_Z"))
|
||||
return Name;
|
||||
|
||||
char *Buf =
|
||||
abi::__cxa_demangle(Name.str().c_str(), nullptr, nullptr, nullptr);
|
||||
char *Buf = itaniumDemangle(Name.str().c_str(), nullptr, nullptr, nullptr);
|
||||
if (!Buf)
|
||||
return Name;
|
||||
std::string S(Buf);
|
||||
free(Buf);
|
||||
return S;
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include "llvm/ADT/StringExtras.h"
|
||||
#include "llvm/ADT/Triple.h"
|
||||
#include "llvm/Config/config.h"
|
||||
#include "llvm/Demangle/Demangle.h"
|
||||
#include "llvm/Support/Debug.h"
|
||||
#include "llvm/Support/Errc.h"
|
||||
#include "llvm/Support/Host.h"
|
||||
|
@ -30,10 +31,6 @@
|
|||
#include "llvm/Support/Path.h"
|
||||
#include <algorithm>
|
||||
|
||||
#if defined(HAVE_CXXABI_H)
|
||||
#include <cxxabi.h>
|
||||
#endif
|
||||
|
||||
using lld::mach_o::ArchHandler;
|
||||
using lld::mach_o::MachOFile;
|
||||
using lld::mach_o::MachODylibFile;
|
||||
|
@ -876,20 +873,18 @@ std::string MachOLinkingContext::demangle(StringRef symbolName) const {
|
|||
if (!symbolName.startswith("__Z"))
|
||||
return symbolName;
|
||||
|
||||
#if defined(HAVE_CXXABI_H)
|
||||
SmallString<256> symBuff;
|
||||
StringRef nullTermSym = Twine(symbolName).toNullTerminatedStringRef(symBuff);
|
||||
// Mach-O has extra leading underscore that needs to be removed.
|
||||
const char *cstr = nullTermSym.data() + 1;
|
||||
int status;
|
||||
char *demangled = abi::__cxa_demangle(cstr, nullptr, nullptr, &status);
|
||||
char *demangled = llvm::itaniumDemangle(cstr, nullptr, nullptr, &status);
|
||||
if (demangled) {
|
||||
std::string result(demangled);
|
||||
// __cxa_demangle() always uses a malloc'ed buffer to return the result.
|
||||
free(demangled);
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
|
||||
return symbolName;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue