1
1
mirror of https://github.com/rui314/mold.git synced 2024-12-28 19:04:27 +03:00
mold/symbols.cc
2021-02-28 21:11:51 +09:00

25 lines
535 B
C++

#include "mold.h"
#include <cxxabi.h>
#include <stdlib.h>
static bool is_mangled_name(std::string_view name) {
return name.starts_with("_Z");
}
std::ostream &operator<<(std::ostream &out, const Symbol &sym) {
if (config.demangle && is_mangled_name(sym.name)) {
int status;
char *name = abi::__cxa_demangle(std::string(sym.name).c_str(),
nullptr, 0, &status);
if (status == 0) {
out << name;
free(name);
return out;
}
}
out << sym.name;
return out;
}