Instantly share code, notes, and snippets.

Embed
What would you like to do?
diff --git a/wasm/Driver.cpp b/wasm/Driver.cpp
index acdb5f93f..d90609396 100644
--- a/wasm/Driver.cpp
+++ b/wasm/Driver.cpp
@@ -310,10 +310,8 @@ static void handleWeakUndefines() {
// Add a synthetic dummy for weak undefined functions. These dummies will
// be GC'd if not used as the target of any "call" instructions.
- Optional<std::string> SymName = demangleItanium(Sym->getName());
- StringRef DebugName =
- Saver.save("undefined function " +
- (SymName ? StringRef(*SymName) : Sym->getName()));
+ std::string SymName = toString(*Sym);
+ StringRef DebugName = Saver.save("undefined function " + SymName);
SyntheticFunction *Func =
make<SyntheticFunction>(Sig, Sym->getName(), DebugName);
Func->setBody(UnreachableFn);
diff --git a/wasm/Symbols.cpp b/wasm/Symbols.cpp
index 035c7f2d7..7c629cba8 100644
--- a/wasm/Symbols.cpp
+++ b/wasm/Symbols.cpp
@@ -226,10 +226,14 @@ void SectionSymbol::setOutputSectionIndex(uint32_t Index) {
void LazySymbol::fetch() { cast<ArchiveFile>(File)->addMember(&ArchiveSymbol); }
std::string lld::toString(const wasm::Symbol &Sym) {
+ return lld::demangleSymbol(Sym.getName());
+}
+
+std::string lld::demangleSymbol(StringRef Name) {
if (Config->Demangle)
- if (Optional<std::string> S = demangleItanium(Sym.getName()))
+ if (Optional<std::string> S = demangleItanium(Name))
return *S;
- return Sym.getName();
+ return Name;
}
std::string lld::toString(wasm::Symbol::Kind Kind) {
diff --git a/wasm/Symbols.h b/wasm/Symbols.h
index 815cc97d2..3584a5fcf 100644
--- a/wasm/Symbols.h
+++ b/wasm/Symbols.h
@@ -349,6 +349,7 @@ T *replaceSymbol(Symbol *S, ArgT &&... Arg) {
// Returns a symbol name for an error message.
std::string toString(const wasm::Symbol &Sym);
std::string toString(wasm::Symbol::Kind Kind);
+std::string demangleSymbol(StringRef Name);
} // namespace lld
diff --git a/wasm/Writer.cpp b/wasm/Writer.cpp
index c26ae5331..c17fb7f7e 100644
--- a/wasm/Writer.cpp
+++ b/wasm/Writer.cpp
@@ -554,8 +554,7 @@ void Writer::createNameSection() {
for (const Symbol *S : ImportedSymbols) {
if (auto *F = dyn_cast<FunctionSymbol>(S)) {
writeUleb128(Sub.OS, F->getFunctionIndex(), "func index");
- Optional<std::string> Name = demangleItanium(F->getName());
- writeStr(Sub.OS, Name ? StringRef(*Name) : F->getName(), "symbol name");
+ writeStr(Sub.OS, toString(*S), "symbol name");
}
}
for (const InputFunction *F : InputFunctions) {
@@ -564,8 +563,7 @@ void Writer::createNameSection() {
if (!F->getDebugName().empty()) {
writeStr(Sub.OS, F->getDebugName(), "symbol name");
} else {
- Optional<std::string> Name = demangleItanium(F->getName());
- writeStr(Sub.OS, Name ? StringRef(*Name) : F->getName(), "symbol name");
+ writeStr(Sub.OS, demangleSymbol(F->getName()), "symbol name");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment