1
1
mirror of https://github.com/rui314/mold.git synced 2024-09-21 18:08:01 +03:00

[ELF] Refactor

This commit is contained in:
Rui Ueyama 2021-09-26 18:50:03 +09:00
parent 58f1fbadc3
commit 67990f775b

View File

@ -5,9 +5,6 @@
namespace mold::elf { namespace mold::elf {
static thread_local char *demangle_buf;
static thread_local size_t demangle_buf_len;
static bool is_mangled_name(std::string_view name) { static bool is_mangled_name(std::string_view name) {
return name.starts_with("_Z"); return name.starts_with("_Z");
} }
@ -15,17 +12,19 @@ static bool is_mangled_name(std::string_view name) {
template <typename E> template <typename E>
std::string_view Symbol<E>::get_demangled_name() const { std::string_view Symbol<E>::get_demangled_name() const {
if (is_mangled_name(name())) { if (is_mangled_name(name())) {
char *mangled = new char[name().size() + 1]; static thread_local char *buf1;
memcpy(mangled, name().data(), name().size()); static thread_local char *buf2;
mangled[name().size()] = '\0';
buf1 = (char *)realloc(buf1, name().size() + 1);
memcpy(buf1, name().data(), name().size());
buf1[name().size()] = '\0';
size_t len = sizeof(demangle_buf);
int status; int status;
demangle_buf = char *p = abi::__cxa_demangle(buf1, buf2, NULL, &status);
abi::__cxa_demangle(mangled, demangle_buf, &demangle_buf_len, &status); if (status == 0) {
delete[](mangled); buf2 = p;
if (status == 0) return p;
return demangle_buf; }
} }
return name(); return name();