Skip to content

Instantly share code, notes, and snippets.

@alexcrichton
Created November 8, 2018 23:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexcrichton/f06b1fa088291e1e90decbbc3a97a4e0 to your computer and use it in GitHub Desktop.
Save alexcrichton/f06b1fa088291e1e90decbbc3a97a4e0 to your computer and use it in GitHub Desktop.
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..0e60262dc 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::maybeDemangleSymbol(Sym.getName());
+}
+
+std::string lld::maybeDemangleSymbol(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..c8c47257c 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 maybeDemangleSymbol(StringRef Name);
} // namespace lld
diff --git a/wasm/Writer.cpp b/wasm/Writer.cpp
index c26ae5331..cb413de67 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, maybeDemangleSymbol(F->getName()), "symbol name");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment