Skip to content

Commit 808f124

Browse files
committed
Demangle Rust symbols
#371
1 parent 0e88fd0 commit 808f124

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

Makefile

+5-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ endif
2323
STRIP = strip
2424

2525
SRCS = $(wildcard *.cc elf/*.cc macho/*.cc)
26-
OBJS = $(SRCS:%.cc=out/%.o)
26+
OBJS = $(SRCS:%.cc=out/%.o) out/rust-demangle.o
2727

2828
OS := $(shell uname -s)
2929
ARCH := $(shell uname -m)
@@ -39,7 +39,7 @@ CFLAGS = -O2
3939
CXXFLAGS = -O2
4040

4141
MOLD_CXXFLAGS := -std=c++20 -fno-exceptions -fno-unwind-tables \
42-
-fno-asynchronous-unwind-tables -Ithird-party/xxhash \
42+
-fno-asynchronous-unwind-tables -Ithird-party \
4343
-DMOLD_VERSION=\"$(VERSION)\" -DLIBDIR="\"$(LIBDIR)\""
4444

4545
MOLD_LDFLAGS := -pthread -lz -lm -ldl
@@ -132,6 +132,9 @@ mold: $(OBJS) $(MIMALLOC_LIB) $(TBB_LIB)
132132
mold-wrapper.so: elf/mold-wrapper.c
133133
$(CC) $(DEPFLAGS) $(CFLAGS) -fPIC -shared -o $@ $< $(MOLD_WRAPPER_LDFLAGS) $(LDFLAGS)
134134

135+
out/rust-demangle.o: third-party/rust-demangle/rust-demangle.c
136+
$(CC) $(CFLAGS) -c -o $@ $<
137+
135138
out/%.o: %.cc out/elf/.keep out/macho/.keep
136139
$(CXX) $(MOLD_CXXFLAGS) $(DEPFLAGS) $(CXXFLAGS) -c -o $@ $<
137140

demangle.cc

+11-6
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,25 @@
22

33
#include <cstdlib>
44
#include <cxxabi.h>
5+
#include <rust-demangle/rust-demangle.h>
56

67
namespace mold {
78

89
std::string_view demangle(std::string_view name) {
910
if (name.starts_with("_Z")) {
1011
static thread_local char *buf;
11-
static thread_local size_t buflen;
12+
if (buf)
13+
free(buf);
1214

1315
int status;
14-
char *p = abi::__cxa_demangle(std::string(name).c_str(), buf, &buflen, &status);
15-
if (status == 0) {
16-
buf = p;
17-
return p;
18-
}
16+
buf = abi::__cxa_demangle(std::string(name).c_str(), nullptr, nullptr,
17+
&status);
18+
if (status == 0)
19+
return buf;
20+
21+
buf = rust_demangle(std::string(name).c_str(), 0);
22+
if (buf)
23+
return buf;
1924
}
2025

2126
return name;

mold.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#include <vector>
2828

2929
#define XXH_INLINE_ALL 1
30-
#include <xxhash.h>
30+
#include <xxhash/xxhash.h>
3131

3232
#ifdef NDEBUG
3333
# define unreachable() __builtin_unreachable()

0 commit comments

Comments
 (0)