mirror of
https://github.com/rui314/mold.git
synced 2024-12-28 02:44:48 +03:00
46 lines
1.0 KiB
C++
46 lines
1.0 KiB
C++
#include "mold.h"
|
|
|
|
#include <cxxabi.h>
|
|
#include <stdlib.h>
|
|
|
|
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");
|
|
}
|
|
|
|
template <typename E>
|
|
std::string_view Symbol<E>::get_demangled_name() const {
|
|
if (is_mangled_name(name)) {
|
|
assert(name[name.size()] == '\0');
|
|
size_t len = sizeof(demangle_buf);
|
|
int status;
|
|
demangle_buf =
|
|
abi::__cxa_demangle(name.data(), demangle_buf, &demangle_buf_len, &status);
|
|
if (status == 0)
|
|
return demangle_buf;
|
|
}
|
|
|
|
return name;
|
|
}
|
|
|
|
template <typename E>
|
|
std::ostream &operator<<(std::ostream &out, const Symbol<E> &sym) {
|
|
if (opt_demangle)
|
|
out << sym.get_demangled_name();
|
|
else
|
|
out << sym.name;
|
|
return out;
|
|
}
|
|
|
|
template class Symbol<X86_64>;
|
|
|
|
template
|
|
std::ostream &operator<<(std::ostream &out, const Symbol<X86_64> &sym);
|
|
|
|
template class Symbol<I386>;
|
|
|
|
template
|
|
std::ostream &operator<<(std::ostream &out, const Symbol<I386> &sym);
|