#include "mold.h" #include #include 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 std::string_view Symbol::get_demangled_name() const { if (is_mangled_name(name())) { assert(nameptr[namelen] == '\0'); size_t len = sizeof(demangle_buf); int status; demangle_buf = abi::__cxa_demangle(nameptr, demangle_buf, &demangle_buf_len, &status); if (status == 0) return demangle_buf; } return name(); } template std::ostream &operator<<(std::ostream &out, const Symbol &sym) { if (opt_demangle) out << sym.get_demangled_name(); else out << sym.name(); return out; } #define INSTANTIATE(E) \ template class Symbol; \ template std::ostream &operator<<(std::ostream &, const Symbol &) INSTANTIATE(X86_64); INSTANTIATE(I386);