mirror of
https://github.com/rui314/mold.git
synced 2024-09-21 01:47:11 +03:00
b42d039bd5
Both rust-demangle and xxhash provide usage instructions with include paths that do not have an extra directory component. This patch fixes uses of these libraries in the code and avoids including the third-party directory wholesale. Signed-off-by: friendlyanon <friendlyanon_@hotmail.com>
43 lines
952 B
C++
43 lines
952 B
C++
#include "mold.h"
|
|
|
|
#include <cstdlib>
|
|
#include <cxxabi.h>
|
|
#include <rust-demangle.h>
|
|
|
|
namespace mold {
|
|
|
|
std::string_view demangle(std::string_view name) {
|
|
static thread_local char *p;
|
|
if (p)
|
|
free(p);
|
|
|
|
// Try to demangle as a Rust symbol. Since legacy-style Rust symbols
|
|
// are also valid as a C++ mangled name, we need to call this before
|
|
// cpp_demangle.
|
|
p = rust_demangle(std::string(name).c_str(), 0);
|
|
if (p)
|
|
return p;
|
|
|
|
// Try to demangle as a C++ symbol.
|
|
if (std::optional<std::string_view> s = cpp_demangle(name))
|
|
return *s;
|
|
return name;
|
|
}
|
|
|
|
std::optional<std::string_view> cpp_demangle(std::string_view name) {
|
|
static thread_local char *buf;
|
|
static thread_local size_t buflen;
|
|
|
|
if (name.starts_with("_Z")) {
|
|
int status;
|
|
char *p = abi::__cxa_demangle(std::string(name).c_str(), buf, &buflen, &status);
|
|
if (status == 0) {
|
|
buf = p;
|
|
return p;
|
|
}
|
|
}
|
|
return {};
|
|
}
|
|
|
|
} // namespace mold
|