1
1
mirror of https://github.com/rui314/mold.git synced 2024-09-22 02:20:51 +03:00
mold/symbols.cc

46 lines
1.0 KiB
C++
Raw Normal View History

2021-02-27 06:16:51 +03:00
#include "mold.h"
#include <cxxabi.h>
#include <stdlib.h>
static thread_local char *demangle_buf;
static thread_local size_t demangle_buf_len;
2021-02-28 15:11:11 +03:00
static bool is_mangled_name(std::string_view name) {
return name.starts_with("_Z");
}
2021-03-29 14:29:57 +03:00
template <typename E>
std::string_view Symbol<E>::get_demangled_name() const {
2021-04-01 14:12:30 +03:00
if (is_mangled_name(get_name())) {
assert(nameptr[namelen] == '\0');
size_t len = sizeof(demangle_buf);
2021-02-27 06:16:51 +03:00
int status;
demangle_buf =
2021-04-01 14:12:30 +03:00
abi::__cxa_demangle(nameptr, demangle_buf, &demangle_buf_len, &status);
if (status == 0)
return demangle_buf;
2021-02-27 06:16:51 +03:00
}
2021-04-01 14:12:30 +03:00
return get_name();
}
2021-03-29 14:29:57 +03:00
template <typename E>
std::ostream &operator<<(std::ostream &out, const Symbol<E> &sym) {
2021-03-29 10:48:23 +03:00
if (opt_demangle)
out << sym.get_demangled_name();
else
2021-04-01 14:12:30 +03:00
out << sym.get_name();
2021-02-27 06:16:51 +03:00
return out;
}
2021-03-29 14:29:57 +03:00
2021-03-30 08:57:38 +03:00
template class Symbol<X86_64>;
2021-03-29 14:29:57 +03:00
template
2021-03-30 08:57:38 +03:00
std::ostream &operator<<(std::ostream &out, const Symbol<X86_64> &sym);
2021-03-30 13:27:00 +03:00
template class Symbol<I386>;
template
std::ostream &operator<<(std::ostream &out, const Symbol<I386> &sym);