mirror of
https://github.com/rui314/mold.git
synced 2024-09-20 01:18:53 +03:00
Attempt to demangle as a Rust symbol before as C++
https://github.com/rui314/mold/issues/371
This commit is contained in:
parent
808f1240ac
commit
22e1bba58e
39
demangle.cc
39
demangle.cc
@ -7,23 +7,34 @@
|
||||
namespace mold {
|
||||
|
||||
std::string_view demangle(std::string_view name) {
|
||||
if (name.starts_with("_Z")) {
|
||||
static thread_local char *buf;
|
||||
if (buf)
|
||||
free(buf);
|
||||
static thread_local char *buf;
|
||||
if (buf)
|
||||
free(buf);
|
||||
|
||||
int status;
|
||||
buf = abi::__cxa_demangle(std::string(name).c_str(), nullptr, nullptr,
|
||||
&status);
|
||||
if (status == 0)
|
||||
return buf;
|
||||
|
||||
buf = rust_demangle(std::string(name).c_str(), 0);
|
||||
if (buf)
|
||||
return buf;
|
||||
}
|
||||
// Try to demangle as a Rust symbol.
|
||||
buf = rust_demangle(std::string(name).c_str(), 0);
|
||||
if (buf)
|
||||
return buf;
|
||||
|
||||
// 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
|
||||
|
@ -1092,8 +1092,9 @@ void apply_version_script(Context<E> &ctx) {
|
||||
}
|
||||
|
||||
if (!cpp_matcher.empty())
|
||||
if (std::optional<u16> ver = cpp_matcher.find(demangle(name)))
|
||||
sym->ver_idx = *ver;
|
||||
if (std::optional<std::string_view> s = cpp_demangle(name))
|
||||
if (std::optional<u16> ver = cpp_matcher.find(*s))
|
||||
sym->ver_idx = *ver;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user