mirror of
https://github.com/rui314/mold.git
synced 2024-09-21 18:08:01 +03:00
[ELF] Refactor
This commit is contained in:
parent
58f1fbadc3
commit
67990f775b
@ -5,9 +5,6 @@
|
||||
|
||||
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) {
|
||||
return name.starts_with("_Z");
|
||||
}
|
||||
@ -15,17 +12,19 @@ static bool is_mangled_name(std::string_view name) {
|
||||
template <typename E>
|
||||
std::string_view Symbol<E>::get_demangled_name() const {
|
||||
if (is_mangled_name(name())) {
|
||||
char *mangled = new char[name().size() + 1];
|
||||
memcpy(mangled, name().data(), name().size());
|
||||
mangled[name().size()] = '\0';
|
||||
static thread_local char *buf1;
|
||||
static thread_local char *buf2;
|
||||
|
||||
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;
|
||||
demangle_buf =
|
||||
abi::__cxa_demangle(mangled, demangle_buf, &demangle_buf_len, &status);
|
||||
delete[](mangled);
|
||||
if (status == 0)
|
||||
return demangle_buf;
|
||||
char *p = abi::__cxa_demangle(buf1, buf2, NULL, &status);
|
||||
if (status == 0) {
|
||||
buf2 = p;
|
||||
return p;
|
||||
}
|
||||
}
|
||||
|
||||
return name();
|
||||
|
Loading…
Reference in New Issue
Block a user