mirror of
https://github.com/rui314/mold.git
synced 2024-09-11 13:06:59 +03:00
Previously, we always tried to demangle a symbol name as a Rust symbol first and then attempted to demangle it as a C++ symbol. This resulted in an incorrect demangled result, as the Rust legacy mangling scheme is not distinguishable from C++. This patch fix the issue by adding the "is_rust_obj" flag to the ObjectFile. We try to demangle a symbol as a Rust one before as a C++ only if the flag is true. Fixes https://github.com/rui314/mold/issues/1159
43 lines
907 B
C++
43 lines
907 B
C++
#include "common.h"
|
|
|
|
#include <cstdlib>
|
|
|
|
#ifndef _WIN32
|
|
#include <cxxabi.h>
|
|
#endif
|
|
|
|
#include "../third-party/rust-demangle/rust-demangle.h"
|
|
|
|
namespace mold {
|
|
|
|
std::optional<std::string_view> demangle_cpp(std::string_view name) {
|
|
static thread_local char *buf;
|
|
static thread_local size_t buflen;
|
|
|
|
// TODO(cwasser): Actually demangle Symbols on Windows using e.g.
|
|
// `UnDecorateSymbolName` from Dbghelp, maybe even Itanium symbols?
|
|
#ifndef _WIN32
|
|
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;
|
|
}
|
|
}
|
|
#endif
|
|
|
|
return {};
|
|
}
|
|
|
|
std::optional<std::string_view> demangle_rust(std::string_view name) {
|
|
static thread_local char *buf;
|
|
free(buf);
|
|
buf = rust_demangle(std::string(name).c_str(), 0);
|
|
if (buf)
|
|
return buf;
|
|
return {};
|
|
}
|
|
|
|
} // namespace mold
|