1
1
mirror of https://github.com/rui314/mold.git synced 2024-12-27 10:23:41 +03:00

Add --demangle

This commit is contained in:
Rui Ueyama 2021-02-27 12:16:51 +09:00
parent e23c358deb
commit c964725182
4 changed files with 27 additions and 5 deletions

View File

@ -12,7 +12,7 @@ LDFLAGS=-L$(TBB_LIBDIR) -Wl,-rpath=$(TBB_LIBDIR) \
LIBS=-lcrypto -pthread -ltbb -lmimalloc
OBJS=main.o object_file.o input_sections.o output_chunks.o mapfile.o perf.o \
linker_script.o archive_file.o output_file.o subprocess.o gc_sections.o \
icf.o
icf.o symbols.o
mold: $(OBJS)
$(CXX) $(CFLAGS) $(OBJS) -o $@ $(LDFLAGS) $(LIBS)

View File

@ -909,6 +909,10 @@ static Config parse_nonpositional_args(std::span<std::string_view> args,
conf.is_static = true;
} else if (read_flag(args, "shared")) {
conf.shared = true;
} else if (read_flag(args, "demangle")) {
conf.demangle = true;
} else if (read_flag(args, "no-demangle")) {
conf.demangle = false;
} else if (read_arg(args, arg, "y") || read_arg(args, arg, "trace-symbol")) {
conf.trace_symbol.push_back(arg);
} else if (read_arg(args, arg, "filler")) {

6
mold.h
View File

@ -56,6 +56,7 @@ enum class BuildIdKind : u8 { NONE, MD5, SHA1, SHA256, UUID };
struct Config {
BuildIdKind build_id = BuildIdKind::NONE;
bool allow_multiple_definition = false;
bool demangle = false;
bool discard_all = false;
bool discard_locals = false;
bool eh_frame_hdr = true;
@ -299,10 +300,7 @@ public:
u8 has_copyrel : 1 = false;
};
inline std::ostream &operator<<(std::ostream &out, const Symbol &sym) {
out << sym.name;
return out;
}
std::ostream &operator<<(std::ostream &out, const Symbol &sym);
//
// input_sections.cc

20
symbols.cc Normal file
View File

@ -0,0 +1,20 @@
#include "mold.h"
#include <cxxabi.h>
#include <stdlib.h>
std::ostream &operator<<(std::ostream &out, const Symbol &sym) {
if (config.demangle) {
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;
}