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

25 lines
439 B
C++
Raw Normal View History

2021-09-26 13:55:46 +03:00
#include "mold.h"
#include <cstdlib>
#include <cxxabi.h>
namespace mold {
std::string_view demangle(std::string_view name) {
if (name.starts_with("_Z")) {
2021-12-10 10:24:54 +03:00
static thread_local char *buf;
static thread_local size_t buflen;
2021-09-26 13:55:46 +03:00
int status;
2021-12-10 10:24:54 +03:00
char *p = abi::__cxa_demangle(std::string(name).c_str(), buf, &buflen, &status);
2021-09-26 13:55:46 +03:00
if (status == 0) {
2021-12-10 10:24:54 +03:00
buf = p;
2021-09-26 13:55:46 +03:00
return p;
}
}
return name;
}
} // namespace mold